]>
Commit | Line | Data |
---|---|---|
b36ba79f | 1 | /* Output routines for GCC for ARM. |
b0888988 | 2 | Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 |
2398fb2a | 3 | Free Software Foundation, Inc. |
cce8749e | 4 | Contributed by Pieter `Tiggr' Schoenmakers (rcpieter@win.tue.nl) |
956d6950 | 5 | and Martin Simmons (@harleqn.co.uk). |
b36ba79f | 6 | More major hacks by Richard Earnshaw (rearnsha@arm.com). |
cce8749e CH |
7 | |
8 | This file is part of GNU CC. | |
9 | ||
10 | GNU CC is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2, or (at your option) | |
13 | any later version. | |
14 | ||
15 | GNU CC is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with GNU CC; see the file COPYING. If not, write to | |
8fb289e7 RK |
22 | the Free Software Foundation, 59 Temple Place - Suite 330, |
23 | Boston, MA 02111-1307, USA. */ | |
ff9940b0 | 24 | |
56636818 | 25 | #include "config.h" |
43cffd11 | 26 | #include "system.h" |
cce8749e | 27 | #include "rtl.h" |
d5b7b3ae | 28 | #include "tree.h" |
c7319d87 | 29 | #include "obstack.h" |
cce8749e CH |
30 | #include "regs.h" |
31 | #include "hard-reg-set.h" | |
32 | #include "real.h" | |
33 | #include "insn-config.h" | |
34 | #include "conditions.h" | |
cce8749e CH |
35 | #include "output.h" |
36 | #include "insn-attr.h" | |
37 | #include "flags.h" | |
af48348a | 38 | #include "reload.h" |
49ad7cfa | 39 | #include "function.h" |
bee06f3d | 40 | #include "expr.h" |
ad076f4e | 41 | #include "toplev.h" |
aec3cfba | 42 | #include "recog.h" |
92a432f4 | 43 | #include "ggc.h" |
d5b7b3ae | 44 | #include "except.h" |
8b97c5f8 | 45 | #include "c-pragma.h" |
c27ba912 | 46 | #include "tm_p.h" |
cce8749e | 47 | |
d5b7b3ae RE |
48 | /* Forward definitions of types. */ |
49 | typedef struct minipool_node Mnode; | |
50 | typedef struct minipool_fixup Mfix; | |
51 | ||
52 | /* In order to improve the layout of the prototypes below | |
53 | some short type abbreviations are defined here. */ | |
54 | #define Hint HOST_WIDE_INT | |
55 | #define Mmode enum machine_mode | |
56 | #define Ulong unsigned long | |
6d3d9133 | 57 | #define Ccstar const char * |
d5b7b3ae RE |
58 | |
59 | /* Forward function declarations. */ | |
60 | static void arm_add_gc_roots PARAMS ((void)); | |
61 | static int arm_gen_constant PARAMS ((enum rtx_code, Mmode, Hint, rtx, rtx, int, int)); | |
d5b7b3ae RE |
62 | static Ulong bit_count PARAMS ((signed int)); |
63 | static int const_ok_for_op PARAMS ((Hint, enum rtx_code)); | |
64 | static int eliminate_lr2ip PARAMS ((rtx *)); | |
65 | static rtx emit_multi_reg_push PARAMS ((int)); | |
66 | static rtx emit_sfm PARAMS ((int, int)); | |
6d3d9133 | 67 | static Ccstar fp_const_from_val PARAMS ((REAL_VALUE_TYPE *)); |
d5b7b3ae RE |
68 | static arm_cc get_arm_condition_code PARAMS ((rtx)); |
69 | static void init_fpa_table PARAMS ((void)); | |
70 | static Hint int_log2 PARAMS ((Hint)); | |
71 | static rtx is_jump_table PARAMS ((rtx)); | |
6d3d9133 NC |
72 | static Ccstar output_multi_immediate PARAMS ((rtx *, Ccstar, Ccstar, int, Hint)); |
73 | static void print_multi_reg PARAMS ((FILE *, Ccstar, int, int)); | |
d5b7b3ae | 74 | static Mmode select_dominance_cc_mode PARAMS ((rtx, rtx, Hint)); |
6d3d9133 | 75 | static Ccstar shift_op PARAMS ((rtx, Hint *)); |
d5b7b3ae RE |
76 | static void arm_init_machine_status PARAMS ((struct function *)); |
77 | static void arm_mark_machine_status PARAMS ((struct function *)); | |
f7a80099 | 78 | static void arm_free_machine_status PARAMS ((struct function *)); |
d5b7b3ae RE |
79 | static int number_of_first_bit_set PARAMS ((int)); |
80 | static void replace_symbols_in_block PARAMS ((tree, rtx, rtx)); | |
81 | static void thumb_exit PARAMS ((FILE *, int, rtx)); | |
82 | static void thumb_pushpop PARAMS ((FILE *, int, int)); | |
6d3d9133 | 83 | static Ccstar thumb_condition_code PARAMS ((rtx, int)); |
d5b7b3ae RE |
84 | static rtx is_jump_table PARAMS ((rtx)); |
85 | static Hint get_jump_table_size PARAMS ((rtx)); | |
86 | static Mnode * move_minipool_fix_forward_ref PARAMS ((Mnode *, Mnode *, Hint)); | |
87 | static Mnode * add_minipool_forward_ref PARAMS ((Mfix *)); | |
88 | static Mnode * move_minipool_fix_backward_ref PARAMS ((Mnode *, Mnode *, Hint)); | |
89 | static Mnode * add_minipool_backward_ref PARAMS ((Mfix *)); | |
90 | static void assign_minipool_offsets PARAMS ((Mfix *)); | |
91 | static void arm_print_value PARAMS ((FILE *, rtx)); | |
92 | static void dump_minipool PARAMS ((rtx)); | |
93 | static int arm_barrier_cost PARAMS ((rtx)); | |
94 | static Mfix * create_fix_barrier PARAMS ((Mfix *, Hint)); | |
95 | static void push_minipool_barrier PARAMS ((rtx, Hint)); | |
96 | static void push_minipool_fix PARAMS ((rtx, Hint, rtx *, Mmode, rtx)); | |
97 | static void note_invalid_constants PARAMS ((rtx, Hint)); | |
87e27392 | 98 | static int current_file_function_operand PARAMS ((rtx)); |
6d3d9133 NC |
99 | static Ulong arm_compute_save_reg_mask PARAMS ((void)); |
100 | static Ulong arm_isr_value PARAMS ((tree)); | |
101 | static Ulong arm_compute_func_type PARAMS ((void)); | |
d5b7b3ae RE |
102 | \f |
103 | #undef Hint | |
104 | #undef Mmode | |
105 | #undef Ulong | |
6d3d9133 | 106 | #undef Ccstar |
f3bb6135 | 107 | |
c7319d87 RE |
108 | /* Obstack for minipool constant handling. */ |
109 | static struct obstack minipool_obstack; | |
110 | static char *minipool_startobj; | |
111 | ||
112 | #define obstack_chunk_alloc xmalloc | |
113 | #define obstack_chunk_free free | |
114 | ||
c27ba912 DM |
115 | /* The maximum number of insns skipped which will be conditionalised if |
116 | possible. */ | |
117 | static int max_insns_skipped = 5; | |
118 | ||
119 | extern FILE * asm_out_file; | |
120 | ||
6354dc9b | 121 | /* True if we are currently building a constant table. */ |
13bd191d PB |
122 | int making_const_table; |
123 | ||
60d0536b | 124 | /* Define the information needed to generate branch insns. This is |
6354dc9b | 125 | stored from the compare operation. */ |
ff9940b0 | 126 | rtx arm_compare_op0, arm_compare_op1; |
ff9940b0 | 127 | |
6354dc9b | 128 | /* What type of floating point are we tuning for? */ |
bee06f3d RE |
129 | enum floating_point_type arm_fpu; |
130 | ||
6354dc9b | 131 | /* What type of floating point instructions are available? */ |
b111229a RE |
132 | enum floating_point_type arm_fpu_arch; |
133 | ||
6354dc9b | 134 | /* What program mode is the cpu running in? 26-bit mode or 32-bit mode. */ |
2b835d68 RE |
135 | enum prog_mode_type arm_prgmode; |
136 | ||
6354dc9b | 137 | /* Set by the -mfp=... option. */ |
f9cc092a | 138 | const char * target_fp_name = NULL; |
2b835d68 | 139 | |
b355a481 | 140 | /* Used to parse -mstructure_size_boundary command line option. */ |
f9cc092a | 141 | const char * structure_size_string = NULL; |
723ae7c1 | 142 | int arm_structure_size_boundary = DEFAULT_STRUCTURE_SIZE_BOUNDARY; |
b355a481 | 143 | |
aec3cfba | 144 | /* Bit values used to identify processor capabilities. */ |
62b10bbc NC |
145 | #define FL_CO_PROC (1 << 0) /* Has external co-processor bus */ |
146 | #define FL_FAST_MULT (1 << 1) /* Fast multiply */ | |
147 | #define FL_MODE26 (1 << 2) /* 26-bit mode support */ | |
148 | #define FL_MODE32 (1 << 3) /* 32-bit mode support */ | |
149 | #define FL_ARCH4 (1 << 4) /* Architecture rel 4 */ | |
150 | #define FL_ARCH5 (1 << 5) /* Architecture rel 5 */ | |
151 | #define FL_THUMB (1 << 6) /* Thumb aware */ | |
152 | #define FL_LDSCHED (1 << 7) /* Load scheduling necessary */ | |
153 | #define FL_STRONG (1 << 8) /* StrongARM */ | |
b15bca31 | 154 | #define FL_ARCH5E (1 << 9) /* DSP extenstions to v5 */ |
d19fb8e3 | 155 | #define FL_XSCALE (1 << 10) /* XScale */ |
aec3cfba | 156 | |
d5b7b3ae RE |
157 | /* The bits in this mask specify which instructions we are |
158 | allowed to generate. */ | |
aec3cfba | 159 | static int insn_flags = 0; |
d5b7b3ae | 160 | |
aec3cfba NC |
161 | /* The bits in this mask specify which instruction scheduling options should |
162 | be used. Note - there is an overlap with the FL_FAST_MULT. For some | |
163 | hardware we want to be able to generate the multiply instructions, but to | |
164 | tune as if they were not present in the architecture. */ | |
165 | static int tune_flags = 0; | |
166 | ||
167 | /* The following are used in the arm.md file as equivalents to bits | |
168 | in the above two flag variables. */ | |
169 | ||
2b835d68 RE |
170 | /* Nonzero if this is an "M" variant of the processor. */ |
171 | int arm_fast_multiply = 0; | |
172 | ||
6354dc9b | 173 | /* Nonzero if this chip supports the ARM Architecture 4 extensions. */ |
2b835d68 RE |
174 | int arm_arch4 = 0; |
175 | ||
6354dc9b | 176 | /* Nonzero if this chip supports the ARM Architecture 5 extensions. */ |
62b10bbc NC |
177 | int arm_arch5 = 0; |
178 | ||
b15bca31 RE |
179 | /* Nonzero if this chip supports the ARM Architecture 5E extensions. */ |
180 | int arm_arch5e = 0; | |
181 | ||
aec3cfba | 182 | /* Nonzero if this chip can benefit from load scheduling. */ |
f5a1b0d2 NC |
183 | int arm_ld_sched = 0; |
184 | ||
185 | /* Nonzero if this chip is a StrongARM. */ | |
186 | int arm_is_strong = 0; | |
187 | ||
d19fb8e3 NC |
188 | /* Nonzero if this chip is an XScale. */ |
189 | int arm_is_xscale = 0; | |
190 | ||
f5a1b0d2 NC |
191 | /* Nonzero if this chip is a an ARM6 or an ARM7. */ |
192 | int arm_is_6_or_7 = 0; | |
b111229a | 193 | |
0616531f RE |
194 | /* Nonzero if generating Thumb instructions. */ |
195 | int thumb_code = 0; | |
196 | ||
cce8749e CH |
197 | /* In case of a PRE_INC, POST_INC, PRE_DEC, POST_DEC memory reference, we |
198 | must report the mode of the memory reference from PRINT_OPERAND to | |
199 | PRINT_OPERAND_ADDRESS. */ | |
f3bb6135 | 200 | enum machine_mode output_memory_reference_mode; |
cce8749e CH |
201 | |
202 | /* Nonzero if the prologue must setup `fp'. */ | |
203 | int current_function_anonymous_args; | |
204 | ||
32de079a | 205 | /* The register number to be used for the PIC offset register. */ |
ed0e6530 | 206 | const char * arm_pic_register_string = NULL; |
32de079a RE |
207 | int arm_pic_register = 9; |
208 | ||
ff9940b0 | 209 | /* Set to 1 when a return insn is output, this means that the epilogue |
6354dc9b | 210 | is not needed. */ |
d5b7b3ae | 211 | int return_used_this_function; |
ff9940b0 | 212 | |
aec3cfba NC |
213 | /* Set to 1 after arm_reorg has started. Reset to start at the start of |
214 | the next function. */ | |
4b632bf1 RE |
215 | static int after_arm_reorg = 0; |
216 | ||
aec3cfba | 217 | /* The maximum number of insns to be used when loading a constant. */ |
2b835d68 RE |
218 | static int arm_constant_limit = 3; |
219 | ||
cce8749e CH |
220 | /* For an explanation of these variables, see final_prescan_insn below. */ |
221 | int arm_ccfsm_state; | |
84ed5e79 | 222 | enum arm_cond_code arm_current_cc; |
cce8749e CH |
223 | rtx arm_target_insn; |
224 | int arm_target_label; | |
9997d19d RE |
225 | |
226 | /* The condition codes of the ARM, and the inverse function. */ | |
cd2b33d0 | 227 | const char * arm_condition_codes[] = |
9997d19d RE |
228 | { |
229 | "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", | |
230 | "hi", "ls", "ge", "lt", "gt", "le", "al", "nv" | |
231 | }; | |
232 | ||
f5a1b0d2 | 233 | #define streq(string1, string2) (strcmp (string1, string2) == 0) |
2b835d68 | 234 | \f |
6354dc9b | 235 | /* Initialization code. */ |
2b835d68 | 236 | |
2b835d68 RE |
237 | struct processors |
238 | { | |
cd2b33d0 | 239 | const char * name; |
2b835d68 RE |
240 | unsigned int flags; |
241 | }; | |
242 | ||
243 | /* Not all of these give usefully different compilation alternatives, | |
244 | but there is no simple way of generalizing them. */ | |
f5a1b0d2 NC |
245 | static struct processors all_cores[] = |
246 | { | |
247 | /* ARM Cores */ | |
248 | ||
249 | {"arm2", FL_CO_PROC | FL_MODE26 }, | |
250 | {"arm250", FL_CO_PROC | FL_MODE26 }, | |
251 | {"arm3", FL_CO_PROC | FL_MODE26 }, | |
252 | {"arm6", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
253 | {"arm60", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
254 | {"arm600", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
255 | {"arm610", FL_MODE26 | FL_MODE32 }, | |
256 | {"arm620", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
949d79eb RE |
257 | {"arm7", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, |
258 | /* arm7m doesn't exist on its own, but only with D, (and I), but | |
d5b7b3ae | 259 | those don't alter the code, so arm7m is sometimes used. */ |
949d79eb RE |
260 | {"arm7m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, |
261 | {"arm7d", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
262 | {"arm7dm", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, | |
263 | {"arm7di", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
f5a1b0d2 NC |
264 | {"arm7dmi", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, |
265 | {"arm70", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
266 | {"arm700", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
267 | {"arm700i", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
268 | {"arm710", FL_MODE26 | FL_MODE32 }, | |
eab4abeb | 269 | {"arm710t", FL_MODE26 | FL_MODE32 | FL_THUMB }, |
a120a3bd | 270 | {"arm720", FL_MODE26 | FL_MODE32 }, |
eab4abeb NC |
271 | {"arm720t", FL_MODE26 | FL_MODE32 | FL_THUMB }, |
272 | {"arm740t", FL_MODE26 | FL_MODE32 | FL_THUMB }, | |
f5a1b0d2 NC |
273 | {"arm710c", FL_MODE26 | FL_MODE32 }, |
274 | {"arm7100", FL_MODE26 | FL_MODE32 }, | |
275 | {"arm7500", FL_MODE26 | FL_MODE32 }, | |
949d79eb RE |
276 | /* Doesn't have an external co-proc, but does have embedded fpu. */ |
277 | {"arm7500fe", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
f5a1b0d2 NC |
278 | {"arm7tdmi", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB }, |
279 | {"arm8", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED }, | |
280 | {"arm810", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED }, | |
281 | {"arm9", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED }, | |
6cf32035 NC |
282 | {"arm920", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED }, |
283 | {"arm920t", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED }, | |
eab4abeb | 284 | {"arm940t", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED }, |
f5a1b0d2 | 285 | {"arm9tdmi", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED }, |
eab4abeb | 286 | {"arm9e", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED }, |
f5a1b0d2 NC |
287 | {"strongarm", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG }, |
288 | {"strongarm110", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG }, | |
289 | {"strongarm1100", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG }, | |
eab4abeb NC |
290 | {"strongarm1110", FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_LDSCHED | FL_STRONG }, |
291 | {"arm10tdmi", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED | FL_ARCH5 }, | |
292 | {"arm1020t", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED | FL_ARCH5 }, | |
293 | {"xscale", FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_LDSCHED | FL_STRONG | FL_ARCH5 | FL_ARCH5E | FL_XSCALE }, | |
f5a1b0d2 NC |
294 | |
295 | {NULL, 0} | |
296 | }; | |
297 | ||
298 | static struct processors all_architectures[] = | |
2b835d68 | 299 | { |
f5a1b0d2 NC |
300 | /* ARM Architectures */ |
301 | ||
62b10bbc NC |
302 | { "armv2", FL_CO_PROC | FL_MODE26 }, |
303 | { "armv2a", FL_CO_PROC | FL_MODE26 }, | |
304 | { "armv3", FL_CO_PROC | FL_MODE26 | FL_MODE32 }, | |
305 | { "armv3m", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT }, | |
949d79eb | 306 | { "armv4", FL_CO_PROC | FL_MODE26 | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 }, |
b111229a RE |
307 | /* Strictly, FL_MODE26 is a permitted option for v4t, but there are no |
308 | implementations that support it, so we will leave it out for now. */ | |
62b10bbc NC |
309 | { "armv4t", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB }, |
310 | { "armv5", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_ARCH5 }, | |
d19fb8e3 NC |
311 | { "armv5t", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_ARCH5 }, |
312 | { "armv5te", FL_CO_PROC | FL_MODE32 | FL_FAST_MULT | FL_ARCH4 | FL_THUMB | FL_ARCH5 | FL_ARCH5E }, | |
62b10bbc | 313 | { NULL, 0 } |
f5a1b0d2 NC |
314 | }; |
315 | ||
316 | /* This is a magic stucture. The 'string' field is magically filled in | |
317 | with a pointer to the value specified by the user on the command line | |
318 | assuming that the user has specified such a value. */ | |
319 | ||
320 | struct arm_cpu_select arm_select[] = | |
321 | { | |
322 | /* string name processors */ | |
323 | { NULL, "-mcpu=", all_cores }, | |
324 | { NULL, "-march=", all_architectures }, | |
325 | { NULL, "-mtune=", all_cores } | |
2b835d68 RE |
326 | }; |
327 | ||
aec3cfba | 328 | /* Return the number of bits set in value' */ |
d5b7b3ae | 329 | static unsigned long |
aec3cfba NC |
330 | bit_count (value) |
331 | signed int value; | |
332 | { | |
d5b7b3ae | 333 | unsigned long count = 0; |
aec3cfba NC |
334 | |
335 | while (value) | |
336 | { | |
5895f793 RE |
337 | value &= ~(value & -value); |
338 | ++count; | |
aec3cfba NC |
339 | } |
340 | ||
341 | return count; | |
342 | } | |
343 | ||
2b835d68 RE |
344 | /* Fix up any incompatible options that the user has specified. |
345 | This has now turned into a maze. */ | |
346 | void | |
347 | arm_override_options () | |
348 | { | |
ed4c4348 | 349 | unsigned i; |
f5a1b0d2 NC |
350 | |
351 | /* Set up the flags based on the cpu/architecture selected by the user. */ | |
b6a1cbae | 352 | for (i = ARRAY_SIZE (arm_select); i--;) |
bd9c7e23 | 353 | { |
f5a1b0d2 NC |
354 | struct arm_cpu_select * ptr = arm_select + i; |
355 | ||
356 | if (ptr->string != NULL && ptr->string[0] != '\0') | |
bd9c7e23 | 357 | { |
13bd191d | 358 | const struct processors * sel; |
bd9c7e23 | 359 | |
5895f793 | 360 | for (sel = ptr->processors; sel->name != NULL; sel++) |
f5a1b0d2 | 361 | if (streq (ptr->string, sel->name)) |
bd9c7e23 | 362 | { |
aec3cfba NC |
363 | if (i == 2) |
364 | tune_flags = sel->flags; | |
365 | else | |
b111229a | 366 | { |
aec3cfba NC |
367 | /* If we have been given an architecture and a processor |
368 | make sure that they are compatible. We only generate | |
369 | a warning though, and we prefer the CPU over the | |
6354dc9b | 370 | architecture. */ |
aec3cfba | 371 | if (insn_flags != 0 && (insn_flags ^ sel->flags)) |
6cf32035 | 372 | warning ("switch -mcpu=%s conflicts with -march= switch", |
aec3cfba NC |
373 | ptr->string); |
374 | ||
375 | insn_flags = sel->flags; | |
b111229a | 376 | } |
f5a1b0d2 | 377 | |
bd9c7e23 RE |
378 | break; |
379 | } | |
380 | ||
381 | if (sel->name == NULL) | |
382 | error ("bad value (%s) for %s switch", ptr->string, ptr->name); | |
383 | } | |
384 | } | |
aec3cfba | 385 | |
f5a1b0d2 | 386 | /* If the user did not specify a processor, choose one for them. */ |
aec3cfba | 387 | if (insn_flags == 0) |
f5a1b0d2 NC |
388 | { |
389 | struct processors * sel; | |
aec3cfba NC |
390 | unsigned int sought; |
391 | static struct cpu_default | |
392 | { | |
cd2b33d0 NC |
393 | int cpu; |
394 | const char * name; | |
aec3cfba NC |
395 | } |
396 | cpu_defaults[] = | |
397 | { | |
398 | { TARGET_CPU_arm2, "arm2" }, | |
399 | { TARGET_CPU_arm6, "arm6" }, | |
400 | { TARGET_CPU_arm610, "arm610" }, | |
2aa0c933 | 401 | { TARGET_CPU_arm710, "arm710" }, |
aec3cfba NC |
402 | { TARGET_CPU_arm7m, "arm7m" }, |
403 | { TARGET_CPU_arm7500fe, "arm7500fe" }, | |
404 | { TARGET_CPU_arm7tdmi, "arm7tdmi" }, | |
405 | { TARGET_CPU_arm8, "arm8" }, | |
406 | { TARGET_CPU_arm810, "arm810" }, | |
407 | { TARGET_CPU_arm9, "arm9" }, | |
408 | { TARGET_CPU_strongarm, "strongarm" }, | |
d19fb8e3 | 409 | { TARGET_CPU_xscale, "xscale" }, |
aec3cfba NC |
410 | { TARGET_CPU_generic, "arm" }, |
411 | { 0, 0 } | |
412 | }; | |
413 | struct cpu_default * def; | |
414 | ||
415 | /* Find the default. */ | |
5895f793 | 416 | for (def = cpu_defaults; def->name; def++) |
aec3cfba NC |
417 | if (def->cpu == TARGET_CPU_DEFAULT) |
418 | break; | |
419 | ||
420 | /* Make sure we found the default CPU. */ | |
421 | if (def->name == NULL) | |
422 | abort (); | |
423 | ||
424 | /* Find the default CPU's flags. */ | |
5895f793 | 425 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba NC |
426 | if (streq (def->name, sel->name)) |
427 | break; | |
428 | ||
429 | if (sel->name == NULL) | |
430 | abort (); | |
431 | ||
432 | insn_flags = sel->flags; | |
433 | ||
434 | /* Now check to see if the user has specified some command line | |
435 | switch that require certain abilities from the cpu. */ | |
436 | sought = 0; | |
f5a1b0d2 | 437 | |
d5b7b3ae | 438 | if (TARGET_INTERWORK || TARGET_THUMB) |
f5a1b0d2 | 439 | { |
aec3cfba NC |
440 | sought |= (FL_THUMB | FL_MODE32); |
441 | ||
442 | /* Force apcs-32 to be used for interworking. */ | |
f5a1b0d2 | 443 | target_flags |= ARM_FLAG_APCS_32; |
aec3cfba | 444 | |
d5b7b3ae | 445 | /* There are no ARM processors that support both APCS-26 and |
aec3cfba NC |
446 | interworking. Therefore we force FL_MODE26 to be removed |
447 | from insn_flags here (if it was set), so that the search | |
448 | below will always be able to find a compatible processor. */ | |
5895f793 | 449 | insn_flags &= ~FL_MODE26; |
f5a1b0d2 | 450 | } |
5895f793 | 451 | else if (!TARGET_APCS_32) |
f5a1b0d2 | 452 | sought |= FL_MODE26; |
d5b7b3ae | 453 | |
aec3cfba | 454 | if (sought != 0 && ((sought & insn_flags) != sought)) |
f5a1b0d2 | 455 | { |
aec3cfba NC |
456 | /* Try to locate a CPU type that supports all of the abilities |
457 | of the default CPU, plus the extra abilities requested by | |
458 | the user. */ | |
5895f793 | 459 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba | 460 | if ((sel->flags & sought) == (sought | insn_flags)) |
f5a1b0d2 NC |
461 | break; |
462 | ||
463 | if (sel->name == NULL) | |
aec3cfba NC |
464 | { |
465 | unsigned int current_bit_count = 0; | |
466 | struct processors * best_fit = NULL; | |
467 | ||
468 | /* Ideally we would like to issue an error message here | |
469 | saying that it was not possible to find a CPU compatible | |
470 | with the default CPU, but which also supports the command | |
471 | line options specified by the programmer, and so they | |
472 | ought to use the -mcpu=<name> command line option to | |
473 | override the default CPU type. | |
474 | ||
475 | Unfortunately this does not work with multilibing. We | |
476 | need to be able to support multilibs for -mapcs-26 and for | |
477 | -mthumb-interwork and there is no CPU that can support both | |
478 | options. Instead if we cannot find a cpu that has both the | |
479 | characteristics of the default cpu and the given command line | |
480 | options we scan the array again looking for a best match. */ | |
5895f793 | 481 | for (sel = all_cores; sel->name != NULL; sel++) |
aec3cfba NC |
482 | if ((sel->flags & sought) == sought) |
483 | { | |
484 | unsigned int count; | |
485 | ||
486 | count = bit_count (sel->flags & insn_flags); | |
487 | ||
488 | if (count >= current_bit_count) | |
489 | { | |
490 | best_fit = sel; | |
491 | current_bit_count = count; | |
492 | } | |
493 | } | |
f5a1b0d2 | 494 | |
aec3cfba NC |
495 | if (best_fit == NULL) |
496 | abort (); | |
497 | else | |
498 | sel = best_fit; | |
499 | } | |
500 | ||
501 | insn_flags = sel->flags; | |
f5a1b0d2 NC |
502 | } |
503 | } | |
aec3cfba NC |
504 | |
505 | /* If tuning has not been specified, tune for whichever processor or | |
506 | architecture has been selected. */ | |
507 | if (tune_flags == 0) | |
508 | tune_flags = insn_flags; | |
509 | ||
f5a1b0d2 NC |
510 | /* Make sure that the processor choice does not conflict with any of the |
511 | other command line choices. */ | |
aec3cfba | 512 | if (TARGET_APCS_32 && !(insn_flags & FL_MODE32)) |
f5a1b0d2 | 513 | { |
aec3cfba NC |
514 | /* If APCS-32 was not the default then it must have been set by the |
515 | user, so issue a warning message. If the user has specified | |
516 | "-mapcs-32 -mcpu=arm2" then we loose here. */ | |
517 | if ((TARGET_DEFAULT & ARM_FLAG_APCS_32) == 0) | |
518 | warning ("target CPU does not support APCS-32" ); | |
5895f793 | 519 | target_flags &= ~ARM_FLAG_APCS_32; |
f5a1b0d2 | 520 | } |
5895f793 | 521 | else if (!TARGET_APCS_32 && !(insn_flags & FL_MODE26)) |
f5a1b0d2 NC |
522 | { |
523 | warning ("target CPU does not support APCS-26" ); | |
524 | target_flags |= ARM_FLAG_APCS_32; | |
525 | } | |
526 | ||
6cfc7210 | 527 | if (TARGET_INTERWORK && !(insn_flags & FL_THUMB)) |
f5a1b0d2 NC |
528 | { |
529 | warning ("target CPU does not support interworking" ); | |
6cfc7210 | 530 | target_flags &= ~ARM_FLAG_INTERWORK; |
f5a1b0d2 NC |
531 | } |
532 | ||
d5b7b3ae RE |
533 | if (TARGET_THUMB && !(insn_flags & FL_THUMB)) |
534 | { | |
5184f7c5 | 535 | warning ("target CPU does not support THUMB instructions."); |
d5b7b3ae RE |
536 | target_flags &= ~ARM_FLAG_THUMB; |
537 | } | |
538 | ||
539 | if (TARGET_APCS_FRAME && TARGET_THUMB) | |
540 | { | |
541 | /* warning ("ignoring -mapcs-frame because -mthumb was used."); */ | |
542 | target_flags &= ~ARM_FLAG_APCS_FRAME; | |
543 | } | |
d19fb8e3 | 544 | |
d5b7b3ae RE |
545 | /* TARGET_BACKTRACE calls leaf_function_p, which causes a crash if done |
546 | from here where no function is being compiled currently. */ | |
547 | if ((target_flags & (THUMB_FLAG_LEAF_BACKTRACE | THUMB_FLAG_BACKTRACE)) | |
548 | && TARGET_ARM) | |
549 | warning ("enabling backtrace support is only meaningful when compiling for the Thumb."); | |
550 | ||
551 | if (TARGET_ARM && TARGET_CALLEE_INTERWORKING) | |
552 | warning ("enabling callee interworking support is only meaningful when compiling for the Thumb."); | |
553 | ||
554 | if (TARGET_ARM && TARGET_CALLER_INTERWORKING) | |
555 | warning ("enabling caller interworking support is only meaningful when compiling for the Thumb."); | |
556 | ||
f5a1b0d2 | 557 | /* If interworking is enabled then APCS-32 must be selected as well. */ |
6cfc7210 | 558 | if (TARGET_INTERWORK) |
f5a1b0d2 | 559 | { |
5895f793 | 560 | if (!TARGET_APCS_32) |
f5a1b0d2 NC |
561 | warning ("interworking forces APCS-32 to be used" ); |
562 | target_flags |= ARM_FLAG_APCS_32; | |
563 | } | |
564 | ||
5895f793 | 565 | if (TARGET_APCS_STACK && !TARGET_APCS_FRAME) |
f5a1b0d2 NC |
566 | { |
567 | warning ("-mapcs-stack-check incompatible with -mno-apcs-frame"); | |
568 | target_flags |= ARM_FLAG_APCS_FRAME; | |
569 | } | |
aec3cfba | 570 | |
2b835d68 RE |
571 | if (TARGET_POKE_FUNCTION_NAME) |
572 | target_flags |= ARM_FLAG_APCS_FRAME; | |
aec3cfba | 573 | |
2b835d68 | 574 | if (TARGET_APCS_REENT && flag_pic) |
400500c4 | 575 | error ("-fpic and -mapcs-reent are incompatible"); |
aec3cfba | 576 | |
2b835d68 | 577 | if (TARGET_APCS_REENT) |
f5a1b0d2 | 578 | warning ("APCS reentrant code not supported. Ignored"); |
aec3cfba | 579 | |
d5b7b3ae RE |
580 | /* If this target is normally configured to use APCS frames, warn if they |
581 | are turned off and debugging is turned on. */ | |
582 | if (TARGET_ARM | |
583 | && write_symbols != NO_DEBUG | |
5895f793 | 584 | && !TARGET_APCS_FRAME |
d5b7b3ae RE |
585 | && (TARGET_DEFAULT & ARM_FLAG_APCS_FRAME)) |
586 | warning ("-g with -mno-apcs-frame may not give sensible debugging"); | |
6cfc7210 | 587 | |
32de079a RE |
588 | /* If stack checking is disabled, we can use r10 as the PIC register, |
589 | which keeps r9 available. */ | |
5895f793 | 590 | if (flag_pic && !TARGET_APCS_STACK) |
32de079a | 591 | arm_pic_register = 10; |
aec3cfba | 592 | |
2b835d68 RE |
593 | if (TARGET_APCS_FLOAT) |
594 | warning ("Passing floating point arguments in fp regs not yet supported"); | |
f5a1b0d2 | 595 | |
aec3cfba | 596 | /* Initialise boolean versions of the flags, for use in the arm.md file. */ |
2ca12935 JL |
597 | arm_fast_multiply = (insn_flags & FL_FAST_MULT) != 0; |
598 | arm_arch4 = (insn_flags & FL_ARCH4) != 0; | |
599 | arm_arch5 = (insn_flags & FL_ARCH5) != 0; | |
b15bca31 | 600 | arm_arch5e = (insn_flags & FL_ARCH5E) != 0; |
a67ded0f | 601 | arm_is_xscale = (insn_flags & FL_XSCALE) != 0; |
6f7ebcbb | 602 | |
2ca12935 JL |
603 | arm_ld_sched = (tune_flags & FL_LDSCHED) != 0; |
604 | arm_is_strong = (tune_flags & FL_STRONG) != 0; | |
0616531f | 605 | thumb_code = (TARGET_ARM == 0); |
d5b7b3ae RE |
606 | arm_is_6_or_7 = (((tune_flags & (FL_MODE26 | FL_MODE32)) |
607 | && !(tune_flags & FL_ARCH4))) != 0; | |
6f7ebcbb | 608 | |
bd9c7e23 RE |
609 | /* Default value for floating point code... if no co-processor |
610 | bus, then schedule for emulated floating point. Otherwise, | |
b111229a RE |
611 | assume the user has an FPA. |
612 | Note: this does not prevent use of floating point instructions, | |
613 | -msoft-float does that. */ | |
aec3cfba | 614 | arm_fpu = (tune_flags & FL_CO_PROC) ? FP_HARD : FP_SOFT3; |
f5a1b0d2 | 615 | |
b111229a | 616 | if (target_fp_name) |
2b835d68 | 617 | { |
f5a1b0d2 | 618 | if (streq (target_fp_name, "2")) |
b111229a | 619 | arm_fpu_arch = FP_SOFT2; |
f5a1b0d2 NC |
620 | else if (streq (target_fp_name, "3")) |
621 | arm_fpu_arch = FP_SOFT3; | |
2b835d68 | 622 | else |
400500c4 | 623 | error ("Invalid floating point emulation option: -mfpe-%s", |
b111229a | 624 | target_fp_name); |
2b835d68 | 625 | } |
b111229a RE |
626 | else |
627 | arm_fpu_arch = FP_DEFAULT; | |
f5a1b0d2 NC |
628 | |
629 | if (TARGET_FPE && arm_fpu != FP_HARD) | |
630 | arm_fpu = FP_SOFT2; | |
aec3cfba | 631 | |
f5a1b0d2 NC |
632 | /* For arm2/3 there is no need to do any scheduling if there is only |
633 | a floating point emulator, or we are doing software floating-point. */ | |
ed0e6530 PB |
634 | if ((TARGET_SOFT_FLOAT || arm_fpu != FP_HARD) |
635 | && (tune_flags & FL_MODE32) == 0) | |
f5a1b0d2 | 636 | flag_schedule_insns = flag_schedule_insns_after_reload = 0; |
aec3cfba | 637 | |
cd2b33d0 | 638 | arm_prgmode = TARGET_APCS_32 ? PROG_MODE_PROG32 : PROG_MODE_PROG26; |
b355a481 NC |
639 | |
640 | if (structure_size_string != NULL) | |
641 | { | |
642 | int size = strtol (structure_size_string, NULL, 0); | |
643 | ||
644 | if (size == 8 || size == 32) | |
645 | arm_structure_size_boundary = size; | |
646 | else | |
647 | warning ("Structure size boundary can only be set to 8 or 32"); | |
648 | } | |
ed0e6530 PB |
649 | |
650 | if (arm_pic_register_string != NULL) | |
651 | { | |
652 | int pic_register; | |
653 | ||
5895f793 | 654 | if (!flag_pic) |
ed0e6530 PB |
655 | warning ("-mpic-register= is useless without -fpic"); |
656 | ||
657 | pic_register = decode_reg_name (arm_pic_register_string); | |
658 | ||
659 | /* Prevent the user from choosing an obviously stupid PIC register. */ | |
660 | if (pic_register < 0 || call_used_regs[pic_register] | |
661 | || pic_register == HARD_FRAME_POINTER_REGNUM | |
662 | || pic_register == STACK_POINTER_REGNUM | |
663 | || pic_register >= PC_REGNUM) | |
664 | error ("Unable to use '%s' for PIC register", arm_pic_register_string); | |
665 | else | |
666 | arm_pic_register = pic_register; | |
667 | } | |
d5b7b3ae RE |
668 | |
669 | if (TARGET_THUMB && flag_schedule_insns) | |
670 | { | |
671 | /* Don't warn since it's on by default in -O2. */ | |
672 | flag_schedule_insns = 0; | |
673 | } | |
674 | ||
f5a1b0d2 NC |
675 | /* If optimizing for space, don't synthesize constants. |
676 | For processors with load scheduling, it never costs more than 2 cycles | |
677 | to load a constant, and the load scheduler may well reduce that to 1. */ | |
aec3cfba | 678 | if (optimize_size || (tune_flags & FL_LDSCHED)) |
f5a1b0d2 | 679 | arm_constant_limit = 1; |
aec3cfba | 680 | |
d19fb8e3 NC |
681 | if (arm_is_xscale) |
682 | arm_constant_limit = 2; | |
683 | ||
f5a1b0d2 NC |
684 | /* If optimizing for size, bump the number of instructions that we |
685 | are prepared to conditionally execute (even on a StrongARM). | |
686 | Otherwise for the StrongARM, which has early execution of branches, | |
687 | a sequence that is worth skipping is shorter. */ | |
688 | if (optimize_size) | |
689 | max_insns_skipped = 6; | |
690 | else if (arm_is_strong) | |
691 | max_insns_skipped = 3; | |
92a432f4 RE |
692 | |
693 | /* Register global variables with the garbage collector. */ | |
694 | arm_add_gc_roots (); | |
695 | } | |
696 | ||
697 | static void | |
698 | arm_add_gc_roots () | |
699 | { | |
700 | ggc_add_rtx_root (&arm_compare_op0, 1); | |
701 | ggc_add_rtx_root (&arm_compare_op1, 1); | |
6d3d9133 | 702 | ggc_add_rtx_root (&arm_target_insn, 1); /* Not sure this is really a root. */ |
c7319d87 RE |
703 | |
704 | gcc_obstack_init(&minipool_obstack); | |
705 | minipool_startobj = (char *) obstack_alloc (&minipool_obstack, 0); | |
2b835d68 | 706 | } |
cce8749e | 707 | \f |
6d3d9133 NC |
708 | /* A table of known ARM exception types. |
709 | For use with the interrupt function attribute. */ | |
710 | ||
711 | typedef struct | |
712 | { | |
713 | const char * arg; | |
714 | unsigned long return_value; | |
715 | } | |
716 | isr_attribute_arg; | |
717 | ||
718 | static isr_attribute_arg isr_attribute_args [] = | |
719 | { | |
720 | { "IRQ", ARM_FT_ISR }, | |
721 | { "irq", ARM_FT_ISR }, | |
722 | { "FIQ", ARM_FT_FIQ }, | |
723 | { "fiq", ARM_FT_FIQ }, | |
724 | { "ABORT", ARM_FT_ISR }, | |
725 | { "abort", ARM_FT_ISR }, | |
726 | { "ABORT", ARM_FT_ISR }, | |
727 | { "abort", ARM_FT_ISR }, | |
728 | { "UNDEF", ARM_FT_EXCEPTION }, | |
729 | { "undef", ARM_FT_EXCEPTION }, | |
730 | { "SWI", ARM_FT_EXCEPTION }, | |
731 | { "swi", ARM_FT_EXCEPTION }, | |
732 | { NULL, ARM_FT_NORMAL } | |
733 | }; | |
734 | ||
735 | /* Returns the (interrupt) function type of the current | |
736 | function, or ARM_FT_UNKNOWN if the type cannot be determined. */ | |
737 | ||
738 | static unsigned long | |
739 | arm_isr_value (argument) | |
740 | tree argument; | |
741 | { | |
742 | isr_attribute_arg * ptr; | |
743 | const char * arg; | |
744 | ||
745 | /* No argument - default to IRQ. */ | |
746 | if (argument == NULL_TREE) | |
747 | return ARM_FT_ISR; | |
748 | ||
749 | /* Get the value of the argument. */ | |
750 | if (TREE_VALUE (argument) == NULL_TREE | |
751 | || TREE_CODE (TREE_VALUE (argument)) != STRING_CST) | |
752 | return ARM_FT_UNKNOWN; | |
753 | ||
754 | arg = TREE_STRING_POINTER (TREE_VALUE (argument)); | |
755 | ||
756 | /* Check it against the list of known arguments. */ | |
757 | for (ptr = isr_attribute_args; ptr->arg != NULL; ptr ++) | |
758 | if (strcmp (arg, ptr->arg) == 0) | |
759 | return ptr->return_value; | |
760 | ||
761 | /* An unrecognised interrupt type. */ | |
762 | return ARM_FT_UNKNOWN; | |
763 | } | |
764 | ||
765 | /* Computes the type of the current function. */ | |
766 | ||
767 | static unsigned long | |
768 | arm_compute_func_type () | |
769 | { | |
770 | unsigned long type = ARM_FT_UNKNOWN; | |
771 | tree a; | |
772 | tree attr; | |
773 | ||
774 | if (TREE_CODE (current_function_decl) != FUNCTION_DECL) | |
775 | abort (); | |
776 | ||
777 | /* Decide if the current function is volatile. Such functions | |
778 | never return, and many memory cycles can be saved by not storing | |
779 | register values that will never be needed again. This optimization | |
780 | was added to speed up context switching in a kernel application. */ | |
781 | if (optimize > 0 | |
782 | && current_function_nothrow | |
783 | && TREE_THIS_VOLATILE (current_function_decl)) | |
784 | type |= ARM_FT_VOLATILE; | |
785 | ||
786 | if (current_function_needs_context) | |
787 | type |= ARM_FT_NESTED; | |
788 | ||
789 | attr = DECL_MACHINE_ATTRIBUTES (current_function_decl); | |
790 | ||
791 | a = lookup_attribute ("naked", attr); | |
792 | if (a != NULL_TREE) | |
793 | type |= ARM_FT_NAKED; | |
794 | ||
795 | if (cfun->machine->eh_epilogue_sp_ofs != NULL_RTX) | |
796 | type |= ARM_FT_EXCEPTION_HANDLER; | |
797 | else | |
798 | { | |
799 | a = lookup_attribute ("isr", attr); | |
800 | if (a == NULL_TREE) | |
801 | a = lookup_attribute ("interrupt", attr); | |
802 | ||
803 | if (a == NULL_TREE) | |
804 | type |= TARGET_INTERWORK ? ARM_FT_INTERWORKED : ARM_FT_NORMAL; | |
805 | else | |
806 | type |= arm_isr_value (TREE_VALUE (a)); | |
807 | } | |
808 | ||
809 | return type; | |
810 | } | |
811 | ||
812 | /* Returns the type of the current function. */ | |
813 | ||
814 | unsigned long | |
815 | arm_current_func_type () | |
816 | { | |
817 | if (ARM_FUNC_TYPE (cfun->machine->func_type) == ARM_FT_UNKNOWN) | |
818 | cfun->machine->func_type = arm_compute_func_type (); | |
819 | ||
820 | return cfun->machine->func_type; | |
821 | } | |
822 | \f | |
6354dc9b | 823 | /* Return 1 if it is possible to return using a single instruction. */ |
6d3d9133 | 824 | |
ff9940b0 | 825 | int |
b36ba79f RE |
826 | use_return_insn (iscond) |
827 | int iscond; | |
ff9940b0 RE |
828 | { |
829 | int regno; | |
9b598fa0 | 830 | unsigned int func_type; |
ff9940b0 | 831 | |
d5b7b3ae | 832 | /* Never use a return instruction before reload has run. */ |
6d3d9133 NC |
833 | if (!reload_completed) |
834 | return 0; | |
835 | ||
9b598fa0 RE |
836 | func_type = arm_current_func_type (); |
837 | ||
6d3d9133 NC |
838 | /* Naked functions, volatile functiond and interrupt |
839 | functions all need special consideration. */ | |
840 | if (func_type & (ARM_FT_INTERRUPT | ARM_FT_VOLATILE | ARM_FT_NAKED)) | |
841 | return 0; | |
842 | ||
843 | /* As do variadic functions. */ | |
844 | if (current_function_pretend_args_size | |
ff9940b0 | 845 | || current_function_anonymous_args |
d5b7b3ae | 846 | /* Of if the function calls __builtin_eh_return () */ |
6d3d9133 | 847 | || ARM_FUNC_TYPE (func_type) == ARM_FT_EXCEPTION_HANDLER |
d5b7b3ae | 848 | /* Or if there is no frame pointer and there is a stack adjustment. */ |
56636818 | 849 | || ((get_frame_size () + current_function_outgoing_args_size != 0) |
5895f793 | 850 | && !frame_pointer_needed)) |
ff9940b0 RE |
851 | return 0; |
852 | ||
b111229a | 853 | /* Can't be done if interworking with Thumb, and any registers have been |
b36ba79f RE |
854 | stacked. Similarly, on StrongARM, conditional returns are expensive |
855 | if they aren't taken and registers have been stacked. */ | |
f5a1b0d2 | 856 | if (iscond && arm_is_strong && frame_pointer_needed) |
b36ba79f | 857 | return 0; |
d5b7b3ae | 858 | |
f5a1b0d2 | 859 | if ((iscond && arm_is_strong) |
6cfc7210 | 860 | || TARGET_INTERWORK) |
6ed30148 | 861 | { |
d5b7b3ae | 862 | for (regno = 0; regno <= LAST_ARM_REGNUM; regno++) |
5895f793 | 863 | if (regs_ever_live[regno] && !call_used_regs[regno]) |
6ed30148 RE |
864 | return 0; |
865 | ||
866 | if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) | |
b111229a | 867 | return 0; |
6ed30148 | 868 | } |
b111229a | 869 | |
6d3d9133 NC |
870 | /* Can't be done if any of the FPU regs are pushed, |
871 | since this also requires an insn. */ | |
d5b7b3ae RE |
872 | if (TARGET_HARD_FLOAT) |
873 | for (regno = FIRST_ARM_FP_REGNUM; regno <= LAST_ARM_FP_REGNUM; regno++) | |
5895f793 | 874 | if (regs_ever_live[regno] && !call_used_regs[regno]) |
d5b7b3ae | 875 | return 0; |
ff9940b0 RE |
876 | |
877 | return 1; | |
878 | } | |
879 | ||
cce8749e CH |
880 | /* Return TRUE if int I is a valid immediate ARM constant. */ |
881 | ||
882 | int | |
883 | const_ok_for_arm (i) | |
ff9940b0 | 884 | HOST_WIDE_INT i; |
cce8749e | 885 | { |
5895f793 | 886 | unsigned HOST_WIDE_INT mask = ~HOST_UINT (0xFF); |
cce8749e | 887 | |
56636818 JL |
888 | /* For machines with >32 bit HOST_WIDE_INT, the bits above bit 31 must |
889 | be all zero, or all one. */ | |
5895f793 RE |
890 | if ((i & ~HOST_UINT (0xffffffff)) != 0 |
891 | && ((i & ~HOST_UINT (0xffffffff)) | |
892 | != ((~HOST_UINT (0)) | |
893 | & ~HOST_UINT (0xffffffff)))) | |
56636818 JL |
894 | return FALSE; |
895 | ||
e2c671ba RE |
896 | /* Fast return for 0 and powers of 2 */ |
897 | if ((i & (i - 1)) == 0) | |
898 | return TRUE; | |
899 | ||
cce8749e CH |
900 | do |
901 | { | |
e5951263 | 902 | if ((i & mask & HOST_UINT (0xffffffff)) == 0) |
f3bb6135 | 903 | return TRUE; |
abaa26e5 | 904 | mask = |
e5951263 NC |
905 | (mask << 2) | ((mask & HOST_UINT (0xffffffff)) |
906 | >> (32 - 2)) | ~(HOST_UINT (0xffffffff)); | |
5895f793 | 907 | } while (mask != ~HOST_UINT (0xFF)); |
cce8749e | 908 | |
f3bb6135 RE |
909 | return FALSE; |
910 | } | |
cce8749e | 911 | |
6354dc9b | 912 | /* Return true if I is a valid constant for the operation CODE. */ |
74bbc178 NC |
913 | static int |
914 | const_ok_for_op (i, code) | |
e2c671ba RE |
915 | HOST_WIDE_INT i; |
916 | enum rtx_code code; | |
e2c671ba RE |
917 | { |
918 | if (const_ok_for_arm (i)) | |
919 | return 1; | |
920 | ||
921 | switch (code) | |
922 | { | |
923 | case PLUS: | |
924 | return const_ok_for_arm (ARM_SIGN_EXTEND (-i)); | |
925 | ||
926 | case MINUS: /* Should only occur with (MINUS I reg) => rsb */ | |
927 | case XOR: | |
928 | case IOR: | |
929 | return 0; | |
930 | ||
931 | case AND: | |
932 | return const_ok_for_arm (ARM_SIGN_EXTEND (~i)); | |
933 | ||
934 | default: | |
935 | abort (); | |
936 | } | |
937 | } | |
938 | ||
939 | /* Emit a sequence of insns to handle a large constant. | |
940 | CODE is the code of the operation required, it can be any of SET, PLUS, | |
941 | IOR, AND, XOR, MINUS; | |
942 | MODE is the mode in which the operation is being performed; | |
943 | VAL is the integer to operate on; | |
944 | SOURCE is the other operand (a register, or a null-pointer for SET); | |
945 | SUBTARGETS means it is safe to create scratch registers if that will | |
2b835d68 RE |
946 | either produce a simpler sequence, or we will want to cse the values. |
947 | Return value is the number of insns emitted. */ | |
e2c671ba RE |
948 | |
949 | int | |
950 | arm_split_constant (code, mode, val, target, source, subtargets) | |
951 | enum rtx_code code; | |
952 | enum machine_mode mode; | |
953 | HOST_WIDE_INT val; | |
954 | rtx target; | |
955 | rtx source; | |
956 | int subtargets; | |
2b835d68 RE |
957 | { |
958 | if (subtargets || code == SET | |
959 | || (GET_CODE (target) == REG && GET_CODE (source) == REG | |
960 | && REGNO (target) != REGNO (source))) | |
961 | { | |
4b632bf1 RE |
962 | /* After arm_reorg has been called, we can't fix up expensive |
963 | constants by pushing them into memory so we must synthesise | |
964 | them in-line, regardless of the cost. This is only likely to | |
965 | be more costly on chips that have load delay slots and we are | |
966 | compiling without running the scheduler (so no splitting | |
aec3cfba NC |
967 | occurred before the final instruction emission). |
968 | ||
969 | Ref: gcc -O1 -mcpu=strongarm gcc.c-torture/compile/980506-2.c | |
aec3cfba | 970 | */ |
5895f793 | 971 | if (!after_arm_reorg |
4b632bf1 RE |
972 | && (arm_gen_constant (code, mode, val, target, source, 1, 0) |
973 | > arm_constant_limit + (code != SET))) | |
2b835d68 RE |
974 | { |
975 | if (code == SET) | |
976 | { | |
977 | /* Currently SET is the only monadic value for CODE, all | |
978 | the rest are diadic. */ | |
43cffd11 | 979 | emit_insn (gen_rtx_SET (VOIDmode, target, GEN_INT (val))); |
2b835d68 RE |
980 | return 1; |
981 | } | |
982 | else | |
983 | { | |
984 | rtx temp = subtargets ? gen_reg_rtx (mode) : target; | |
985 | ||
43cffd11 | 986 | emit_insn (gen_rtx_SET (VOIDmode, temp, GEN_INT (val))); |
2b835d68 RE |
987 | /* For MINUS, the value is subtracted from, since we never |
988 | have subtraction of a constant. */ | |
989 | if (code == MINUS) | |
43cffd11 | 990 | emit_insn (gen_rtx_SET (VOIDmode, target, |
d5b7b3ae | 991 | gen_rtx_MINUS (mode, temp, source))); |
2b835d68 | 992 | else |
43cffd11 RE |
993 | emit_insn (gen_rtx_SET (VOIDmode, target, |
994 | gen_rtx (code, mode, source, temp))); | |
2b835d68 RE |
995 | return 2; |
996 | } | |
997 | } | |
998 | } | |
999 | ||
1000 | return arm_gen_constant (code, mode, val, target, source, subtargets, 1); | |
1001 | } | |
1002 | ||
ceebdb09 PB |
1003 | static int |
1004 | count_insns_for_constant (HOST_WIDE_INT remainder, int i) | |
1005 | { | |
1006 | HOST_WIDE_INT temp1; | |
1007 | int num_insns = 0; | |
1008 | do | |
1009 | { | |
1010 | int end; | |
1011 | ||
1012 | if (i <= 0) | |
1013 | i += 32; | |
1014 | if (remainder & (3 << (i - 2))) | |
1015 | { | |
1016 | end = i - 8; | |
1017 | if (end < 0) | |
1018 | end += 32; | |
1019 | temp1 = remainder & ((0x0ff << end) | |
1020 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
1021 | remainder &= ~temp1; | |
1022 | num_insns++; | |
1023 | i -= 6; | |
1024 | } | |
1025 | i -= 2; | |
1026 | } while (remainder); | |
1027 | return num_insns; | |
1028 | } | |
1029 | ||
2b835d68 RE |
1030 | /* As above, but extra parameter GENERATE which, if clear, suppresses |
1031 | RTL generation. */ | |
d5b7b3ae | 1032 | static int |
2b835d68 RE |
1033 | arm_gen_constant (code, mode, val, target, source, subtargets, generate) |
1034 | enum rtx_code code; | |
1035 | enum machine_mode mode; | |
1036 | HOST_WIDE_INT val; | |
1037 | rtx target; | |
1038 | rtx source; | |
1039 | int subtargets; | |
1040 | int generate; | |
e2c671ba | 1041 | { |
e2c671ba RE |
1042 | int can_invert = 0; |
1043 | int can_negate = 0; | |
1044 | int can_negate_initial = 0; | |
1045 | int can_shift = 0; | |
1046 | int i; | |
1047 | int num_bits_set = 0; | |
1048 | int set_sign_bit_copies = 0; | |
1049 | int clear_sign_bit_copies = 0; | |
1050 | int clear_zero_bit_copies = 0; | |
1051 | int set_zero_bit_copies = 0; | |
1052 | int insns = 0; | |
e2c671ba | 1053 | unsigned HOST_WIDE_INT temp1, temp2; |
e5951263 | 1054 | unsigned HOST_WIDE_INT remainder = val & HOST_UINT (0xffffffff); |
e2c671ba | 1055 | |
d5b7b3ae | 1056 | /* Find out which operations are safe for a given CODE. Also do a quick |
e2c671ba RE |
1057 | check for degenerate cases; these can occur when DImode operations |
1058 | are split. */ | |
1059 | switch (code) | |
1060 | { | |
1061 | case SET: | |
1062 | can_invert = 1; | |
1063 | can_shift = 1; | |
1064 | can_negate = 1; | |
1065 | break; | |
1066 | ||
1067 | case PLUS: | |
1068 | can_negate = 1; | |
1069 | can_negate_initial = 1; | |
1070 | break; | |
1071 | ||
1072 | case IOR: | |
e5951263 | 1073 | if (remainder == HOST_UINT (0xffffffff)) |
e2c671ba | 1074 | { |
2b835d68 | 1075 | if (generate) |
43cffd11 RE |
1076 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1077 | GEN_INT (ARM_SIGN_EXTEND (val)))); | |
e2c671ba RE |
1078 | return 1; |
1079 | } | |
1080 | if (remainder == 0) | |
1081 | { | |
1082 | if (reload_completed && rtx_equal_p (target, source)) | |
1083 | return 0; | |
2b835d68 | 1084 | if (generate) |
43cffd11 | 1085 | emit_insn (gen_rtx_SET (VOIDmode, target, source)); |
e2c671ba RE |
1086 | return 1; |
1087 | } | |
1088 | break; | |
1089 | ||
1090 | case AND: | |
1091 | if (remainder == 0) | |
1092 | { | |
2b835d68 | 1093 | if (generate) |
43cffd11 | 1094 | emit_insn (gen_rtx_SET (VOIDmode, target, const0_rtx)); |
e2c671ba RE |
1095 | return 1; |
1096 | } | |
e5951263 | 1097 | if (remainder == HOST_UINT (0xffffffff)) |
e2c671ba RE |
1098 | { |
1099 | if (reload_completed && rtx_equal_p (target, source)) | |
1100 | return 0; | |
2b835d68 | 1101 | if (generate) |
43cffd11 | 1102 | emit_insn (gen_rtx_SET (VOIDmode, target, source)); |
e2c671ba RE |
1103 | return 1; |
1104 | } | |
1105 | can_invert = 1; | |
1106 | break; | |
1107 | ||
1108 | case XOR: | |
1109 | if (remainder == 0) | |
1110 | { | |
1111 | if (reload_completed && rtx_equal_p (target, source)) | |
1112 | return 0; | |
2b835d68 | 1113 | if (generate) |
43cffd11 | 1114 | emit_insn (gen_rtx_SET (VOIDmode, target, source)); |
e2c671ba RE |
1115 | return 1; |
1116 | } | |
e5951263 | 1117 | if (remainder == HOST_UINT (0xffffffff)) |
e2c671ba | 1118 | { |
2b835d68 | 1119 | if (generate) |
43cffd11 RE |
1120 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1121 | gen_rtx_NOT (mode, source))); | |
e2c671ba RE |
1122 | return 1; |
1123 | } | |
1124 | ||
1125 | /* We don't know how to handle this yet below. */ | |
1126 | abort (); | |
1127 | ||
1128 | case MINUS: | |
1129 | /* We treat MINUS as (val - source), since (source - val) is always | |
1130 | passed as (source + (-val)). */ | |
1131 | if (remainder == 0) | |
1132 | { | |
2b835d68 | 1133 | if (generate) |
43cffd11 RE |
1134 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1135 | gen_rtx_NEG (mode, source))); | |
e2c671ba RE |
1136 | return 1; |
1137 | } | |
1138 | if (const_ok_for_arm (val)) | |
1139 | { | |
2b835d68 | 1140 | if (generate) |
43cffd11 RE |
1141 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1142 | gen_rtx_MINUS (mode, GEN_INT (val), | |
1143 | source))); | |
e2c671ba RE |
1144 | return 1; |
1145 | } | |
1146 | can_negate = 1; | |
1147 | ||
1148 | break; | |
1149 | ||
1150 | default: | |
1151 | abort (); | |
1152 | } | |
1153 | ||
6354dc9b | 1154 | /* If we can do it in one insn get out quickly. */ |
e2c671ba RE |
1155 | if (const_ok_for_arm (val) |
1156 | || (can_negate_initial && const_ok_for_arm (-val)) | |
1157 | || (can_invert && const_ok_for_arm (~val))) | |
1158 | { | |
2b835d68 | 1159 | if (generate) |
43cffd11 RE |
1160 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1161 | (source ? gen_rtx (code, mode, source, | |
1162 | GEN_INT (val)) | |
1163 | : GEN_INT (val)))); | |
e2c671ba RE |
1164 | return 1; |
1165 | } | |
1166 | ||
e2c671ba | 1167 | /* Calculate a few attributes that may be useful for specific |
6354dc9b | 1168 | optimizations. */ |
e2c671ba RE |
1169 | for (i = 31; i >= 0; i--) |
1170 | { | |
1171 | if ((remainder & (1 << i)) == 0) | |
1172 | clear_sign_bit_copies++; | |
1173 | else | |
1174 | break; | |
1175 | } | |
1176 | ||
1177 | for (i = 31; i >= 0; i--) | |
1178 | { | |
1179 | if ((remainder & (1 << i)) != 0) | |
1180 | set_sign_bit_copies++; | |
1181 | else | |
1182 | break; | |
1183 | } | |
1184 | ||
1185 | for (i = 0; i <= 31; i++) | |
1186 | { | |
1187 | if ((remainder & (1 << i)) == 0) | |
1188 | clear_zero_bit_copies++; | |
1189 | else | |
1190 | break; | |
1191 | } | |
1192 | ||
1193 | for (i = 0; i <= 31; i++) | |
1194 | { | |
1195 | if ((remainder & (1 << i)) != 0) | |
1196 | set_zero_bit_copies++; | |
1197 | else | |
1198 | break; | |
1199 | } | |
1200 | ||
1201 | switch (code) | |
1202 | { | |
1203 | case SET: | |
1204 | /* See if we can do this by sign_extending a constant that is known | |
1205 | to be negative. This is a good, way of doing it, since the shift | |
1206 | may well merge into a subsequent insn. */ | |
1207 | if (set_sign_bit_copies > 1) | |
1208 | { | |
1209 | if (const_ok_for_arm | |
1210 | (temp1 = ARM_SIGN_EXTEND (remainder | |
1211 | << (set_sign_bit_copies - 1)))) | |
1212 | { | |
2b835d68 RE |
1213 | if (generate) |
1214 | { | |
d499463f | 1215 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
43cffd11 RE |
1216 | emit_insn (gen_rtx_SET (VOIDmode, new_src, |
1217 | GEN_INT (temp1))); | |
2b835d68 RE |
1218 | emit_insn (gen_ashrsi3 (target, new_src, |
1219 | GEN_INT (set_sign_bit_copies - 1))); | |
1220 | } | |
e2c671ba RE |
1221 | return 2; |
1222 | } | |
1223 | /* For an inverted constant, we will need to set the low bits, | |
1224 | these will be shifted out of harm's way. */ | |
1225 | temp1 |= (1 << (set_sign_bit_copies - 1)) - 1; | |
1226 | if (const_ok_for_arm (~temp1)) | |
1227 | { | |
2b835d68 RE |
1228 | if (generate) |
1229 | { | |
d499463f | 1230 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
43cffd11 RE |
1231 | emit_insn (gen_rtx_SET (VOIDmode, new_src, |
1232 | GEN_INT (temp1))); | |
2b835d68 RE |
1233 | emit_insn (gen_ashrsi3 (target, new_src, |
1234 | GEN_INT (set_sign_bit_copies - 1))); | |
1235 | } | |
e2c671ba RE |
1236 | return 2; |
1237 | } | |
1238 | } | |
1239 | ||
1240 | /* See if we can generate this by setting the bottom (or the top) | |
1241 | 16 bits, and then shifting these into the other half of the | |
1242 | word. We only look for the simplest cases, to do more would cost | |
1243 | too much. Be careful, however, not to generate this when the | |
1244 | alternative would take fewer insns. */ | |
e5951263 | 1245 | if (val & HOST_UINT (0xffff0000)) |
e2c671ba | 1246 | { |
e5951263 | 1247 | temp1 = remainder & HOST_UINT (0xffff0000); |
e2c671ba RE |
1248 | temp2 = remainder & 0x0000ffff; |
1249 | ||
6354dc9b | 1250 | /* Overlaps outside this range are best done using other methods. */ |
e2c671ba RE |
1251 | for (i = 9; i < 24; i++) |
1252 | { | |
d5b7b3ae | 1253 | if ((((temp2 | (temp2 << i)) |
e5951263 | 1254 | & HOST_UINT (0xffffffff)) == remainder) |
5895f793 | 1255 | && !const_ok_for_arm (temp2)) |
e2c671ba | 1256 | { |
d499463f RE |
1257 | rtx new_src = (subtargets |
1258 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
1259 | : target); | |
1260 | insns = arm_gen_constant (code, mode, temp2, new_src, | |
2b835d68 | 1261 | source, subtargets, generate); |
e2c671ba | 1262 | source = new_src; |
2b835d68 | 1263 | if (generate) |
43cffd11 RE |
1264 | emit_insn (gen_rtx_SET |
1265 | (VOIDmode, target, | |
1266 | gen_rtx_IOR (mode, | |
1267 | gen_rtx_ASHIFT (mode, source, | |
1268 | GEN_INT (i)), | |
1269 | source))); | |
e2c671ba RE |
1270 | return insns + 1; |
1271 | } | |
1272 | } | |
1273 | ||
6354dc9b | 1274 | /* Don't duplicate cases already considered. */ |
e2c671ba RE |
1275 | for (i = 17; i < 24; i++) |
1276 | { | |
1277 | if (((temp1 | (temp1 >> i)) == remainder) | |
5895f793 | 1278 | && !const_ok_for_arm (temp1)) |
e2c671ba | 1279 | { |
d499463f RE |
1280 | rtx new_src = (subtargets |
1281 | ? (generate ? gen_reg_rtx (mode) : NULL_RTX) | |
1282 | : target); | |
1283 | insns = arm_gen_constant (code, mode, temp1, new_src, | |
2b835d68 | 1284 | source, subtargets, generate); |
e2c671ba | 1285 | source = new_src; |
2b835d68 | 1286 | if (generate) |
43cffd11 RE |
1287 | emit_insn |
1288 | (gen_rtx_SET (VOIDmode, target, | |
1289 | gen_rtx_IOR | |
1290 | (mode, | |
1291 | gen_rtx_LSHIFTRT (mode, source, | |
1292 | GEN_INT (i)), | |
1293 | source))); | |
e2c671ba RE |
1294 | return insns + 1; |
1295 | } | |
1296 | } | |
1297 | } | |
1298 | break; | |
1299 | ||
1300 | case IOR: | |
1301 | case XOR: | |
7b64da89 RE |
1302 | /* If we have IOR or XOR, and the constant can be loaded in a |
1303 | single instruction, and we can find a temporary to put it in, | |
e2c671ba RE |
1304 | then this can be done in two instructions instead of 3-4. */ |
1305 | if (subtargets | |
d499463f | 1306 | /* TARGET can't be NULL if SUBTARGETS is 0 */ |
5895f793 | 1307 | || (reload_completed && !reg_mentioned_p (target, source))) |
e2c671ba | 1308 | { |
5895f793 | 1309 | if (const_ok_for_arm (ARM_SIGN_EXTEND (~val))) |
e2c671ba | 1310 | { |
2b835d68 RE |
1311 | if (generate) |
1312 | { | |
1313 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
e2c671ba | 1314 | |
43cffd11 RE |
1315 | emit_insn (gen_rtx_SET (VOIDmode, sub, GEN_INT (val))); |
1316 | emit_insn (gen_rtx_SET (VOIDmode, target, | |
1317 | gen_rtx (code, mode, source, sub))); | |
2b835d68 | 1318 | } |
e2c671ba RE |
1319 | return 2; |
1320 | } | |
1321 | } | |
1322 | ||
1323 | if (code == XOR) | |
1324 | break; | |
1325 | ||
1326 | if (set_sign_bit_copies > 8 | |
1327 | && (val & (-1 << (32 - set_sign_bit_copies))) == val) | |
1328 | { | |
2b835d68 RE |
1329 | if (generate) |
1330 | { | |
1331 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
1332 | rtx shift = GEN_INT (set_sign_bit_copies); | |
1333 | ||
43cffd11 RE |
1334 | emit_insn (gen_rtx_SET (VOIDmode, sub, |
1335 | gen_rtx_NOT (mode, | |
1336 | gen_rtx_ASHIFT (mode, | |
1337 | source, | |
f5a1b0d2 | 1338 | shift)))); |
43cffd11 RE |
1339 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1340 | gen_rtx_NOT (mode, | |
1341 | gen_rtx_LSHIFTRT (mode, sub, | |
1342 | shift)))); | |
2b835d68 | 1343 | } |
e2c671ba RE |
1344 | return 2; |
1345 | } | |
1346 | ||
1347 | if (set_zero_bit_copies > 8 | |
1348 | && (remainder & ((1 << set_zero_bit_copies) - 1)) == remainder) | |
1349 | { | |
2b835d68 RE |
1350 | if (generate) |
1351 | { | |
1352 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
1353 | rtx shift = GEN_INT (set_zero_bit_copies); | |
1354 | ||
43cffd11 RE |
1355 | emit_insn (gen_rtx_SET (VOIDmode, sub, |
1356 | gen_rtx_NOT (mode, | |
1357 | gen_rtx_LSHIFTRT (mode, | |
1358 | source, | |
f5a1b0d2 | 1359 | shift)))); |
43cffd11 RE |
1360 | emit_insn (gen_rtx_SET (VOIDmode, target, |
1361 | gen_rtx_NOT (mode, | |
1362 | gen_rtx_ASHIFT (mode, sub, | |
f5a1b0d2 | 1363 | shift)))); |
2b835d68 | 1364 | } |
e2c671ba RE |
1365 | return 2; |
1366 | } | |
1367 | ||
5895f793 | 1368 | if (const_ok_for_arm (temp1 = ARM_SIGN_EXTEND (~val))) |
e2c671ba | 1369 | { |
2b835d68 RE |
1370 | if (generate) |
1371 | { | |
1372 | rtx sub = subtargets ? gen_reg_rtx (mode) : target; | |
43cffd11 RE |
1373 | emit_insn (gen_rtx_SET (VOIDmode, sub, |
1374 | gen_rtx_NOT (mode, source))); | |
2b835d68 RE |
1375 | source = sub; |
1376 | if (subtargets) | |
1377 | sub = gen_reg_rtx (mode); | |
43cffd11 RE |
1378 | emit_insn (gen_rtx_SET (VOIDmode, sub, |
1379 | gen_rtx_AND (mode, source, | |
1380 | GEN_INT (temp1)))); | |
1381 | emit_insn (gen_rtx_SET (VOIDmode, target, | |
1382 | gen_rtx_NOT (mode, sub))); | |
2b835d68 | 1383 | } |
e2c671ba RE |
1384 | return 3; |
1385 | } | |
1386 | break; | |
1387 | ||
1388 | case AND: | |
1389 | /* See if two shifts will do 2 or more insn's worth of work. */ | |
1390 | if (clear_sign_bit_copies >= 16 && clear_sign_bit_copies < 24) | |
1391 | { | |
e5951263 | 1392 | HOST_WIDE_INT shift_mask = (((HOST_UINT (0xffffffff)) |
e2c671ba | 1393 | << (32 - clear_sign_bit_copies)) |
e5951263 | 1394 | & HOST_UINT (0xffffffff)); |
e2c671ba | 1395 | |
e5951263 | 1396 | if ((remainder | shift_mask) != HOST_UINT (0xffffffff)) |
e2c671ba | 1397 | { |
2b835d68 RE |
1398 | if (generate) |
1399 | { | |
d499463f | 1400 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
2b835d68 | 1401 | insns = arm_gen_constant (AND, mode, remainder | shift_mask, |
d499463f RE |
1402 | new_src, source, subtargets, 1); |
1403 | source = new_src; | |
2b835d68 RE |
1404 | } |
1405 | else | |
d499463f RE |
1406 | { |
1407 | rtx targ = subtargets ? NULL_RTX : target; | |
1408 | insns = arm_gen_constant (AND, mode, remainder | shift_mask, | |
1409 | targ, source, subtargets, 0); | |
1410 | } | |
2b835d68 RE |
1411 | } |
1412 | ||
1413 | if (generate) | |
1414 | { | |
d499463f RE |
1415 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
1416 | rtx shift = GEN_INT (clear_sign_bit_copies); | |
1417 | ||
1418 | emit_insn (gen_ashlsi3 (new_src, source, shift)); | |
1419 | emit_insn (gen_lshrsi3 (target, new_src, shift)); | |
e2c671ba RE |
1420 | } |
1421 | ||
e2c671ba RE |
1422 | return insns + 2; |
1423 | } | |
1424 | ||
1425 | if (clear_zero_bit_copies >= 16 && clear_zero_bit_copies < 24) | |
1426 | { | |
1427 | HOST_WIDE_INT shift_mask = (1 << clear_zero_bit_copies) - 1; | |
e2c671ba | 1428 | |
e5951263 | 1429 | if ((remainder | shift_mask) != HOST_UINT (0xffffffff)) |
e2c671ba | 1430 | { |
2b835d68 RE |
1431 | if (generate) |
1432 | { | |
d499463f RE |
1433 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
1434 | ||
2b835d68 | 1435 | insns = arm_gen_constant (AND, mode, remainder | shift_mask, |
d499463f RE |
1436 | new_src, source, subtargets, 1); |
1437 | source = new_src; | |
2b835d68 RE |
1438 | } |
1439 | else | |
d499463f RE |
1440 | { |
1441 | rtx targ = subtargets ? NULL_RTX : target; | |
1442 | ||
1443 | insns = arm_gen_constant (AND, mode, remainder | shift_mask, | |
1444 | targ, source, subtargets, 0); | |
1445 | } | |
2b835d68 RE |
1446 | } |
1447 | ||
1448 | if (generate) | |
1449 | { | |
d499463f RE |
1450 | rtx new_src = subtargets ? gen_reg_rtx (mode) : target; |
1451 | rtx shift = GEN_INT (clear_zero_bit_copies); | |
1452 | ||
1453 | emit_insn (gen_lshrsi3 (new_src, source, shift)); | |
1454 | emit_insn (gen_ashlsi3 (target, new_src, shift)); | |
e2c671ba RE |
1455 | } |
1456 | ||
e2c671ba RE |
1457 | return insns + 2; |
1458 | } | |
1459 | ||
1460 | break; | |
1461 | ||
1462 | default: | |
1463 | break; | |
1464 | } | |
1465 | ||
1466 | for (i = 0; i < 32; i++) | |
1467 | if (remainder & (1 << i)) | |
1468 | num_bits_set++; | |
1469 | ||
1470 | if (code == AND || (can_invert && num_bits_set > 16)) | |
e5951263 | 1471 | remainder = (~remainder) & HOST_UINT (0xffffffff); |
e2c671ba | 1472 | else if (code == PLUS && num_bits_set > 16) |
e5951263 | 1473 | remainder = (-remainder) & HOST_UINT (0xffffffff); |
e2c671ba RE |
1474 | else |
1475 | { | |
1476 | can_invert = 0; | |
1477 | can_negate = 0; | |
1478 | } | |
1479 | ||
1480 | /* Now try and find a way of doing the job in either two or three | |
1481 | instructions. | |
1482 | We start by looking for the largest block of zeros that are aligned on | |
1483 | a 2-bit boundary, we then fill up the temps, wrapping around to the | |
1484 | top of the word when we drop off the bottom. | |
6354dc9b | 1485 | In the worst case this code should produce no more than four insns. */ |
e2c671ba RE |
1486 | { |
1487 | int best_start = 0; | |
1488 | int best_consecutive_zeros = 0; | |
1489 | ||
1490 | for (i = 0; i < 32; i += 2) | |
1491 | { | |
1492 | int consecutive_zeros = 0; | |
1493 | ||
5895f793 | 1494 | if (!(remainder & (3 << i))) |
e2c671ba | 1495 | { |
5895f793 | 1496 | while ((i < 32) && !(remainder & (3 << i))) |
e2c671ba RE |
1497 | { |
1498 | consecutive_zeros += 2; | |
1499 | i += 2; | |
1500 | } | |
1501 | if (consecutive_zeros > best_consecutive_zeros) | |
1502 | { | |
1503 | best_consecutive_zeros = consecutive_zeros; | |
1504 | best_start = i - consecutive_zeros; | |
1505 | } | |
1506 | i -= 2; | |
1507 | } | |
1508 | } | |
1509 | ||
ceebdb09 PB |
1510 | /* So long as it won't require any more insns to do so, it's |
1511 | desirable to emit a small constant (in bits 0...9) in the last | |
1512 | insn. This way there is more chance that it can be combined with | |
1513 | a later addressing insn to form a pre-indexed load or store | |
1514 | operation. Consider: | |
1515 | ||
1516 | *((volatile int *)0xe0000100) = 1; | |
1517 | *((volatile int *)0xe0000110) = 2; | |
1518 | ||
1519 | We want this to wind up as: | |
1520 | ||
1521 | mov rA, #0xe0000000 | |
1522 | mov rB, #1 | |
1523 | str rB, [rA, #0x100] | |
1524 | mov rB, #2 | |
1525 | str rB, [rA, #0x110] | |
1526 | ||
1527 | rather than having to synthesize both large constants from scratch. | |
1528 | ||
1529 | Therefore, we calculate how many insns would be required to emit | |
1530 | the constant starting from `best_start', and also starting from | |
1531 | zero (ie with bit 31 first to be output). If `best_start' doesn't | |
1532 | yield a shorter sequence, we may as well use zero. */ | |
1533 | if (best_start != 0 | |
1534 | && ((((unsigned HOST_WIDE_INT) 1) << best_start) < remainder) | |
1535 | && (count_insns_for_constant (remainder, 0) <= | |
1536 | count_insns_for_constant (remainder, best_start))) | |
1537 | best_start = 0; | |
1538 | ||
1539 | /* Now start emitting the insns. */ | |
e2c671ba RE |
1540 | i = best_start; |
1541 | do | |
1542 | { | |
1543 | int end; | |
1544 | ||
1545 | if (i <= 0) | |
1546 | i += 32; | |
1547 | if (remainder & (3 << (i - 2))) | |
1548 | { | |
1549 | end = i - 8; | |
1550 | if (end < 0) | |
1551 | end += 32; | |
1552 | temp1 = remainder & ((0x0ff << end) | |
1553 | | ((i < end) ? (0xff >> (32 - end)) : 0)); | |
1554 | remainder &= ~temp1; | |
1555 | ||
d499463f | 1556 | if (generate) |
e2c671ba | 1557 | { |
d499463f RE |
1558 | rtx new_src; |
1559 | ||
1560 | if (code == SET) | |
43cffd11 RE |
1561 | emit_insn (gen_rtx_SET (VOIDmode, |
1562 | new_src = (subtargets | |
1563 | ? gen_reg_rtx (mode) | |
1564 | : target), | |
1565 | GEN_INT (can_invert | |
1566 | ? ~temp1 : temp1))); | |
d499463f | 1567 | else if (code == MINUS) |
43cffd11 RE |
1568 | emit_insn (gen_rtx_SET (VOIDmode, |
1569 | new_src = (subtargets | |
1570 | ? gen_reg_rtx (mode) | |
1571 | : target), | |
1572 | gen_rtx (code, mode, GEN_INT (temp1), | |
1573 | source))); | |
d499463f | 1574 | else |
43cffd11 RE |
1575 | emit_insn (gen_rtx_SET (VOIDmode, |
1576 | new_src = (remainder | |
1577 | ? (subtargets | |
1578 | ? gen_reg_rtx (mode) | |
1579 | : target) | |
1580 | : target), | |
1581 | gen_rtx (code, mode, source, | |
1582 | GEN_INT (can_invert ? ~temp1 | |
1583 | : (can_negate | |
1584 | ? -temp1 | |
1585 | : temp1))))); | |
d499463f | 1586 | source = new_src; |
e2c671ba RE |
1587 | } |
1588 | ||
d499463f RE |
1589 | if (code == SET) |
1590 | { | |
1591 | can_invert = 0; | |
1592 | code = PLUS; | |
1593 | } | |
1594 | else if (code == MINUS) | |
1595 | code = PLUS; | |
1596 | ||
e2c671ba | 1597 | insns++; |
e2c671ba RE |
1598 | i -= 6; |
1599 | } | |
1600 | i -= 2; | |
1601 | } while (remainder); | |
1602 | } | |
1603 | return insns; | |
1604 | } | |
1605 | ||
bd9c7e23 RE |
1606 | /* Canonicalize a comparison so that we are more likely to recognize it. |
1607 | This can be done for a few constant compares, where we can make the | |
1608 | immediate value easier to load. */ | |
1609 | enum rtx_code | |
1610 | arm_canonicalize_comparison (code, op1) | |
1611 | enum rtx_code code; | |
62b10bbc | 1612 | rtx * op1; |
bd9c7e23 | 1613 | { |
ad076f4e | 1614 | unsigned HOST_WIDE_INT i = INTVAL (*op1); |
bd9c7e23 RE |
1615 | |
1616 | switch (code) | |
1617 | { | |
1618 | case EQ: | |
1619 | case NE: | |
1620 | return code; | |
1621 | ||
1622 | case GT: | |
1623 | case LE: | |
5895f793 RE |
1624 | if (i != (((HOST_UINT (1)) << (HOST_BITS_PER_WIDE_INT - 1)) - 1) |
1625 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) | |
bd9c7e23 | 1626 | { |
5895f793 | 1627 | *op1 = GEN_INT (i + 1); |
bd9c7e23 RE |
1628 | return code == GT ? GE : LT; |
1629 | } | |
1630 | break; | |
1631 | ||
1632 | case GE: | |
1633 | case LT: | |
e5951263 | 1634 | if (i != ((HOST_UINT (1)) << (HOST_BITS_PER_WIDE_INT - 1)) |
5895f793 | 1635 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 | 1636 | { |
5895f793 | 1637 | *op1 = GEN_INT (i - 1); |
bd9c7e23 RE |
1638 | return code == GE ? GT : LE; |
1639 | } | |
1640 | break; | |
1641 | ||
1642 | case GTU: | |
1643 | case LEU: | |
5895f793 RE |
1644 | if (i != ~(HOST_UINT (0)) |
1645 | && (const_ok_for_arm (i + 1) || const_ok_for_arm (-(i + 1)))) | |
bd9c7e23 RE |
1646 | { |
1647 | *op1 = GEN_INT (i + 1); | |
1648 | return code == GTU ? GEU : LTU; | |
1649 | } | |
1650 | break; | |
1651 | ||
1652 | case GEU: | |
1653 | case LTU: | |
1654 | if (i != 0 | |
5895f793 | 1655 | && (const_ok_for_arm (i - 1) || const_ok_for_arm (-(i - 1)))) |
bd9c7e23 RE |
1656 | { |
1657 | *op1 = GEN_INT (i - 1); | |
1658 | return code == GEU ? GTU : LEU; | |
1659 | } | |
1660 | break; | |
1661 | ||
1662 | default: | |
1663 | abort (); | |
1664 | } | |
1665 | ||
1666 | return code; | |
1667 | } | |
bd9c7e23 | 1668 | |
f5a1b0d2 NC |
1669 | /* Decide whether a type should be returned in memory (true) |
1670 | or in a register (false). This is called by the macro | |
1671 | RETURN_IN_MEMORY. */ | |
2b835d68 RE |
1672 | int |
1673 | arm_return_in_memory (type) | |
1674 | tree type; | |
1675 | { | |
5895f793 | 1676 | if (!AGGREGATE_TYPE_P (type)) |
9e291dbe | 1677 | /* All simple types are returned in registers. */ |
d7d01975 | 1678 | return 0; |
d5b7b3ae RE |
1679 | |
1680 | /* For the arm-wince targets we choose to be compitable with Microsoft's | |
1681 | ARM and Thumb compilers, which always return aggregates in memory. */ | |
1682 | #ifndef ARM_WINCE | |
1683 | ||
d7d01975 | 1684 | if (int_size_in_bytes (type) > 4) |
9e291dbe | 1685 | /* All structures/unions bigger than one word are returned in memory. */ |
d7d01975 | 1686 | return 1; |
d5b7b3ae | 1687 | |
d7d01975 | 1688 | if (TREE_CODE (type) == RECORD_TYPE) |
2b835d68 RE |
1689 | { |
1690 | tree field; | |
1691 | ||
3a2ea258 RE |
1692 | /* For a struct the APCS says that we only return in a register |
1693 | if the type is 'integer like' and every addressable element | |
1694 | has an offset of zero. For practical purposes this means | |
1695 | that the structure can have at most one non bit-field element | |
1696 | and that this element must be the first one in the structure. */ | |
1697 | ||
f5a1b0d2 NC |
1698 | /* Find the first field, ignoring non FIELD_DECL things which will |
1699 | have been created by C++. */ | |
1700 | for (field = TYPE_FIELDS (type); | |
1701 | field && TREE_CODE (field) != FIELD_DECL; | |
1702 | field = TREE_CHAIN (field)) | |
1703 | continue; | |
1704 | ||
1705 | if (field == NULL) | |
9e291dbe | 1706 | return 0; /* An empty structure. Allowed by an extension to ANSI C. */ |
f5a1b0d2 | 1707 | |
d5b7b3ae RE |
1708 | /* Check that the first field is valid for returning in a register. */ |
1709 | ||
1710 | /* ... Floats are not allowed */ | |
9e291dbe | 1711 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
3a2ea258 RE |
1712 | return 1; |
1713 | ||
d5b7b3ae RE |
1714 | /* ... Aggregates that are not themselves valid for returning in |
1715 | a register are not allowed. */ | |
9e291dbe | 1716 | if (RETURN_IN_MEMORY (TREE_TYPE (field))) |
3a2ea258 | 1717 | return 1; |
6f7ebcbb | 1718 | |
3a2ea258 RE |
1719 | /* Now check the remaining fields, if any. Only bitfields are allowed, |
1720 | since they are not addressable. */ | |
f5a1b0d2 NC |
1721 | for (field = TREE_CHAIN (field); |
1722 | field; | |
1723 | field = TREE_CHAIN (field)) | |
1724 | { | |
1725 | if (TREE_CODE (field) != FIELD_DECL) | |
1726 | continue; | |
1727 | ||
5895f793 | 1728 | if (!DECL_BIT_FIELD_TYPE (field)) |
f5a1b0d2 NC |
1729 | return 1; |
1730 | } | |
2b835d68 RE |
1731 | |
1732 | return 0; | |
1733 | } | |
d7d01975 NC |
1734 | |
1735 | if (TREE_CODE (type) == UNION_TYPE) | |
2b835d68 RE |
1736 | { |
1737 | tree field; | |
1738 | ||
1739 | /* Unions can be returned in registers if every element is | |
1740 | integral, or can be returned in an integer register. */ | |
f5a1b0d2 NC |
1741 | for (field = TYPE_FIELDS (type); |
1742 | field; | |
1743 | field = TREE_CHAIN (field)) | |
2b835d68 | 1744 | { |
f5a1b0d2 NC |
1745 | if (TREE_CODE (field) != FIELD_DECL) |
1746 | continue; | |
1747 | ||
6cc8c0b3 NC |
1748 | if (FLOAT_TYPE_P (TREE_TYPE (field))) |
1749 | return 1; | |
1750 | ||
f5a1b0d2 | 1751 | if (RETURN_IN_MEMORY (TREE_TYPE (field))) |
2b835d68 RE |
1752 | return 1; |
1753 | } | |
f5a1b0d2 | 1754 | |
2b835d68 RE |
1755 | return 0; |
1756 | } | |
d5b7b3ae | 1757 | #endif /* not ARM_WINCE */ |
f5a1b0d2 | 1758 | |
d5b7b3ae | 1759 | /* Return all other types in memory. */ |
2b835d68 RE |
1760 | return 1; |
1761 | } | |
1762 | ||
82e9d970 PB |
1763 | /* Initialize a variable CUM of type CUMULATIVE_ARGS |
1764 | for a call to a function whose data type is FNTYPE. | |
1765 | For a library call, FNTYPE is NULL. */ | |
1766 | void | |
1767 | arm_init_cumulative_args (pcum, fntype, libname, indirect) | |
1768 | CUMULATIVE_ARGS * pcum; | |
1769 | tree fntype; | |
1770 | rtx libname ATTRIBUTE_UNUSED; | |
1771 | int indirect ATTRIBUTE_UNUSED; | |
1772 | { | |
1773 | /* On the ARM, the offset starts at 0. */ | |
c27ba912 DM |
1774 | pcum->nregs = ((fntype && aggregate_value_p (TREE_TYPE (fntype))) ? 1 : 0); |
1775 | ||
82e9d970 PB |
1776 | pcum->call_cookie = CALL_NORMAL; |
1777 | ||
1778 | if (TARGET_LONG_CALLS) | |
1779 | pcum->call_cookie = CALL_LONG; | |
1780 | ||
1781 | /* Check for long call/short call attributes. The attributes | |
1782 | override any command line option. */ | |
1783 | if (fntype) | |
1784 | { | |
1785 | if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (fntype))) | |
1786 | pcum->call_cookie = CALL_SHORT; | |
1787 | else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (fntype))) | |
1788 | pcum->call_cookie = CALL_LONG; | |
1789 | } | |
1790 | } | |
1791 | ||
1792 | /* Determine where to put an argument to a function. | |
1793 | Value is zero to push the argument on the stack, | |
1794 | or a hard register in which to store the argument. | |
1795 | ||
1796 | MODE is the argument's machine mode. | |
1797 | TYPE is the data type of the argument (as a tree). | |
1798 | This is null for libcalls where that information may | |
1799 | not be available. | |
1800 | CUM is a variable of type CUMULATIVE_ARGS which gives info about | |
1801 | the preceding args and about the function being called. | |
1802 | NAMED is nonzero if this argument is a named parameter | |
1803 | (otherwise it is an extra parameter matching an ellipsis). */ | |
1804 | rtx | |
1805 | arm_function_arg (pcum, mode, type, named) | |
1806 | CUMULATIVE_ARGS * pcum; | |
1807 | enum machine_mode mode; | |
1808 | tree type ATTRIBUTE_UNUSED; | |
1809 | int named; | |
1810 | { | |
1811 | if (mode == VOIDmode) | |
1812 | /* Compute operand 2 of the call insn. */ | |
1813 | return GEN_INT (pcum->call_cookie); | |
1814 | ||
5895f793 | 1815 | if (!named || pcum->nregs >= NUM_ARG_REGS) |
82e9d970 PB |
1816 | return NULL_RTX; |
1817 | ||
1818 | return gen_rtx_REG (mode, pcum->nregs); | |
1819 | } | |
82e9d970 | 1820 | \f |
c27ba912 DM |
1821 | /* Encode the current state of the #pragma [no_]long_calls. */ |
1822 | typedef enum | |
82e9d970 | 1823 | { |
c27ba912 DM |
1824 | OFF, /* No #pramgma [no_]long_calls is in effect. */ |
1825 | LONG, /* #pragma long_calls is in effect. */ | |
1826 | SHORT /* #pragma no_long_calls is in effect. */ | |
1827 | } arm_pragma_enum; | |
82e9d970 | 1828 | |
c27ba912 | 1829 | static arm_pragma_enum arm_pragma_long_calls = OFF; |
82e9d970 | 1830 | |
8b97c5f8 ZW |
1831 | void |
1832 | arm_pr_long_calls (pfile) | |
1833 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
82e9d970 | 1834 | { |
8b97c5f8 ZW |
1835 | arm_pragma_long_calls = LONG; |
1836 | } | |
1837 | ||
1838 | void | |
1839 | arm_pr_no_long_calls (pfile) | |
1840 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
1841 | { | |
1842 | arm_pragma_long_calls = SHORT; | |
1843 | } | |
1844 | ||
1845 | void | |
1846 | arm_pr_long_calls_off (pfile) | |
1847 | cpp_reader *pfile ATTRIBUTE_UNUSED; | |
1848 | { | |
1849 | arm_pragma_long_calls = OFF; | |
82e9d970 | 1850 | } |
8b97c5f8 | 1851 | |
82e9d970 PB |
1852 | \f |
1853 | /* Return nonzero if IDENTIFIER with arguments ARGS is a valid machine specific | |
1854 | attribute for TYPE. The attributes in ATTRIBUTES have previously been | |
1855 | assigned to TYPE. */ | |
1856 | int | |
1857 | arm_valid_type_attribute_p (type, attributes, identifier, args) | |
1858 | tree type; | |
1859 | tree attributes ATTRIBUTE_UNUSED; | |
1860 | tree identifier; | |
1861 | tree args; | |
1862 | { | |
1863 | if ( TREE_CODE (type) != FUNCTION_TYPE | |
1864 | && TREE_CODE (type) != METHOD_TYPE | |
1865 | && TREE_CODE (type) != FIELD_DECL | |
1866 | && TREE_CODE (type) != TYPE_DECL) | |
1867 | return 0; | |
1868 | ||
1869 | /* Function calls made to this symbol must be done indirectly, because | |
1870 | it may lie outside of the 26 bit addressing range of a normal function | |
1871 | call. */ | |
1872 | if (is_attribute_p ("long_call", identifier)) | |
1873 | return (args == NULL_TREE); | |
c27ba912 | 1874 | |
82e9d970 PB |
1875 | /* Whereas these functions are always known to reside within the 26 bit |
1876 | addressing range. */ | |
1877 | if (is_attribute_p ("short_call", identifier)) | |
1878 | return (args == NULL_TREE); | |
1879 | ||
6d3d9133 NC |
1880 | /* Interrupt Service Routines have special prologue and epilogue requirements. */ |
1881 | if (is_attribute_p ("isr", identifier) | |
1882 | || is_attribute_p ("interrupt", identifier)) | |
1883 | return arm_isr_value (args); | |
1884 | ||
82e9d970 PB |
1885 | return 0; |
1886 | } | |
1887 | ||
1888 | /* Return 0 if the attributes for two types are incompatible, 1 if they | |
1889 | are compatible, and 2 if they are nearly compatible (which causes a | |
1890 | warning to be generated). */ | |
1891 | int | |
1892 | arm_comp_type_attributes (type1, type2) | |
1893 | tree type1; | |
1894 | tree type2; | |
1895 | { | |
1cb8d58a | 1896 | int l1, l2, s1, s2; |
bd7fc26f | 1897 | |
82e9d970 PB |
1898 | /* Check for mismatch of non-default calling convention. */ |
1899 | if (TREE_CODE (type1) != FUNCTION_TYPE) | |
1900 | return 1; | |
1901 | ||
1902 | /* Check for mismatched call attributes. */ | |
1cb8d58a NC |
1903 | l1 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type1)) != NULL; |
1904 | l2 = lookup_attribute ("long_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
1905 | s1 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type1)) != NULL; | |
1906 | s2 = lookup_attribute ("short_call", TYPE_ATTRIBUTES (type2)) != NULL; | |
bd7fc26f NC |
1907 | |
1908 | /* Only bother to check if an attribute is defined. */ | |
1909 | if (l1 | l2 | s1 | s2) | |
1910 | { | |
1911 | /* If one type has an attribute, the other must have the same attribute. */ | |
1cb8d58a | 1912 | if ((l1 != l2) || (s1 != s2)) |
bd7fc26f | 1913 | return 0; |
82e9d970 | 1914 | |
bd7fc26f NC |
1915 | /* Disallow mixed attributes. */ |
1916 | if ((l1 & s2) || (l2 & s1)) | |
1917 | return 0; | |
1918 | } | |
1919 | ||
6d3d9133 NC |
1920 | /* Check for mismatched ISR attribute. */ |
1921 | l1 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type1)) != NULL; | |
1922 | if (! l1) | |
1923 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type1)) != NULL; | |
1924 | l2 = lookup_attribute ("isr", TYPE_ATTRIBUTES (type2)) != NULL; | |
1925 | if (! l2) | |
1926 | l1 = lookup_attribute ("interrupt", TYPE_ATTRIBUTES (type2)) != NULL; | |
1927 | if (l1 != l2) | |
1928 | return 0; | |
1929 | ||
bd7fc26f | 1930 | return 1; |
82e9d970 PB |
1931 | } |
1932 | ||
c27ba912 DM |
1933 | /* Encode long_call or short_call attribute by prefixing |
1934 | symbol name in DECL with a special character FLAG. */ | |
1935 | void | |
1936 | arm_encode_call_attribute (decl, flag) | |
1937 | tree decl; | |
cd2b33d0 | 1938 | int flag; |
c27ba912 | 1939 | { |
3cce094d | 1940 | const char * str = XSTR (XEXP (DECL_RTL (decl), 0), 0); |
6354dc9b | 1941 | int len = strlen (str); |
d19fb8e3 | 1942 | char * newstr; |
c27ba912 DM |
1943 | |
1944 | if (TREE_CODE (decl) != FUNCTION_DECL) | |
1945 | return; | |
1946 | ||
1947 | /* Do not allow weak functions to be treated as short call. */ | |
1948 | if (DECL_WEAK (decl) && flag == SHORT_CALL_FLAG_CHAR) | |
1949 | return; | |
c27ba912 | 1950 | |
520a57c8 ZW |
1951 | newstr = alloca (len + 2); |
1952 | newstr[0] = flag; | |
1953 | strcpy (newstr + 1, str); | |
c27ba912 | 1954 | |
6d3d9133 | 1955 | newstr = (char *) ggc_alloc_string (newstr, len + 1); |
c27ba912 DM |
1956 | XSTR (XEXP (DECL_RTL (decl), 0), 0) = newstr; |
1957 | } | |
1958 | ||
1959 | /* Assigns default attributes to newly defined type. This is used to | |
1960 | set short_call/long_call attributes for function types of | |
1961 | functions defined inside corresponding #pragma scopes. */ | |
1962 | void | |
1963 | arm_set_default_type_attributes (type) | |
1964 | tree type; | |
1965 | { | |
1966 | /* Add __attribute__ ((long_call)) to all functions, when | |
1967 | inside #pragma long_calls or __attribute__ ((short_call)), | |
1968 | when inside #pragma no_long_calls. */ | |
1969 | if (TREE_CODE (type) == FUNCTION_TYPE || TREE_CODE (type) == METHOD_TYPE) | |
1970 | { | |
1971 | tree type_attr_list, attr_name; | |
1972 | type_attr_list = TYPE_ATTRIBUTES (type); | |
1973 | ||
1974 | if (arm_pragma_long_calls == LONG) | |
1975 | attr_name = get_identifier ("long_call"); | |
1976 | else if (arm_pragma_long_calls == SHORT) | |
1977 | attr_name = get_identifier ("short_call"); | |
1978 | else | |
1979 | return; | |
1980 | ||
1981 | type_attr_list = tree_cons (attr_name, NULL_TREE, type_attr_list); | |
1982 | TYPE_ATTRIBUTES (type) = type_attr_list; | |
1983 | } | |
1984 | } | |
1985 | \f | |
1986 | /* Return 1 if the operand is a SYMBOL_REF for a function known to be | |
1987 | defined within the current compilation unit. If this caanot be | |
1988 | determined, then 0 is returned. */ | |
1989 | static int | |
1990 | current_file_function_operand (sym_ref) | |
1991 | rtx sym_ref; | |
1992 | { | |
1993 | /* This is a bit of a fib. A function will have a short call flag | |
1994 | applied to its name if it has the short call attribute, or it has | |
1995 | already been defined within the current compilation unit. */ | |
1996 | if (ENCODED_SHORT_CALL_ATTR_P (XSTR (sym_ref, 0))) | |
1997 | return 1; | |
1998 | ||
6d77b53e | 1999 | /* The current function is always defined within the current compilation |
c27ba912 DM |
2000 | unit. if it s a weak defintion however, then this may not be the real |
2001 | defintion of the function, and so we have to say no. */ | |
2002 | if (sym_ref == XEXP (DECL_RTL (current_function_decl), 0) | |
5895f793 | 2003 | && !DECL_WEAK (current_function_decl)) |
c27ba912 DM |
2004 | return 1; |
2005 | ||
2006 | /* We cannot make the determination - default to returning 0. */ | |
2007 | return 0; | |
2008 | } | |
2009 | ||
2010 | /* Return non-zero if a 32 bit "long_call" should be generated for | |
2011 | this call. We generate a long_call if the function: | |
2012 | ||
2013 | a. has an __attribute__((long call)) | |
2014 | or b. is within the scope of a #pragma long_calls | |
2015 | or c. the -mlong-calls command line switch has been specified | |
2016 | ||
2017 | However we do not generate a long call if the function: | |
2018 | ||
2019 | d. has an __attribute__ ((short_call)) | |
2020 | or e. is inside the scope of a #pragma no_long_calls | |
2021 | or f. has an __attribute__ ((section)) | |
2022 | or g. is defined within the current compilation unit. | |
2023 | ||
2024 | This function will be called by C fragments contained in the machine | |
2025 | description file. CALL_REF and CALL_COOKIE correspond to the matched | |
2026 | rtl operands. CALL_SYMBOL is used to distinguish between | |
2027 | two different callers of the function. It is set to 1 in the | |
2028 | "call_symbol" and "call_symbol_value" patterns and to 0 in the "call" | |
2029 | and "call_value" patterns. This is because of the difference in the | |
2030 | SYM_REFs passed by these patterns. */ | |
2031 | int | |
2032 | arm_is_longcall_p (sym_ref, call_cookie, call_symbol) | |
2033 | rtx sym_ref; | |
2034 | int call_cookie; | |
2035 | int call_symbol; | |
2036 | { | |
5895f793 | 2037 | if (!call_symbol) |
c27ba912 DM |
2038 | { |
2039 | if (GET_CODE (sym_ref) != MEM) | |
2040 | return 0; | |
2041 | ||
2042 | sym_ref = XEXP (sym_ref, 0); | |
2043 | } | |
2044 | ||
2045 | if (GET_CODE (sym_ref) != SYMBOL_REF) | |
2046 | return 0; | |
2047 | ||
2048 | if (call_cookie & CALL_SHORT) | |
2049 | return 0; | |
2050 | ||
2051 | if (TARGET_LONG_CALLS && flag_function_sections) | |
2052 | return 1; | |
2053 | ||
87e27392 | 2054 | if (current_file_function_operand (sym_ref)) |
c27ba912 DM |
2055 | return 0; |
2056 | ||
2057 | return (call_cookie & CALL_LONG) | |
2058 | || ENCODED_LONG_CALL_ATTR_P (XSTR (sym_ref, 0)) | |
2059 | || TARGET_LONG_CALLS; | |
2060 | } | |
f99fce0c RE |
2061 | |
2062 | /* Return non-zero if it is ok to make a tail-call to DECL. */ | |
2063 | int | |
2064 | arm_function_ok_for_sibcall (decl) | |
2065 | tree decl; | |
2066 | { | |
2067 | int call_type = TARGET_LONG_CALLS ? CALL_LONG : CALL_NORMAL; | |
2068 | ||
2069 | /* Never tailcall something for which we have no decl, or if we | |
2070 | are in Thumb mode. */ | |
2071 | if (decl == NULL || TARGET_THUMB) | |
2072 | return 0; | |
2073 | ||
2074 | /* Get the calling method. */ | |
2075 | if (lookup_attribute ("short_call", TYPE_ATTRIBUTES (TREE_TYPE (decl)))) | |
2076 | call_type = CALL_SHORT; | |
2077 | else if (lookup_attribute ("long_call", TYPE_ATTRIBUTES (TREE_TYPE (decl)))) | |
2078 | call_type = CALL_LONG; | |
2079 | ||
2080 | /* Cannot tail-call to long calls, since these are out of range of | |
2081 | a branch instruction. However, if not compiling PIC, we know | |
2082 | we can reach the symbol if it is in this compilation unit. */ | |
5895f793 | 2083 | if (call_type == CALL_LONG && (flag_pic || !TREE_ASM_WRITTEN (decl))) |
f99fce0c RE |
2084 | return 0; |
2085 | ||
2086 | /* If we are interworking and the function is not declared static | |
2087 | then we can't tail-call it unless we know that it exists in this | |
2088 | compilation unit (since it might be a Thumb routine). */ | |
5895f793 | 2089 | if (TARGET_INTERWORK && TREE_PUBLIC (decl) && !TREE_ASM_WRITTEN (decl)) |
f99fce0c RE |
2090 | return 0; |
2091 | ||
6d3d9133 NC |
2092 | /* Never tailcall from an ISR routine - it needs a special exit sequence. */ |
2093 | if (IS_INTERRUPT (arm_current_func_type ())) | |
2094 | return 0; | |
2095 | ||
f99fce0c RE |
2096 | /* Everything else is ok. */ |
2097 | return 1; | |
2098 | } | |
2099 | ||
82e9d970 | 2100 | \f |
32de079a RE |
2101 | int |
2102 | legitimate_pic_operand_p (x) | |
2103 | rtx x; | |
2104 | { | |
d5b7b3ae RE |
2105 | if (CONSTANT_P (x) |
2106 | && flag_pic | |
32de079a RE |
2107 | && (GET_CODE (x) == SYMBOL_REF |
2108 | || (GET_CODE (x) == CONST | |
2109 | && GET_CODE (XEXP (x, 0)) == PLUS | |
2110 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF))) | |
2111 | return 0; | |
2112 | ||
2113 | return 1; | |
2114 | } | |
2115 | ||
2116 | rtx | |
2117 | legitimize_pic_address (orig, mode, reg) | |
2118 | rtx orig; | |
2119 | enum machine_mode mode; | |
2120 | rtx reg; | |
2121 | { | |
2122 | if (GET_CODE (orig) == SYMBOL_REF) | |
2123 | { | |
2124 | rtx pic_ref, address; | |
2125 | rtx insn; | |
2126 | int subregs = 0; | |
2127 | ||
2128 | if (reg == 0) | |
2129 | { | |
893f3d5b | 2130 | if (no_new_pseudos) |
32de079a RE |
2131 | abort (); |
2132 | else | |
2133 | reg = gen_reg_rtx (Pmode); | |
2134 | ||
2135 | subregs = 1; | |
2136 | } | |
2137 | ||
2138 | #ifdef AOF_ASSEMBLER | |
2139 | /* The AOF assembler can generate relocations for these directly, and | |
6354dc9b | 2140 | understands that the PIC register has to be added into the offset. */ |
32de079a RE |
2141 | insn = emit_insn (gen_pic_load_addr_based (reg, orig)); |
2142 | #else | |
2143 | if (subregs) | |
2144 | address = gen_reg_rtx (Pmode); | |
2145 | else | |
2146 | address = reg; | |
2147 | ||
4bec9f7d NC |
2148 | if (TARGET_ARM) |
2149 | emit_insn (gen_pic_load_addr_arm (address, orig)); | |
2150 | else | |
2151 | emit_insn (gen_pic_load_addr_thumb (address, orig)); | |
32de079a | 2152 | |
43cffd11 RE |
2153 | pic_ref = gen_rtx_MEM (Pmode, |
2154 | gen_rtx_PLUS (Pmode, pic_offset_table_rtx, | |
2155 | address)); | |
32de079a RE |
2156 | RTX_UNCHANGING_P (pic_ref) = 1; |
2157 | insn = emit_move_insn (reg, pic_ref); | |
2158 | #endif | |
2159 | current_function_uses_pic_offset_table = 1; | |
2160 | /* Put a REG_EQUAL note on this insn, so that it can be optimized | |
2161 | by loop. */ | |
43cffd11 RE |
2162 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL, orig, |
2163 | REG_NOTES (insn)); | |
32de079a RE |
2164 | return reg; |
2165 | } | |
2166 | else if (GET_CODE (orig) == CONST) | |
2167 | { | |
2168 | rtx base, offset; | |
2169 | ||
2170 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
2171 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
2172 | return orig; | |
2173 | ||
2174 | if (reg == 0) | |
2175 | { | |
893f3d5b | 2176 | if (no_new_pseudos) |
32de079a RE |
2177 | abort (); |
2178 | else | |
2179 | reg = gen_reg_rtx (Pmode); | |
2180 | } | |
2181 | ||
2182 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
2183 | { | |
2184 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, reg); | |
2185 | offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
2186 | base == reg ? 0 : reg); | |
2187 | } | |
2188 | else | |
2189 | abort (); | |
2190 | ||
2191 | if (GET_CODE (offset) == CONST_INT) | |
2192 | { | |
2193 | /* The base register doesn't really matter, we only want to | |
2194 | test the index for the appropriate mode. */ | |
f1008e52 | 2195 | ARM_GO_IF_LEGITIMATE_INDEX (mode, 0, offset, win); |
32de079a | 2196 | |
5895f793 | 2197 | if (!no_new_pseudos) |
32de079a RE |
2198 | offset = force_reg (Pmode, offset); |
2199 | else | |
2200 | abort (); | |
2201 | ||
2202 | win: | |
2203 | if (GET_CODE (offset) == CONST_INT) | |
2204 | return plus_constant_for_output (base, INTVAL (offset)); | |
2205 | } | |
2206 | ||
2207 | if (GET_MODE_SIZE (mode) > 4 | |
2208 | && (GET_MODE_CLASS (mode) == MODE_INT | |
2209 | || TARGET_SOFT_FLOAT)) | |
2210 | { | |
2211 | emit_insn (gen_addsi3 (reg, base, offset)); | |
2212 | return reg; | |
2213 | } | |
2214 | ||
43cffd11 | 2215 | return gen_rtx_PLUS (Pmode, base, offset); |
32de079a RE |
2216 | } |
2217 | else if (GET_CODE (orig) == LABEL_REF) | |
82e9d970 PB |
2218 | { |
2219 | current_function_uses_pic_offset_table = 1; | |
2220 | ||
2221 | if (NEED_GOT_RELOC) | |
d5b7b3ae RE |
2222 | { |
2223 | rtx pic_ref, address = gen_reg_rtx (Pmode); | |
4bec9f7d NC |
2224 | |
2225 | if (TARGET_ARM) | |
2226 | emit_insn (gen_pic_load_addr_arm (address, orig)); | |
2227 | else | |
2228 | emit_insn (gen_pic_load_addr_thumb (address, orig)); | |
d19fb8e3 | 2229 | |
d5b7b3ae RE |
2230 | pic_ref = gen_rtx_PLUS (Pmode, pic_offset_table_rtx, address); |
2231 | ||
2232 | emit_move_insn (address, pic_ref); | |
2233 | return address; | |
2234 | } | |
82e9d970 | 2235 | } |
32de079a RE |
2236 | |
2237 | return orig; | |
2238 | } | |
2239 | ||
c1163e75 PB |
2240 | /* Generate code to load the PIC register. PROLOGUE is true if |
2241 | called from arm_expand_prologue (in which case we want the | |
2242 | generated insns at the start of the function); false if called | |
2243 | by an exception receiver that needs the PIC register reloaded | |
2244 | (in which case the insns are just dumped at the current location). */ | |
eab4abeb | 2245 | |
32de079a | 2246 | void |
eab4abeb NC |
2247 | arm_finalize_pic (prologue) |
2248 | int prologue; | |
32de079a RE |
2249 | { |
2250 | #ifndef AOF_ASSEMBLER | |
c1163e75 | 2251 | rtx l1, pic_tmp, pic_tmp2, seq, pic_rtx; |
32de079a RE |
2252 | rtx global_offset_table; |
2253 | ||
ed0e6530 | 2254 | if (current_function_uses_pic_offset_table == 0 || TARGET_SINGLE_PIC_BASE) |
32de079a RE |
2255 | return; |
2256 | ||
5895f793 | 2257 | if (!flag_pic) |
32de079a RE |
2258 | abort (); |
2259 | ||
2260 | start_sequence (); | |
2261 | l1 = gen_label_rtx (); | |
2262 | ||
43cffd11 | 2263 | global_offset_table = gen_rtx_SYMBOL_REF (Pmode, "_GLOBAL_OFFSET_TABLE_"); |
dfa08768 | 2264 | /* On the ARM the PC register contains 'dot + 8' at the time of the |
d5b7b3ae RE |
2265 | addition, on the Thumb it is 'dot + 4'. */ |
2266 | pic_tmp = plus_constant (gen_rtx_LABEL_REF (Pmode, l1), TARGET_ARM ? 8 : 4); | |
84306176 PB |
2267 | if (GOT_PCREL) |
2268 | pic_tmp2 = gen_rtx_CONST (VOIDmode, | |
43cffd11 | 2269 | gen_rtx_PLUS (Pmode, global_offset_table, pc_rtx)); |
84306176 PB |
2270 | else |
2271 | pic_tmp2 = gen_rtx_CONST (VOIDmode, global_offset_table); | |
43cffd11 RE |
2272 | |
2273 | pic_rtx = gen_rtx_CONST (Pmode, gen_rtx_MINUS (Pmode, pic_tmp2, pic_tmp)); | |
f5a1b0d2 | 2274 | |
d5b7b3ae | 2275 | if (TARGET_ARM) |
4bec9f7d NC |
2276 | { |
2277 | emit_insn (gen_pic_load_addr_arm (pic_offset_table_rtx, pic_rtx)); | |
2278 | emit_insn (gen_pic_add_dot_plus_eight (pic_offset_table_rtx, l1)); | |
2279 | } | |
d5b7b3ae | 2280 | else |
4bec9f7d NC |
2281 | { |
2282 | emit_insn (gen_pic_load_addr_thumb (pic_offset_table_rtx, pic_rtx)); | |
2283 | emit_insn (gen_pic_add_dot_plus_four (pic_offset_table_rtx, l1)); | |
2284 | } | |
32de079a RE |
2285 | |
2286 | seq = gen_sequence (); | |
2287 | end_sequence (); | |
c1163e75 PB |
2288 | if (prologue) |
2289 | emit_insn_after (seq, get_insns ()); | |
2290 | else | |
2291 | emit_insn (seq); | |
32de079a RE |
2292 | |
2293 | /* Need to emit this whether or not we obey regdecls, | |
2294 | since setjmp/longjmp can cause life info to screw up. */ | |
43cffd11 | 2295 | emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx)); |
32de079a RE |
2296 | #endif /* AOF_ASSEMBLER */ |
2297 | } | |
2298 | ||
e2c671ba RE |
2299 | #define REG_OR_SUBREG_REG(X) \ |
2300 | (GET_CODE (X) == REG \ | |
2301 | || (GET_CODE (X) == SUBREG && GET_CODE (SUBREG_REG (X)) == REG)) | |
2302 | ||
2303 | #define REG_OR_SUBREG_RTX(X) \ | |
2304 | (GET_CODE (X) == REG ? (X) : SUBREG_REG (X)) | |
2305 | ||
d5b7b3ae RE |
2306 | #ifndef COSTS_N_INSNS |
2307 | #define COSTS_N_INSNS(N) ((N) * 4 - 2) | |
2308 | #endif | |
e2c671ba RE |
2309 | |
2310 | int | |
d5b7b3ae | 2311 | arm_rtx_costs (x, code, outer) |
e2c671ba | 2312 | rtx x; |
74bbc178 | 2313 | enum rtx_code code; |
d5b7b3ae | 2314 | enum rtx_code outer; |
e2c671ba RE |
2315 | { |
2316 | enum machine_mode mode = GET_MODE (x); | |
2317 | enum rtx_code subcode; | |
2318 | int extra_cost; | |
2319 | ||
d5b7b3ae RE |
2320 | if (TARGET_THUMB) |
2321 | { | |
2322 | switch (code) | |
2323 | { | |
2324 | case ASHIFT: | |
2325 | case ASHIFTRT: | |
2326 | case LSHIFTRT: | |
2327 | case ROTATERT: | |
2328 | case PLUS: | |
2329 | case MINUS: | |
2330 | case COMPARE: | |
2331 | case NEG: | |
2332 | case NOT: | |
2333 | return COSTS_N_INSNS (1); | |
2334 | ||
2335 | case MULT: | |
2336 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2337 | { | |
2338 | int cycles = 0; | |
2339 | unsigned HOST_WIDE_INT i = INTVAL (XEXP (x, 1)); | |
2340 | ||
2341 | while (i) | |
2342 | { | |
2343 | i >>= 2; | |
5895f793 | 2344 | cycles++; |
d5b7b3ae RE |
2345 | } |
2346 | return COSTS_N_INSNS (2) + cycles; | |
2347 | } | |
2348 | return COSTS_N_INSNS (1) + 16; | |
2349 | ||
2350 | case SET: | |
2351 | return (COSTS_N_INSNS (1) | |
2352 | + 4 * ((GET_CODE (SET_SRC (x)) == MEM) | |
2353 | + GET_CODE (SET_DEST (x)) == MEM)); | |
2354 | ||
2355 | case CONST_INT: | |
2356 | if (outer == SET) | |
2357 | { | |
2358 | if ((unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
2359 | return 0; | |
2360 | if (thumb_shiftable_const (INTVAL (x))) | |
2361 | return COSTS_N_INSNS (2); | |
2362 | return COSTS_N_INSNS (3); | |
2363 | } | |
2364 | else if (outer == PLUS | |
2365 | && INTVAL (x) < 256 && INTVAL (x) > -256) | |
2366 | return 0; | |
2367 | else if (outer == COMPARE | |
2368 | && (unsigned HOST_WIDE_INT) INTVAL (x) < 256) | |
2369 | return 0; | |
2370 | else if (outer == ASHIFT || outer == ASHIFTRT | |
2371 | || outer == LSHIFTRT) | |
2372 | return 0; | |
2373 | return COSTS_N_INSNS (2); | |
2374 | ||
2375 | case CONST: | |
2376 | case CONST_DOUBLE: | |
2377 | case LABEL_REF: | |
2378 | case SYMBOL_REF: | |
2379 | return COSTS_N_INSNS (3); | |
2380 | ||
2381 | case UDIV: | |
2382 | case UMOD: | |
2383 | case DIV: | |
2384 | case MOD: | |
2385 | return 100; | |
2386 | ||
2387 | case TRUNCATE: | |
2388 | return 99; | |
2389 | ||
2390 | case AND: | |
2391 | case XOR: | |
2392 | case IOR: | |
2393 | /* XXX guess. */ | |
2394 | return 8; | |
2395 | ||
2396 | case ADDRESSOF: | |
2397 | case MEM: | |
2398 | /* XXX another guess. */ | |
2399 | /* Memory costs quite a lot for the first word, but subsequent words | |
2400 | load at the equivalent of a single insn each. */ | |
2401 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
2402 | + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0)); | |
2403 | ||
2404 | case IF_THEN_ELSE: | |
2405 | /* XXX a guess. */ | |
2406 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
2407 | return 14; | |
2408 | return 2; | |
2409 | ||
2410 | case ZERO_EXTEND: | |
2411 | /* XXX still guessing. */ | |
2412 | switch (GET_MODE (XEXP (x, 0))) | |
2413 | { | |
2414 | case QImode: | |
2415 | return (1 + (mode == DImode ? 4 : 0) | |
2416 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2417 | ||
2418 | case HImode: | |
2419 | return (4 + (mode == DImode ? 4 : 0) | |
2420 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2421 | ||
2422 | case SImode: | |
2423 | return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2424 | ||
2425 | default: | |
2426 | return 99; | |
2427 | } | |
2428 | ||
2429 | default: | |
2430 | return 99; | |
2431 | #if 0 | |
2432 | case FFS: | |
2433 | case FLOAT: | |
2434 | case FIX: | |
2435 | case UNSIGNED_FIX: | |
2436 | /* XXX guess */ | |
2437 | fprintf (stderr, "unexpected code for thumb in rtx_costs: %s\n", | |
2438 | rtx_name[code]); | |
2439 | abort (); | |
2440 | #endif | |
2441 | } | |
2442 | } | |
2443 | ||
e2c671ba RE |
2444 | switch (code) |
2445 | { | |
2446 | case MEM: | |
2447 | /* Memory costs quite a lot for the first word, but subsequent words | |
2448 | load at the equivalent of a single insn each. */ | |
2449 | return (10 + 4 * ((GET_MODE_SIZE (mode) - 1) / UNITS_PER_WORD) | |
2450 | + (CONSTANT_POOL_ADDRESS_P (x) ? 4 : 0)); | |
2451 | ||
2452 | case DIV: | |
2453 | case MOD: | |
2454 | return 100; | |
2455 | ||
2456 | case ROTATE: | |
2457 | if (mode == SImode && GET_CODE (XEXP (x, 1)) == REG) | |
2458 | return 4; | |
2459 | /* Fall through */ | |
2460 | case ROTATERT: | |
2461 | if (mode != SImode) | |
2462 | return 8; | |
2463 | /* Fall through */ | |
2464 | case ASHIFT: case LSHIFTRT: case ASHIFTRT: | |
2465 | if (mode == DImode) | |
2466 | return (8 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : 8) | |
2467 | + ((GET_CODE (XEXP (x, 0)) == REG | |
2468 | || (GET_CODE (XEXP (x, 0)) == SUBREG | |
2469 | && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG)) | |
2470 | ? 0 : 8)); | |
2471 | return (1 + ((GET_CODE (XEXP (x, 0)) == REG | |
2472 | || (GET_CODE (XEXP (x, 0)) == SUBREG | |
2473 | && GET_CODE (SUBREG_REG (XEXP (x, 0))) == REG)) | |
2474 | ? 0 : 4) | |
2475 | + ((GET_CODE (XEXP (x, 1)) == REG | |
2476 | || (GET_CODE (XEXP (x, 1)) == SUBREG | |
2477 | && GET_CODE (SUBREG_REG (XEXP (x, 1))) == REG) | |
2478 | || (GET_CODE (XEXP (x, 1)) == CONST_INT)) | |
2479 | ? 0 : 4)); | |
2480 | ||
2481 | case MINUS: | |
2482 | if (mode == DImode) | |
2483 | return (4 + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 8) | |
2484 | + ((REG_OR_SUBREG_REG (XEXP (x, 0)) | |
2485 | || (GET_CODE (XEXP (x, 0)) == CONST_INT | |
2486 | && const_ok_for_arm (INTVAL (XEXP (x, 0))))) | |
2487 | ? 0 : 8)); | |
2488 | ||
2489 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
2490 | return (2 + ((REG_OR_SUBREG_REG (XEXP (x, 1)) | |
2491 | || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
2492 | && const_double_rtx_ok_for_fpu (XEXP (x, 1)))) | |
2493 | ? 0 : 8) | |
2494 | + ((REG_OR_SUBREG_REG (XEXP (x, 0)) | |
2495 | || (GET_CODE (XEXP (x, 0)) == CONST_DOUBLE | |
2496 | && const_double_rtx_ok_for_fpu (XEXP (x, 0)))) | |
2497 | ? 0 : 8)); | |
2498 | ||
2499 | if (((GET_CODE (XEXP (x, 0)) == CONST_INT | |
2500 | && const_ok_for_arm (INTVAL (XEXP (x, 0))) | |
2501 | && REG_OR_SUBREG_REG (XEXP (x, 1)))) | |
2502 | || (((subcode = GET_CODE (XEXP (x, 1))) == ASHIFT | |
2503 | || subcode == ASHIFTRT || subcode == LSHIFTRT | |
2504 | || subcode == ROTATE || subcode == ROTATERT | |
2505 | || (subcode == MULT | |
2506 | && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT | |
2507 | && ((INTVAL (XEXP (XEXP (x, 1), 1)) & | |
2508 | (INTVAL (XEXP (XEXP (x, 1), 1)) - 1)) == 0))) | |
2509 | && REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 0)) | |
2510 | && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 1), 1)) | |
2511 | || GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT) | |
2512 | && REG_OR_SUBREG_REG (XEXP (x, 0)))) | |
2513 | return 1; | |
2514 | /* Fall through */ | |
2515 | ||
2516 | case PLUS: | |
2517 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
2518 | return (2 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8) | |
2519 | + ((REG_OR_SUBREG_REG (XEXP (x, 1)) | |
2520 | || (GET_CODE (XEXP (x, 1)) == CONST_DOUBLE | |
2521 | && const_double_rtx_ok_for_fpu (XEXP (x, 1)))) | |
2522 | ? 0 : 8)); | |
2523 | ||
2524 | /* Fall through */ | |
2525 | case AND: case XOR: case IOR: | |
2526 | extra_cost = 0; | |
2527 | ||
2528 | /* Normally the frame registers will be spilt into reg+const during | |
2529 | reload, so it is a bad idea to combine them with other instructions, | |
2530 | since then they might not be moved outside of loops. As a compromise | |
2531 | we allow integration with ops that have a constant as their second | |
2532 | operand. */ | |
2533 | if ((REG_OR_SUBREG_REG (XEXP (x, 0)) | |
2534 | && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))) | |
2535 | && GET_CODE (XEXP (x, 1)) != CONST_INT) | |
2536 | || (REG_OR_SUBREG_REG (XEXP (x, 0)) | |
2537 | && ARM_FRAME_RTX (REG_OR_SUBREG_RTX (XEXP (x, 0))))) | |
2538 | extra_cost = 4; | |
2539 | ||
2540 | if (mode == DImode) | |
2541 | return (4 + extra_cost + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 8) | |
2542 | + ((REG_OR_SUBREG_REG (XEXP (x, 1)) | |
2543 | || (GET_CODE (XEXP (x, 1)) == CONST_INT | |
74bbc178 | 2544 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code))) |
e2c671ba RE |
2545 | ? 0 : 8)); |
2546 | ||
2547 | if (REG_OR_SUBREG_REG (XEXP (x, 0))) | |
2548 | return (1 + (GET_CODE (XEXP (x, 1)) == CONST_INT ? 0 : extra_cost) | |
2549 | + ((REG_OR_SUBREG_REG (XEXP (x, 1)) | |
2550 | || (GET_CODE (XEXP (x, 1)) == CONST_INT | |
74bbc178 | 2551 | && const_ok_for_op (INTVAL (XEXP (x, 1)), code))) |
e2c671ba RE |
2552 | ? 0 : 4)); |
2553 | ||
2554 | else if (REG_OR_SUBREG_REG (XEXP (x, 1))) | |
2555 | return (1 + extra_cost | |
2556 | + ((((subcode = GET_CODE (XEXP (x, 0))) == ASHIFT | |
2557 | || subcode == LSHIFTRT || subcode == ASHIFTRT | |
2558 | || subcode == ROTATE || subcode == ROTATERT | |
2559 | || (subcode == MULT | |
2560 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
2561 | && ((INTVAL (XEXP (XEXP (x, 0), 1)) & | |
ad076f4e | 2562 | (INTVAL (XEXP (XEXP (x, 0), 1)) - 1)) == 0))) |
e2c671ba RE |
2563 | && (REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 0))) |
2564 | && ((REG_OR_SUBREG_REG (XEXP (XEXP (x, 0), 1))) | |
ad076f4e | 2565 | || GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT)) |
e2c671ba RE |
2566 | ? 0 : 4)); |
2567 | ||
2568 | return 8; | |
2569 | ||
2570 | case MULT: | |
b111229a | 2571 | /* There is no point basing this on the tuning, since it is always the |
6354dc9b | 2572 | fast variant if it exists at all. */ |
2b835d68 RE |
2573 | if (arm_fast_multiply && mode == DImode |
2574 | && (GET_CODE (XEXP (x, 0)) == GET_CODE (XEXP (x, 1))) | |
2575 | && (GET_CODE (XEXP (x, 0)) == ZERO_EXTEND | |
2576 | || GET_CODE (XEXP (x, 0)) == SIGN_EXTEND)) | |
2577 | return 8; | |
2578 | ||
e2c671ba RE |
2579 | if (GET_MODE_CLASS (mode) == MODE_FLOAT |
2580 | || mode == DImode) | |
2581 | return 30; | |
2582 | ||
2583 | if (GET_CODE (XEXP (x, 1)) == CONST_INT) | |
2584 | { | |
2b835d68 | 2585 | unsigned HOST_WIDE_INT i = (INTVAL (XEXP (x, 1)) |
e5951263 | 2586 | & HOST_UINT (0xffffffff)); |
e2c671ba RE |
2587 | int add_cost = const_ok_for_arm (i) ? 4 : 8; |
2588 | int j; | |
6354dc9b NC |
2589 | |
2590 | /* Tune as appropriate. */ | |
aec3cfba | 2591 | int booth_unit_size = ((tune_flags & FL_FAST_MULT) ? 8 : 2); |
2a5307b1 | 2592 | |
2b835d68 | 2593 | for (j = 0; i && j < 32; j += booth_unit_size) |
e2c671ba | 2594 | { |
2b835d68 | 2595 | i >>= booth_unit_size; |
e2c671ba RE |
2596 | add_cost += 2; |
2597 | } | |
2598 | ||
2599 | return add_cost; | |
2600 | } | |
2601 | ||
aec3cfba | 2602 | return (((tune_flags & FL_FAST_MULT) ? 8 : 30) |
2b835d68 | 2603 | + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4) |
e2c671ba RE |
2604 | + (REG_OR_SUBREG_REG (XEXP (x, 1)) ? 0 : 4)); |
2605 | ||
56636818 JL |
2606 | case TRUNCATE: |
2607 | if (arm_fast_multiply && mode == SImode | |
2608 | && GET_CODE (XEXP (x, 0)) == LSHIFTRT | |
2609 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT | |
2610 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) | |
2611 | == GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 1))) | |
2612 | && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == ZERO_EXTEND | |
2613 | || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == SIGN_EXTEND)) | |
2614 | return 8; | |
2615 | return 99; | |
2616 | ||
e2c671ba RE |
2617 | case NEG: |
2618 | if (GET_MODE_CLASS (mode) == MODE_FLOAT) | |
2619 | return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 6); | |
2620 | /* Fall through */ | |
2621 | case NOT: | |
2622 | if (mode == DImode) | |
2623 | return 4 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4); | |
2624 | ||
2625 | return 1 + (REG_OR_SUBREG_REG (XEXP (x, 0)) ? 0 : 4); | |
2626 | ||
2627 | case IF_THEN_ELSE: | |
2628 | if (GET_CODE (XEXP (x, 1)) == PC || GET_CODE (XEXP (x, 2)) == PC) | |
2629 | return 14; | |
2630 | return 2; | |
2631 | ||
2632 | case COMPARE: | |
2633 | return 1; | |
2634 | ||
2635 | case ABS: | |
2636 | return 4 + (mode == DImode ? 4 : 0); | |
2637 | ||
2638 | case SIGN_EXTEND: | |
2639 | if (GET_MODE (XEXP (x, 0)) == QImode) | |
2640 | return (4 + (mode == DImode ? 4 : 0) | |
2641 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2642 | /* Fall through */ | |
2643 | case ZERO_EXTEND: | |
2644 | switch (GET_MODE (XEXP (x, 0))) | |
2645 | { | |
2646 | case QImode: | |
2647 | return (1 + (mode == DImode ? 4 : 0) | |
2648 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2649 | ||
2650 | case HImode: | |
2651 | return (4 + (mode == DImode ? 4 : 0) | |
2652 | + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
2653 | ||
2654 | case SImode: | |
2655 | return (1 + (GET_CODE (XEXP (x, 0)) == MEM ? 10 : 0)); | |
ad076f4e RE |
2656 | |
2657 | default: | |
2658 | break; | |
e2c671ba RE |
2659 | } |
2660 | abort (); | |
2661 | ||
d5b7b3ae RE |
2662 | case CONST_INT: |
2663 | if (const_ok_for_arm (INTVAL (x))) | |
2664 | return outer == SET ? 2 : -1; | |
2665 | else if (outer == AND | |
5895f793 | 2666 | && const_ok_for_arm (~INTVAL (x))) |
d5b7b3ae RE |
2667 | return -1; |
2668 | else if ((outer == COMPARE | |
2669 | || outer == PLUS || outer == MINUS) | |
5895f793 | 2670 | && const_ok_for_arm (-INTVAL (x))) |
d5b7b3ae RE |
2671 | return -1; |
2672 | else | |
2673 | return 5; | |
2674 | ||
2675 | case CONST: | |
2676 | case LABEL_REF: | |
2677 | case SYMBOL_REF: | |
2678 | return 6; | |
2679 | ||
2680 | case CONST_DOUBLE: | |
2681 | if (const_double_rtx_ok_for_fpu (x)) | |
2682 | return outer == SET ? 2 : -1; | |
2683 | else if ((outer == COMPARE || outer == PLUS) | |
2684 | && neg_const_double_rtx_ok_for_fpu (x)) | |
2685 | return -1; | |
2686 | return 7; | |
2687 | ||
e2c671ba RE |
2688 | default: |
2689 | return 99; | |
2690 | } | |
2691 | } | |
32de079a RE |
2692 | |
2693 | int | |
2694 | arm_adjust_cost (insn, link, dep, cost) | |
2695 | rtx insn; | |
2696 | rtx link; | |
2697 | rtx dep; | |
2698 | int cost; | |
2699 | { | |
2700 | rtx i_pat, d_pat; | |
2701 | ||
d19fb8e3 NC |
2702 | /* Some true dependencies can have a higher cost depending |
2703 | on precisely how certain input operands are used. */ | |
2704 | if (arm_is_xscale | |
2705 | && REG_NOTE_KIND (link) == 0 | |
2706 | && recog_memoized (insn) < 0 | |
2707 | && recog_memoized (dep) < 0) | |
2708 | { | |
2709 | int shift_opnum = get_attr_shift (insn); | |
2710 | enum attr_type attr_type = get_attr_type (dep); | |
2711 | ||
2712 | /* If nonzero, SHIFT_OPNUM contains the operand number of a shifted | |
2713 | operand for INSN. If we have a shifted input operand and the | |
2714 | instruction we depend on is another ALU instruction, then we may | |
2715 | have to account for an additional stall. */ | |
2716 | if (shift_opnum != 0 && attr_type == TYPE_NORMAL) | |
2717 | { | |
2718 | rtx shifted_operand; | |
2719 | int opno; | |
2720 | ||
2721 | /* Get the shifted operand. */ | |
2722 | extract_insn (insn); | |
2723 | shifted_operand = recog_data.operand[shift_opnum]; | |
2724 | ||
2725 | /* Iterate over all the operands in DEP. If we write an operand | |
2726 | that overlaps with SHIFTED_OPERAND, then we have increase the | |
2727 | cost of this dependency. */ | |
2728 | extract_insn (dep); | |
2729 | preprocess_constraints (); | |
2730 | for (opno = 0; opno < recog_data.n_operands; opno++) | |
2731 | { | |
2732 | /* We can ignore strict inputs. */ | |
2733 | if (recog_data.operand_type[opno] == OP_IN) | |
2734 | continue; | |
2735 | ||
2736 | if (reg_overlap_mentioned_p (recog_data.operand[opno], | |
2737 | shifted_operand)) | |
2738 | return 2; | |
2739 | } | |
2740 | } | |
2741 | } | |
2742 | ||
6354dc9b | 2743 | /* XXX This is not strictly true for the FPA. */ |
d5b7b3ae RE |
2744 | if (REG_NOTE_KIND (link) == REG_DEP_ANTI |
2745 | || REG_NOTE_KIND (link) == REG_DEP_OUTPUT) | |
b36ba79f RE |
2746 | return 0; |
2747 | ||
d5b7b3ae RE |
2748 | /* Call insns don't incur a stall, even if they follow a load. */ |
2749 | if (REG_NOTE_KIND (link) == 0 | |
2750 | && GET_CODE (insn) == CALL_INSN) | |
2751 | return 1; | |
2752 | ||
32de079a RE |
2753 | if ((i_pat = single_set (insn)) != NULL |
2754 | && GET_CODE (SET_SRC (i_pat)) == MEM | |
2755 | && (d_pat = single_set (dep)) != NULL | |
2756 | && GET_CODE (SET_DEST (d_pat)) == MEM) | |
2757 | { | |
2758 | /* This is a load after a store, there is no conflict if the load reads | |
2759 | from a cached area. Assume that loads from the stack, and from the | |
2760 | constant pool are cached, and that others will miss. This is a | |
6354dc9b | 2761 | hack. */ |
32de079a | 2762 | |
32de079a RE |
2763 | if (CONSTANT_POOL_ADDRESS_P (XEXP (SET_SRC (i_pat), 0)) |
2764 | || reg_mentioned_p (stack_pointer_rtx, XEXP (SET_SRC (i_pat), 0)) | |
2765 | || reg_mentioned_p (frame_pointer_rtx, XEXP (SET_SRC (i_pat), 0)) | |
2766 | || reg_mentioned_p (hard_frame_pointer_rtx, | |
2767 | XEXP (SET_SRC (i_pat), 0))) | |
949d79eb | 2768 | return 1; |
32de079a RE |
2769 | } |
2770 | ||
2771 | return cost; | |
2772 | } | |
2773 | ||
6354dc9b | 2774 | /* This code has been fixed for cross compilation. */ |
ff9940b0 RE |
2775 | |
2776 | static int fpa_consts_inited = 0; | |
2777 | ||
cd2b33d0 | 2778 | static const char * strings_fpa[8] = |
62b10bbc | 2779 | { |
2b835d68 RE |
2780 | "0", "1", "2", "3", |
2781 | "4", "5", "0.5", "10" | |
2782 | }; | |
ff9940b0 RE |
2783 | |
2784 | static REAL_VALUE_TYPE values_fpa[8]; | |
2785 | ||
2786 | static void | |
2787 | init_fpa_table () | |
2788 | { | |
2789 | int i; | |
2790 | REAL_VALUE_TYPE r; | |
2791 | ||
2792 | for (i = 0; i < 8; i++) | |
2793 | { | |
2794 | r = REAL_VALUE_ATOF (strings_fpa[i], DFmode); | |
2795 | values_fpa[i] = r; | |
2796 | } | |
f3bb6135 | 2797 | |
ff9940b0 RE |
2798 | fpa_consts_inited = 1; |
2799 | } | |
2800 | ||
6354dc9b | 2801 | /* Return TRUE if rtx X is a valid immediate FPU constant. */ |
cce8749e CH |
2802 | |
2803 | int | |
2804 | const_double_rtx_ok_for_fpu (x) | |
2805 | rtx x; | |
2806 | { | |
ff9940b0 RE |
2807 | REAL_VALUE_TYPE r; |
2808 | int i; | |
2809 | ||
2810 | if (!fpa_consts_inited) | |
2811 | init_fpa_table (); | |
2812 | ||
2813 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
2814 | if (REAL_VALUE_MINUS_ZERO (r)) | |
2815 | return 0; | |
f3bb6135 | 2816 | |
ff9940b0 RE |
2817 | for (i = 0; i < 8; i++) |
2818 | if (REAL_VALUES_EQUAL (r, values_fpa[i])) | |
2819 | return 1; | |
f3bb6135 | 2820 | |
ff9940b0 | 2821 | return 0; |
f3bb6135 | 2822 | } |
ff9940b0 | 2823 | |
6354dc9b | 2824 | /* Return TRUE if rtx X is a valid immediate FPU constant. */ |
ff9940b0 RE |
2825 | |
2826 | int | |
2827 | neg_const_double_rtx_ok_for_fpu (x) | |
2828 | rtx x; | |
2829 | { | |
2830 | REAL_VALUE_TYPE r; | |
2831 | int i; | |
2832 | ||
2833 | if (!fpa_consts_inited) | |
2834 | init_fpa_table (); | |
2835 | ||
2836 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
2837 | r = REAL_VALUE_NEGATE (r); | |
2838 | if (REAL_VALUE_MINUS_ZERO (r)) | |
2839 | return 0; | |
f3bb6135 | 2840 | |
ff9940b0 RE |
2841 | for (i = 0; i < 8; i++) |
2842 | if (REAL_VALUES_EQUAL (r, values_fpa[i])) | |
2843 | return 1; | |
f3bb6135 | 2844 | |
ff9940b0 | 2845 | return 0; |
f3bb6135 | 2846 | } |
cce8749e CH |
2847 | \f |
2848 | /* Predicates for `match_operand' and `match_operator'. */ | |
2849 | ||
ff9940b0 | 2850 | /* s_register_operand is the same as register_operand, but it doesn't accept |
56a38cec DE |
2851 | (SUBREG (MEM)...). |
2852 | ||
2853 | This function exists because at the time it was put in it led to better | |
2854 | code. SUBREG(MEM) always needs a reload in the places where | |
2855 | s_register_operand is used, and this seemed to lead to excessive | |
2856 | reloading. */ | |
ff9940b0 RE |
2857 | |
2858 | int | |
2859 | s_register_operand (op, mode) | |
2860 | register rtx op; | |
2861 | enum machine_mode mode; | |
2862 | { | |
2863 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
2864 | return 0; | |
2865 | ||
2866 | if (GET_CODE (op) == SUBREG) | |
f3bb6135 | 2867 | op = SUBREG_REG (op); |
ff9940b0 RE |
2868 | |
2869 | /* We don't consider registers whose class is NO_REGS | |
2870 | to be a register operand. */ | |
d5b7b3ae | 2871 | /* XXX might have to check for lo regs only for thumb ??? */ |
ff9940b0 RE |
2872 | return (GET_CODE (op) == REG |
2873 | && (REGNO (op) >= FIRST_PSEUDO_REGISTER | |
2874 | || REGNO_REG_CLASS (REGNO (op)) != NO_REGS)); | |
2875 | } | |
2876 | ||
b0888988 RE |
2877 | /* A hard register operand (even before reload. */ |
2878 | int | |
2879 | arm_hard_register_operand (op, mode) | |
2880 | register rtx op; | |
2881 | enum machine_mode mode; | |
2882 | { | |
2883 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
2884 | return 0; | |
2885 | ||
2886 | return (GET_CODE (op) == REG | |
2887 | && REGNO (op) < FIRST_PSEUDO_REGISTER); | |
2888 | } | |
2889 | ||
e2c671ba RE |
2890 | /* Only accept reg, subreg(reg), const_int. */ |
2891 | ||
2892 | int | |
2893 | reg_or_int_operand (op, mode) | |
2894 | register rtx op; | |
2895 | enum machine_mode mode; | |
2896 | { | |
2897 | if (GET_CODE (op) == CONST_INT) | |
2898 | return 1; | |
2899 | ||
2900 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
2901 | return 0; | |
2902 | ||
2903 | if (GET_CODE (op) == SUBREG) | |
2904 | op = SUBREG_REG (op); | |
2905 | ||
2906 | /* We don't consider registers whose class is NO_REGS | |
2907 | to be a register operand. */ | |
2908 | return (GET_CODE (op) == REG | |
2909 | && (REGNO (op) >= FIRST_PSEUDO_REGISTER | |
2910 | || REGNO_REG_CLASS (REGNO (op)) != NO_REGS)); | |
2911 | } | |
2912 | ||
ff9940b0 RE |
2913 | /* Return 1 if OP is an item in memory, given that we are in reload. */ |
2914 | ||
2915 | int | |
d5b7b3ae | 2916 | arm_reload_memory_operand (op, mode) |
ff9940b0 | 2917 | rtx op; |
74bbc178 | 2918 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ff9940b0 RE |
2919 | { |
2920 | int regno = true_regnum (op); | |
2921 | ||
5895f793 | 2922 | return (!CONSTANT_P (op) |
ff9940b0 RE |
2923 | && (regno == -1 |
2924 | || (GET_CODE (op) == REG | |
2925 | && REGNO (op) >= FIRST_PSEUDO_REGISTER))); | |
2926 | } | |
2927 | ||
4d818c85 | 2928 | /* Return 1 if OP is a valid memory address, but not valid for a signed byte |
d5b7b3ae RE |
2929 | memory access (architecture V4). |
2930 | MODE is QImode if called when computing contraints, or VOIDmode when | |
2931 | emitting patterns. In this latter case we cannot use memory_operand() | |
2932 | because it will fail on badly formed MEMs, which is precisly what we are | |
2933 | trying to catch. */ | |
4d818c85 RE |
2934 | int |
2935 | bad_signed_byte_operand (op, mode) | |
2936 | rtx op; | |
d5b7b3ae | 2937 | enum machine_mode mode ATTRIBUTE_UNUSED; |
4d818c85 | 2938 | { |
d5b7b3ae | 2939 | #if 0 |
5895f793 | 2940 | if ((mode == QImode && !memory_operand (op, mode)) || GET_CODE (op) != MEM) |
d5b7b3ae RE |
2941 | return 0; |
2942 | #endif | |
2943 | if (GET_CODE (op) != MEM) | |
4d818c85 RE |
2944 | return 0; |
2945 | ||
2946 | op = XEXP (op, 0); | |
2947 | ||
6354dc9b | 2948 | /* A sum of anything more complex than reg + reg or reg + const is bad. */ |
4d818c85 | 2949 | if ((GET_CODE (op) == PLUS || GET_CODE (op) == MINUS) |
5895f793 RE |
2950 | && (!s_register_operand (XEXP (op, 0), VOIDmode) |
2951 | || (!s_register_operand (XEXP (op, 1), VOIDmode) | |
9c8cc54f | 2952 | && GET_CODE (XEXP (op, 1)) != CONST_INT))) |
4d818c85 RE |
2953 | return 1; |
2954 | ||
6354dc9b | 2955 | /* Big constants are also bad. */ |
4d818c85 RE |
2956 | if (GET_CODE (op) == PLUS && GET_CODE (XEXP (op, 1)) == CONST_INT |
2957 | && (INTVAL (XEXP (op, 1)) > 0xff | |
2958 | || -INTVAL (XEXP (op, 1)) > 0xff)) | |
2959 | return 1; | |
2960 | ||
6354dc9b | 2961 | /* Everything else is good, or can will automatically be made so. */ |
4d818c85 RE |
2962 | return 0; |
2963 | } | |
2964 | ||
cce8749e CH |
2965 | /* Return TRUE for valid operands for the rhs of an ARM instruction. */ |
2966 | ||
2967 | int | |
2968 | arm_rhs_operand (op, mode) | |
2969 | rtx op; | |
2970 | enum machine_mode mode; | |
2971 | { | |
ff9940b0 | 2972 | return (s_register_operand (op, mode) |
cce8749e | 2973 | || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op)))); |
f3bb6135 | 2974 | } |
cce8749e | 2975 | |
ff9940b0 RE |
2976 | /* Return TRUE for valid operands for the rhs of an ARM instruction, or a load. |
2977 | */ | |
2978 | ||
2979 | int | |
2980 | arm_rhsm_operand (op, mode) | |
2981 | rtx op; | |
2982 | enum machine_mode mode; | |
2983 | { | |
2984 | return (s_register_operand (op, mode) | |
2985 | || (GET_CODE (op) == CONST_INT && const_ok_for_arm (INTVAL (op))) | |
2986 | || memory_operand (op, mode)); | |
f3bb6135 | 2987 | } |
ff9940b0 RE |
2988 | |
2989 | /* Return TRUE for valid operands for the rhs of an ARM instruction, or if a | |
2990 | constant that is valid when negated. */ | |
2991 | ||
2992 | int | |
2993 | arm_add_operand (op, mode) | |
2994 | rtx op; | |
2995 | enum machine_mode mode; | |
2996 | { | |
d5b7b3ae RE |
2997 | if (TARGET_THUMB) |
2998 | return thumb_cmp_operand (op, mode); | |
2999 | ||
ff9940b0 RE |
3000 | return (s_register_operand (op, mode) |
3001 | || (GET_CODE (op) == CONST_INT | |
3002 | && (const_ok_for_arm (INTVAL (op)) | |
3003 | || const_ok_for_arm (-INTVAL (op))))); | |
f3bb6135 | 3004 | } |
ff9940b0 RE |
3005 | |
3006 | int | |
3007 | arm_not_operand (op, mode) | |
3008 | rtx op; | |
3009 | enum machine_mode mode; | |
3010 | { | |
3011 | return (s_register_operand (op, mode) | |
3012 | || (GET_CODE (op) == CONST_INT | |
3013 | && (const_ok_for_arm (INTVAL (op)) | |
3014 | || const_ok_for_arm (~INTVAL (op))))); | |
f3bb6135 | 3015 | } |
ff9940b0 | 3016 | |
5165176d RE |
3017 | /* Return TRUE if the operand is a memory reference which contains an |
3018 | offsettable address. */ | |
3019 | int | |
3020 | offsettable_memory_operand (op, mode) | |
3021 | register rtx op; | |
3022 | enum machine_mode mode; | |
3023 | { | |
3024 | if (mode == VOIDmode) | |
3025 | mode = GET_MODE (op); | |
3026 | ||
3027 | return (mode == GET_MODE (op) | |
3028 | && GET_CODE (op) == MEM | |
3029 | && offsettable_address_p (reload_completed | reload_in_progress, | |
3030 | mode, XEXP (op, 0))); | |
3031 | } | |
3032 | ||
3033 | /* Return TRUE if the operand is a memory reference which is, or can be | |
3034 | made word aligned by adjusting the offset. */ | |
3035 | int | |
3036 | alignable_memory_operand (op, mode) | |
3037 | register rtx op; | |
3038 | enum machine_mode mode; | |
3039 | { | |
3040 | rtx reg; | |
3041 | ||
3042 | if (mode == VOIDmode) | |
3043 | mode = GET_MODE (op); | |
3044 | ||
3045 | if (mode != GET_MODE (op) || GET_CODE (op) != MEM) | |
3046 | return 0; | |
3047 | ||
3048 | op = XEXP (op, 0); | |
3049 | ||
3050 | return ((GET_CODE (reg = op) == REG | |
3051 | || (GET_CODE (op) == SUBREG | |
3052 | && GET_CODE (reg = SUBREG_REG (op)) == REG) | |
3053 | || (GET_CODE (op) == PLUS | |
3054 | && GET_CODE (XEXP (op, 1)) == CONST_INT | |
3055 | && (GET_CODE (reg = XEXP (op, 0)) == REG | |
3056 | || (GET_CODE (XEXP (op, 0)) == SUBREG | |
3057 | && GET_CODE (reg = SUBREG_REG (XEXP (op, 0))) == REG)))) | |
bdb429a5 | 3058 | && REGNO_POINTER_ALIGN (REGNO (reg)) >= 32); |
5165176d RE |
3059 | } |
3060 | ||
b111229a RE |
3061 | /* Similar to s_register_operand, but does not allow hard integer |
3062 | registers. */ | |
3063 | int | |
3064 | f_register_operand (op, mode) | |
3065 | register rtx op; | |
3066 | enum machine_mode mode; | |
3067 | { | |
3068 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3069 | return 0; | |
3070 | ||
3071 | if (GET_CODE (op) == SUBREG) | |
3072 | op = SUBREG_REG (op); | |
3073 | ||
3074 | /* We don't consider registers whose class is NO_REGS | |
3075 | to be a register operand. */ | |
3076 | return (GET_CODE (op) == REG | |
3077 | && (REGNO (op) >= FIRST_PSEUDO_REGISTER | |
3078 | || REGNO_REG_CLASS (REGNO (op)) == FPU_REGS)); | |
3079 | } | |
3080 | ||
cce8749e CH |
3081 | /* Return TRUE for valid operands for the rhs of an FPU instruction. */ |
3082 | ||
3083 | int | |
3084 | fpu_rhs_operand (op, mode) | |
3085 | rtx op; | |
3086 | enum machine_mode mode; | |
3087 | { | |
ff9940b0 | 3088 | if (s_register_operand (op, mode)) |
f3bb6135 | 3089 | return TRUE; |
9ce71c6f BS |
3090 | |
3091 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3092 | return FALSE; | |
3093 | ||
3094 | if (GET_CODE (op) == CONST_DOUBLE) | |
3095 | return const_double_rtx_ok_for_fpu (op); | |
f3bb6135 RE |
3096 | |
3097 | return FALSE; | |
3098 | } | |
cce8749e | 3099 | |
ff9940b0 RE |
3100 | int |
3101 | fpu_add_operand (op, mode) | |
3102 | rtx op; | |
3103 | enum machine_mode mode; | |
3104 | { | |
3105 | if (s_register_operand (op, mode)) | |
f3bb6135 | 3106 | return TRUE; |
9ce71c6f BS |
3107 | |
3108 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3109 | return FALSE; | |
3110 | ||
3111 | if (GET_CODE (op) == CONST_DOUBLE) | |
f3bb6135 RE |
3112 | return (const_double_rtx_ok_for_fpu (op) |
3113 | || neg_const_double_rtx_ok_for_fpu (op)); | |
3114 | ||
3115 | return FALSE; | |
ff9940b0 RE |
3116 | } |
3117 | ||
cce8749e CH |
3118 | /* Return nonzero if OP is a constant power of two. */ |
3119 | ||
3120 | int | |
3121 | power_of_two_operand (op, mode) | |
3122 | rtx op; | |
74bbc178 | 3123 | enum machine_mode mode ATTRIBUTE_UNUSED; |
cce8749e CH |
3124 | { |
3125 | if (GET_CODE (op) == CONST_INT) | |
3126 | { | |
d5b7b3ae | 3127 | HOST_WIDE_INT value = INTVAL (op); |
f3bb6135 | 3128 | return value != 0 && (value & (value - 1)) == 0; |
cce8749e | 3129 | } |
f3bb6135 RE |
3130 | return FALSE; |
3131 | } | |
cce8749e CH |
3132 | |
3133 | /* Return TRUE for a valid operand of a DImode operation. | |
e9c6b69b | 3134 | Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address). |
ff9940b0 RE |
3135 | Note that this disallows MEM(REG+REG), but allows |
3136 | MEM(PRE/POST_INC/DEC(REG)). */ | |
cce8749e CH |
3137 | |
3138 | int | |
3139 | di_operand (op, mode) | |
3140 | rtx op; | |
3141 | enum machine_mode mode; | |
3142 | { | |
ff9940b0 | 3143 | if (s_register_operand (op, mode)) |
f3bb6135 | 3144 | return TRUE; |
cce8749e | 3145 | |
9ce71c6f BS |
3146 | if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode) |
3147 | return FALSE; | |
3148 | ||
e9c6b69b NC |
3149 | if (GET_CODE (op) == SUBREG) |
3150 | op = SUBREG_REG (op); | |
3151 | ||
cce8749e CH |
3152 | switch (GET_CODE (op)) |
3153 | { | |
3154 | case CONST_DOUBLE: | |
3155 | case CONST_INT: | |
f3bb6135 RE |
3156 | return TRUE; |
3157 | ||
cce8749e | 3158 | case MEM: |
f3bb6135 RE |
3159 | return memory_address_p (DImode, XEXP (op, 0)); |
3160 | ||
cce8749e | 3161 | default: |
f3bb6135 | 3162 | return FALSE; |
cce8749e | 3163 | } |
f3bb6135 | 3164 | } |
cce8749e | 3165 | |
d5b7b3ae RE |
3166 | /* Like di_operand, but don't accept constants. */ |
3167 | int | |
3168 | nonimmediate_di_operand (op, mode) | |
3169 | rtx op; | |
3170 | enum machine_mode mode; | |
3171 | { | |
3172 | if (s_register_operand (op, mode)) | |
3173 | return TRUE; | |
3174 | ||
3175 | if (mode != VOIDmode && GET_MODE (op) != VOIDmode && GET_MODE (op) != DImode) | |
3176 | return FALSE; | |
3177 | ||
3178 | if (GET_CODE (op) == SUBREG) | |
3179 | op = SUBREG_REG (op); | |
3180 | ||
3181 | if (GET_CODE (op) == MEM) | |
3182 | return memory_address_p (DImode, XEXP (op, 0)); | |
3183 | ||
3184 | return FALSE; | |
3185 | } | |
3186 | ||
f3139301 | 3187 | /* Return TRUE for a valid operand of a DFmode operation when -msoft-float. |
e9c6b69b | 3188 | Either: REG, SUBREG, CONST_DOUBLE or MEM(DImode_address). |
f3139301 DE |
3189 | Note that this disallows MEM(REG+REG), but allows |
3190 | MEM(PRE/POST_INC/DEC(REG)). */ | |
3191 | ||
3192 | int | |
3193 | soft_df_operand (op, mode) | |
3194 | rtx op; | |
3195 | enum machine_mode mode; | |
3196 | { | |
3197 | if (s_register_operand (op, mode)) | |
3198 | return TRUE; | |
3199 | ||
9ce71c6f BS |
3200 | if (mode != VOIDmode && GET_MODE (op) != mode) |
3201 | return FALSE; | |
3202 | ||
37b80d2e BS |
3203 | if (GET_CODE (op) == SUBREG && CONSTANT_P (SUBREG_REG (op))) |
3204 | return FALSE; | |
3205 | ||
e9c6b69b NC |
3206 | if (GET_CODE (op) == SUBREG) |
3207 | op = SUBREG_REG (op); | |
9ce71c6f | 3208 | |
f3139301 DE |
3209 | switch (GET_CODE (op)) |
3210 | { | |
3211 | case CONST_DOUBLE: | |
3212 | return TRUE; | |
3213 | ||
3214 | case MEM: | |
3215 | return memory_address_p (DFmode, XEXP (op, 0)); | |
3216 | ||
3217 | default: | |
3218 | return FALSE; | |
3219 | } | |
3220 | } | |
3221 | ||
d5b7b3ae RE |
3222 | /* Like soft_df_operand, but don't accept constants. */ |
3223 | int | |
3224 | nonimmediate_soft_df_operand (op, mode) | |
3225 | rtx op; | |
3226 | enum machine_mode mode; | |
3227 | { | |
3228 | if (s_register_operand (op, mode)) | |
3229 | return TRUE; | |
3230 | ||
3231 | if (mode != VOIDmode && GET_MODE (op) != mode) | |
3232 | return FALSE; | |
3233 | ||
3234 | if (GET_CODE (op) == SUBREG) | |
3235 | op = SUBREG_REG (op); | |
3236 | ||
3237 | if (GET_CODE (op) == MEM) | |
3238 | return memory_address_p (DFmode, XEXP (op, 0)); | |
3239 | return FALSE; | |
3240 | } | |
cce8749e | 3241 | |
d5b7b3ae | 3242 | /* Return TRUE for valid index operands. */ |
cce8749e CH |
3243 | int |
3244 | index_operand (op, mode) | |
3245 | rtx op; | |
3246 | enum machine_mode mode; | |
3247 | { | |
d5b7b3ae | 3248 | return (s_register_operand (op, mode) |
ff9940b0 | 3249 | || (immediate_operand (op, mode) |
d5b7b3ae RE |
3250 | && (GET_CODE (op) != CONST_INT |
3251 | || (INTVAL (op) < 4096 && INTVAL (op) > -4096)))); | |
f3bb6135 | 3252 | } |
cce8749e | 3253 | |
ff9940b0 RE |
3254 | /* Return TRUE for valid shifts by a constant. This also accepts any |
3255 | power of two on the (somewhat overly relaxed) assumption that the | |
6354dc9b | 3256 | shift operator in this case was a mult. */ |
ff9940b0 RE |
3257 | |
3258 | int | |
3259 | const_shift_operand (op, mode) | |
3260 | rtx op; | |
3261 | enum machine_mode mode; | |
3262 | { | |
3263 | return (power_of_two_operand (op, mode) | |
3264 | || (immediate_operand (op, mode) | |
d5b7b3ae RE |
3265 | && (GET_CODE (op) != CONST_INT |
3266 | || (INTVAL (op) < 32 && INTVAL (op) > 0)))); | |
f3bb6135 | 3267 | } |
ff9940b0 | 3268 | |
cce8749e CH |
3269 | /* Return TRUE for arithmetic operators which can be combined with a multiply |
3270 | (shift). */ | |
3271 | ||
3272 | int | |
3273 | shiftable_operator (x, mode) | |
3274 | rtx x; | |
3275 | enum machine_mode mode; | |
3276 | { | |
3277 | if (GET_MODE (x) != mode) | |
3278 | return FALSE; | |
3279 | else | |
3280 | { | |
3281 | enum rtx_code code = GET_CODE (x); | |
3282 | ||
3283 | return (code == PLUS || code == MINUS | |
3284 | || code == IOR || code == XOR || code == AND); | |
3285 | } | |
f3bb6135 | 3286 | } |
cce8749e | 3287 | |
6ab589e0 JL |
3288 | /* Return TRUE for binary logical operators. */ |
3289 | ||
3290 | int | |
3291 | logical_binary_operator (x, mode) | |
3292 | rtx x; | |
3293 | enum machine_mode mode; | |
3294 | { | |
3295 | if (GET_MODE (x) != mode) | |
3296 | return FALSE; | |
3297 | else | |
3298 | { | |
3299 | enum rtx_code code = GET_CODE (x); | |
3300 | ||
3301 | return (code == IOR || code == XOR || code == AND); | |
3302 | } | |
3303 | } | |
3304 | ||
6354dc9b | 3305 | /* Return TRUE for shift operators. */ |
cce8749e CH |
3306 | |
3307 | int | |
3308 | shift_operator (x, mode) | |
3309 | rtx x; | |
3310 | enum machine_mode mode; | |
3311 | { | |
3312 | if (GET_MODE (x) != mode) | |
3313 | return FALSE; | |
3314 | else | |
3315 | { | |
3316 | enum rtx_code code = GET_CODE (x); | |
3317 | ||
ff9940b0 | 3318 | if (code == MULT) |
aec3cfba | 3319 | return power_of_two_operand (XEXP (x, 1), mode); |
f3bb6135 | 3320 | |
e2c671ba RE |
3321 | return (code == ASHIFT || code == ASHIFTRT || code == LSHIFTRT |
3322 | || code == ROTATERT); | |
cce8749e | 3323 | } |
f3bb6135 | 3324 | } |
ff9940b0 | 3325 | |
6354dc9b NC |
3326 | /* Return TRUE if x is EQ or NE. */ |
3327 | int | |
3328 | equality_operator (x, mode) | |
f3bb6135 | 3329 | rtx x; |
74bbc178 | 3330 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ff9940b0 | 3331 | { |
f3bb6135 | 3332 | return GET_CODE (x) == EQ || GET_CODE (x) == NE; |
ff9940b0 RE |
3333 | } |
3334 | ||
e45b72c4 RE |
3335 | /* Return TRUE if x is a comparison operator other than LTGT or UNEQ. */ |
3336 | int | |
3337 | arm_comparison_operator (x, mode) | |
3338 | rtx x; | |
3339 | enum machine_mode mode; | |
3340 | { | |
3341 | return (comparison_operator (x, mode) | |
3342 | && GET_CODE (x) != LTGT | |
3343 | && GET_CODE (x) != UNEQ); | |
3344 | } | |
3345 | ||
6354dc9b | 3346 | /* Return TRUE for SMIN SMAX UMIN UMAX operators. */ |
ff9940b0 RE |
3347 | int |
3348 | minmax_operator (x, mode) | |
3349 | rtx x; | |
3350 | enum machine_mode mode; | |
3351 | { | |
3352 | enum rtx_code code = GET_CODE (x); | |
3353 | ||
3354 | if (GET_MODE (x) != mode) | |
3355 | return FALSE; | |
f3bb6135 | 3356 | |
ff9940b0 | 3357 | return code == SMIN || code == SMAX || code == UMIN || code == UMAX; |
f3bb6135 | 3358 | } |
ff9940b0 | 3359 | |
ff9940b0 | 3360 | /* Return TRUE if this is the condition code register, if we aren't given |
6354dc9b | 3361 | a mode, accept any class CCmode register. */ |
ff9940b0 RE |
3362 | int |
3363 | cc_register (x, mode) | |
f3bb6135 RE |
3364 | rtx x; |
3365 | enum machine_mode mode; | |
ff9940b0 RE |
3366 | { |
3367 | if (mode == VOIDmode) | |
3368 | { | |
3369 | mode = GET_MODE (x); | |
d5b7b3ae | 3370 | |
ff9940b0 RE |
3371 | if (GET_MODE_CLASS (mode) != MODE_CC) |
3372 | return FALSE; | |
3373 | } | |
f3bb6135 | 3374 | |
d5b7b3ae RE |
3375 | if ( GET_MODE (x) == mode |
3376 | && GET_CODE (x) == REG | |
3377 | && REGNO (x) == CC_REGNUM) | |
ff9940b0 | 3378 | return TRUE; |
f3bb6135 | 3379 | |
ff9940b0 RE |
3380 | return FALSE; |
3381 | } | |
5bbe2d40 RE |
3382 | |
3383 | /* Return TRUE if this is the condition code register, if we aren't given | |
84ed5e79 RE |
3384 | a mode, accept any class CCmode register which indicates a dominance |
3385 | expression. */ | |
5bbe2d40 | 3386 | int |
84ed5e79 | 3387 | dominant_cc_register (x, mode) |
5bbe2d40 RE |
3388 | rtx x; |
3389 | enum machine_mode mode; | |
3390 | { | |
3391 | if (mode == VOIDmode) | |
3392 | { | |
3393 | mode = GET_MODE (x); | |
d5b7b3ae | 3394 | |
84ed5e79 | 3395 | if (GET_MODE_CLASS (mode) != MODE_CC) |
5bbe2d40 RE |
3396 | return FALSE; |
3397 | } | |
3398 | ||
d5b7b3ae | 3399 | if ( mode != CC_DNEmode && mode != CC_DEQmode |
84ed5e79 RE |
3400 | && mode != CC_DLEmode && mode != CC_DLTmode |
3401 | && mode != CC_DGEmode && mode != CC_DGTmode | |
3402 | && mode != CC_DLEUmode && mode != CC_DLTUmode | |
3403 | && mode != CC_DGEUmode && mode != CC_DGTUmode) | |
3404 | return FALSE; | |
3405 | ||
d5b7b3ae | 3406 | return cc_register (x, mode); |
5bbe2d40 RE |
3407 | } |
3408 | ||
2b835d68 RE |
3409 | /* Return TRUE if X references a SYMBOL_REF. */ |
3410 | int | |
3411 | symbol_mentioned_p (x) | |
3412 | rtx x; | |
3413 | { | |
6f7d635c | 3414 | register const char * fmt; |
2b835d68 RE |
3415 | register int i; |
3416 | ||
3417 | if (GET_CODE (x) == SYMBOL_REF) | |
3418 | return 1; | |
3419 | ||
3420 | fmt = GET_RTX_FORMAT (GET_CODE (x)); | |
d5b7b3ae | 3421 | |
2b835d68 RE |
3422 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
3423 | { | |
3424 | if (fmt[i] == 'E') | |
3425 | { | |
3426 | register int j; | |
3427 | ||
3428 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
3429 | if (symbol_mentioned_p (XVECEXP (x, i, j))) | |
3430 | return 1; | |
3431 | } | |
3432 | else if (fmt[i] == 'e' && symbol_mentioned_p (XEXP (x, i))) | |
3433 | return 1; | |
3434 | } | |
3435 | ||
3436 | return 0; | |
3437 | } | |
3438 | ||
3439 | /* Return TRUE if X references a LABEL_REF. */ | |
3440 | int | |
3441 | label_mentioned_p (x) | |
3442 | rtx x; | |
3443 | { | |
6f7d635c | 3444 | register const char * fmt; |
2b835d68 RE |
3445 | register int i; |
3446 | ||
3447 | if (GET_CODE (x) == LABEL_REF) | |
3448 | return 1; | |
3449 | ||
3450 | fmt = GET_RTX_FORMAT (GET_CODE (x)); | |
3451 | for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) | |
3452 | { | |
3453 | if (fmt[i] == 'E') | |
3454 | { | |
3455 | register int j; | |
3456 | ||
3457 | for (j = XVECLEN (x, i) - 1; j >= 0; j--) | |
3458 | if (label_mentioned_p (XVECEXP (x, i, j))) | |
3459 | return 1; | |
3460 | } | |
3461 | else if (fmt[i] == 'e' && label_mentioned_p (XEXP (x, i))) | |
3462 | return 1; | |
3463 | } | |
3464 | ||
3465 | return 0; | |
3466 | } | |
3467 | ||
ff9940b0 RE |
3468 | enum rtx_code |
3469 | minmax_code (x) | |
f3bb6135 | 3470 | rtx x; |
ff9940b0 RE |
3471 | { |
3472 | enum rtx_code code = GET_CODE (x); | |
3473 | ||
3474 | if (code == SMAX) | |
3475 | return GE; | |
f3bb6135 | 3476 | else if (code == SMIN) |
ff9940b0 | 3477 | return LE; |
f3bb6135 | 3478 | else if (code == UMIN) |
ff9940b0 | 3479 | return LEU; |
f3bb6135 | 3480 | else if (code == UMAX) |
ff9940b0 | 3481 | return GEU; |
f3bb6135 | 3482 | |
ff9940b0 RE |
3483 | abort (); |
3484 | } | |
3485 | ||
6354dc9b | 3486 | /* Return 1 if memory locations are adjacent. */ |
f3bb6135 | 3487 | int |
ff9940b0 RE |
3488 | adjacent_mem_locations (a, b) |
3489 | rtx a, b; | |
3490 | { | |
3491 | int val0 = 0, val1 = 0; | |
3492 | int reg0, reg1; | |
3493 | ||
3494 | if ((GET_CODE (XEXP (a, 0)) == REG | |
3495 | || (GET_CODE (XEXP (a, 0)) == PLUS | |
3496 | && GET_CODE (XEXP (XEXP (a, 0), 1)) == CONST_INT)) | |
3497 | && (GET_CODE (XEXP (b, 0)) == REG | |
3498 | || (GET_CODE (XEXP (b, 0)) == PLUS | |
3499 | && GET_CODE (XEXP (XEXP (b, 0), 1)) == CONST_INT))) | |
3500 | { | |
3501 | if (GET_CODE (XEXP (a, 0)) == PLUS) | |
3502 | { | |
3503 | reg0 = REGNO (XEXP (XEXP (a, 0), 0)); | |
3504 | val0 = INTVAL (XEXP (XEXP (a, 0), 1)); | |
3505 | } | |
3506 | else | |
3507 | reg0 = REGNO (XEXP (a, 0)); | |
3508 | if (GET_CODE (XEXP (b, 0)) == PLUS) | |
3509 | { | |
3510 | reg1 = REGNO (XEXP (XEXP (b, 0), 0)); | |
3511 | val1 = INTVAL (XEXP (XEXP (b, 0), 1)); | |
3512 | } | |
3513 | else | |
3514 | reg1 = REGNO (XEXP (b, 0)); | |
3515 | return (reg0 == reg1) && ((val1 - val0) == 4 || (val0 - val1) == 4); | |
3516 | } | |
3517 | return 0; | |
3518 | } | |
3519 | ||
3520 | /* Return 1 if OP is a load multiple operation. It is known to be | |
6354dc9b | 3521 | parallel and the first section will be tested. */ |
f3bb6135 | 3522 | int |
ff9940b0 RE |
3523 | load_multiple_operation (op, mode) |
3524 | rtx op; | |
74bbc178 | 3525 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ff9940b0 | 3526 | { |
f3bb6135 | 3527 | HOST_WIDE_INT count = XVECLEN (op, 0); |
ff9940b0 RE |
3528 | int dest_regno; |
3529 | rtx src_addr; | |
f3bb6135 | 3530 | HOST_WIDE_INT i = 1, base = 0; |
ff9940b0 RE |
3531 | rtx elt; |
3532 | ||
3533 | if (count <= 1 | |
3534 | || GET_CODE (XVECEXP (op, 0, 0)) != SET) | |
3535 | return 0; | |
3536 | ||
6354dc9b | 3537 | /* Check to see if this might be a write-back. */ |
ff9940b0 RE |
3538 | if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS) |
3539 | { | |
3540 | i++; | |
3541 | base = 1; | |
3542 | ||
6354dc9b | 3543 | /* Now check it more carefully. */ |
ff9940b0 RE |
3544 | if (GET_CODE (SET_DEST (elt)) != REG |
3545 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG | |
3546 | || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt)) | |
3547 | || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT | |
41e3f998 | 3548 | || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4) |
ff9940b0 | 3549 | return 0; |
ff9940b0 RE |
3550 | } |
3551 | ||
3552 | /* Perform a quick check so we don't blow up below. */ | |
3553 | if (count <= i | |
3554 | || GET_CODE (XVECEXP (op, 0, i - 1)) != SET | |
3555 | || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != REG | |
3556 | || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != MEM) | |
3557 | return 0; | |
3558 | ||
3559 | dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, i - 1))); | |
3560 | src_addr = XEXP (SET_SRC (XVECEXP (op, 0, i - 1)), 0); | |
3561 | ||
3562 | for (; i < count; i++) | |
3563 | { | |
ed4c4348 | 3564 | elt = XVECEXP (op, 0, i); |
ff9940b0 RE |
3565 | |
3566 | if (GET_CODE (elt) != SET | |
3567 | || GET_CODE (SET_DEST (elt)) != REG | |
3568 | || GET_MODE (SET_DEST (elt)) != SImode | |
6354dc9b | 3569 | || REGNO (SET_DEST (elt)) != (unsigned int)(dest_regno + i - base) |
ff9940b0 RE |
3570 | || GET_CODE (SET_SRC (elt)) != MEM |
3571 | || GET_MODE (SET_SRC (elt)) != SImode | |
3572 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS | |
5895f793 | 3573 | || !rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr) |
ff9940b0 RE |
3574 | || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT |
3575 | || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != (i - base) * 4) | |
3576 | return 0; | |
3577 | } | |
3578 | ||
3579 | return 1; | |
3580 | } | |
3581 | ||
3582 | /* Return 1 if OP is a store multiple operation. It is known to be | |
6354dc9b | 3583 | parallel and the first section will be tested. */ |
f3bb6135 | 3584 | int |
ff9940b0 RE |
3585 | store_multiple_operation (op, mode) |
3586 | rtx op; | |
74bbc178 | 3587 | enum machine_mode mode ATTRIBUTE_UNUSED; |
ff9940b0 | 3588 | { |
f3bb6135 | 3589 | HOST_WIDE_INT count = XVECLEN (op, 0); |
ff9940b0 RE |
3590 | int src_regno; |
3591 | rtx dest_addr; | |
f3bb6135 | 3592 | HOST_WIDE_INT i = 1, base = 0; |
ff9940b0 RE |
3593 | rtx elt; |
3594 | ||
3595 | if (count <= 1 | |
3596 | || GET_CODE (XVECEXP (op, 0, 0)) != SET) | |
3597 | return 0; | |
3598 | ||
6354dc9b | 3599 | /* Check to see if this might be a write-back. */ |
ff9940b0 RE |
3600 | if (GET_CODE (SET_SRC (elt = XVECEXP (op, 0, 0))) == PLUS) |
3601 | { | |
3602 | i++; | |
3603 | base = 1; | |
3604 | ||
6354dc9b | 3605 | /* Now check it more carefully. */ |
ff9940b0 RE |
3606 | if (GET_CODE (SET_DEST (elt)) != REG |
3607 | || GET_CODE (XEXP (SET_SRC (elt), 0)) != REG | |
3608 | || REGNO (XEXP (SET_SRC (elt), 0)) != REGNO (SET_DEST (elt)) | |
3609 | || GET_CODE (XEXP (SET_SRC (elt), 1)) != CONST_INT | |
41e3f998 | 3610 | || INTVAL (XEXP (SET_SRC (elt), 1)) != (count - 1) * 4) |
ff9940b0 | 3611 | return 0; |
ff9940b0 RE |
3612 | } |
3613 | ||
3614 | /* Perform a quick check so we don't blow up below. */ | |
3615 | if (count <= i | |
3616 | || GET_CODE (XVECEXP (op, 0, i - 1)) != SET | |
3617 | || GET_CODE (SET_DEST (XVECEXP (op, 0, i - 1))) != MEM | |
3618 | || GET_CODE (SET_SRC (XVECEXP (op, 0, i - 1))) != REG) | |
3619 | return 0; | |
3620 | ||
3621 | src_regno = REGNO (SET_SRC (XVECEXP (op, 0, i - 1))); | |
3622 | dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, i - 1)), 0); | |
3623 | ||
3624 | for (; i < count; i++) | |
3625 | { | |
3626 | elt = XVECEXP (op, 0, i); | |
3627 | ||
3628 | if (GET_CODE (elt) != SET | |
3629 | || GET_CODE (SET_SRC (elt)) != REG | |
3630 | || GET_MODE (SET_SRC (elt)) != SImode | |
6354dc9b | 3631 | || REGNO (SET_SRC (elt)) != (unsigned int)(src_regno + i - base) |
ff9940b0 RE |
3632 | || GET_CODE (SET_DEST (elt)) != MEM |
3633 | || GET_MODE (SET_DEST (elt)) != SImode | |
3634 | || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS | |
5895f793 | 3635 | || !rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr) |
ff9940b0 RE |
3636 | || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT |
3637 | || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != (i - base) * 4) | |
3638 | return 0; | |
3639 | } | |
3640 | ||
3641 | return 1; | |
3642 | } | |
e2c671ba | 3643 | |
84ed5e79 RE |
3644 | int |
3645 | load_multiple_sequence (operands, nops, regs, base, load_offset) | |
62b10bbc | 3646 | rtx * operands; |
84ed5e79 | 3647 | int nops; |
62b10bbc NC |
3648 | int * regs; |
3649 | int * base; | |
3650 | HOST_WIDE_INT * load_offset; | |
84ed5e79 RE |
3651 | { |
3652 | int unsorted_regs[4]; | |
3653 | HOST_WIDE_INT unsorted_offsets[4]; | |
3654 | int order[4]; | |
ad076f4e | 3655 | int base_reg = -1; |
84ed5e79 RE |
3656 | int i; |
3657 | ||
3658 | /* Can only handle 2, 3, or 4 insns at present, though could be easily | |
3659 | extended if required. */ | |
3660 | if (nops < 2 || nops > 4) | |
3661 | abort (); | |
3662 | ||
3663 | /* Loop over the operands and check that the memory references are | |
3664 | suitable (ie immediate offsets from the same base register). At | |
3665 | the same time, extract the target register, and the memory | |
3666 | offsets. */ | |
3667 | for (i = 0; i < nops; i++) | |
3668 | { | |
3669 | rtx reg; | |
3670 | rtx offset; | |
3671 | ||
56636818 JL |
3672 | /* Convert a subreg of a mem into the mem itself. */ |
3673 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
d5b7b3ae | 3674 | operands[nops + i] = alter_subreg (operands[nops + i]); |
56636818 | 3675 | |
84ed5e79 RE |
3676 | if (GET_CODE (operands[nops + i]) != MEM) |
3677 | abort (); | |
3678 | ||
3679 | /* Don't reorder volatile memory references; it doesn't seem worth | |
3680 | looking for the case where the order is ok anyway. */ | |
3681 | if (MEM_VOLATILE_P (operands[nops + i])) | |
3682 | return 0; | |
3683 | ||
3684 | offset = const0_rtx; | |
3685 | ||
3686 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
3687 | || (GET_CODE (reg) == SUBREG | |
3688 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
3689 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
3690 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
3691 | == REG) | |
3692 | || (GET_CODE (reg) == SUBREG | |
3693 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
3694 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
3695 | == CONST_INT))) | |
3696 | { | |
3697 | if (i == 0) | |
3698 | { | |
d5b7b3ae | 3699 | base_reg = REGNO (reg); |
84ed5e79 RE |
3700 | unsorted_regs[0] = (GET_CODE (operands[i]) == REG |
3701 | ? REGNO (operands[i]) | |
3702 | : REGNO (SUBREG_REG (operands[i]))); | |
3703 | order[0] = 0; | |
3704 | } | |
3705 | else | |
3706 | { | |
6354dc9b | 3707 | if (base_reg != (int) REGNO (reg)) |
84ed5e79 RE |
3708 | /* Not addressed from the same base register. */ |
3709 | return 0; | |
3710 | ||
3711 | unsorted_regs[i] = (GET_CODE (operands[i]) == REG | |
3712 | ? REGNO (operands[i]) | |
3713 | : REGNO (SUBREG_REG (operands[i]))); | |
3714 | if (unsorted_regs[i] < unsorted_regs[order[0]]) | |
3715 | order[0] = i; | |
3716 | } | |
3717 | ||
3718 | /* If it isn't an integer register, or if it overwrites the | |
3719 | base register but isn't the last insn in the list, then | |
3720 | we can't do this. */ | |
3721 | if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14 | |
3722 | || (i != nops - 1 && unsorted_regs[i] == base_reg)) | |
3723 | return 0; | |
3724 | ||
3725 | unsorted_offsets[i] = INTVAL (offset); | |
3726 | } | |
3727 | else | |
3728 | /* Not a suitable memory address. */ | |
3729 | return 0; | |
3730 | } | |
3731 | ||
3732 | /* All the useful information has now been extracted from the | |
3733 | operands into unsorted_regs and unsorted_offsets; additionally, | |
3734 | order[0] has been set to the lowest numbered register in the | |
3735 | list. Sort the registers into order, and check that the memory | |
3736 | offsets are ascending and adjacent. */ | |
3737 | ||
3738 | for (i = 1; i < nops; i++) | |
3739 | { | |
3740 | int j; | |
3741 | ||
3742 | order[i] = order[i - 1]; | |
3743 | for (j = 0; j < nops; j++) | |
3744 | if (unsorted_regs[j] > unsorted_regs[order[i - 1]] | |
3745 | && (order[i] == order[i - 1] | |
3746 | || unsorted_regs[j] < unsorted_regs[order[i]])) | |
3747 | order[i] = j; | |
3748 | ||
3749 | /* Have we found a suitable register? if not, one must be used more | |
3750 | than once. */ | |
3751 | if (order[i] == order[i - 1]) | |
3752 | return 0; | |
3753 | ||
3754 | /* Is the memory address adjacent and ascending? */ | |
3755 | if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4) | |
3756 | return 0; | |
3757 | } | |
3758 | ||
3759 | if (base) | |
3760 | { | |
3761 | *base = base_reg; | |
3762 | ||
3763 | for (i = 0; i < nops; i++) | |
3764 | regs[i] = unsorted_regs[order[i]]; | |
3765 | ||
3766 | *load_offset = unsorted_offsets[order[0]]; | |
3767 | } | |
3768 | ||
3769 | if (unsorted_offsets[order[0]] == 0) | |
3770 | return 1; /* ldmia */ | |
3771 | ||
3772 | if (unsorted_offsets[order[0]] == 4) | |
3773 | return 2; /* ldmib */ | |
3774 | ||
3775 | if (unsorted_offsets[order[nops - 1]] == 0) | |
3776 | return 3; /* ldmda */ | |
3777 | ||
3778 | if (unsorted_offsets[order[nops - 1]] == -4) | |
3779 | return 4; /* ldmdb */ | |
3780 | ||
949d79eb RE |
3781 | /* For ARM8,9 & StrongARM, 2 ldr instructions are faster than an ldm |
3782 | if the offset isn't small enough. The reason 2 ldrs are faster | |
3783 | is because these ARMs are able to do more than one cache access | |
3784 | in a single cycle. The ARM9 and StrongARM have Harvard caches, | |
3785 | whilst the ARM8 has a double bandwidth cache. This means that | |
3786 | these cores can do both an instruction fetch and a data fetch in | |
3787 | a single cycle, so the trick of calculating the address into a | |
3788 | scratch register (one of the result regs) and then doing a load | |
3789 | multiple actually becomes slower (and no smaller in code size). | |
3790 | That is the transformation | |
6cc8c0b3 NC |
3791 | |
3792 | ldr rd1, [rbase + offset] | |
3793 | ldr rd2, [rbase + offset + 4] | |
3794 | ||
3795 | to | |
3796 | ||
3797 | add rd1, rbase, offset | |
3798 | ldmia rd1, {rd1, rd2} | |
3799 | ||
949d79eb RE |
3800 | produces worse code -- '3 cycles + any stalls on rd2' instead of |
3801 | '2 cycles + any stalls on rd2'. On ARMs with only one cache | |
3802 | access per cycle, the first sequence could never complete in less | |
3803 | than 6 cycles, whereas the ldm sequence would only take 5 and | |
3804 | would make better use of sequential accesses if not hitting the | |
3805 | cache. | |
3806 | ||
3807 | We cheat here and test 'arm_ld_sched' which we currently know to | |
3808 | only be true for the ARM8, ARM9 and StrongARM. If this ever | |
3809 | changes, then the test below needs to be reworked. */ | |
f5a1b0d2 | 3810 | if (nops == 2 && arm_ld_sched) |
b36ba79f RE |
3811 | return 0; |
3812 | ||
84ed5e79 RE |
3813 | /* Can't do it without setting up the offset, only do this if it takes |
3814 | no more than one insn. */ | |
3815 | return (const_ok_for_arm (unsorted_offsets[order[0]]) | |
3816 | || const_ok_for_arm (-unsorted_offsets[order[0]])) ? 5 : 0; | |
3817 | } | |
3818 | ||
cd2b33d0 | 3819 | const char * |
84ed5e79 | 3820 | emit_ldm_seq (operands, nops) |
62b10bbc | 3821 | rtx * operands; |
84ed5e79 RE |
3822 | int nops; |
3823 | { | |
3824 | int regs[4]; | |
3825 | int base_reg; | |
3826 | HOST_WIDE_INT offset; | |
3827 | char buf[100]; | |
3828 | int i; | |
3829 | ||
3830 | switch (load_multiple_sequence (operands, nops, regs, &base_reg, &offset)) | |
3831 | { | |
3832 | case 1: | |
3833 | strcpy (buf, "ldm%?ia\t"); | |
3834 | break; | |
3835 | ||
3836 | case 2: | |
3837 | strcpy (buf, "ldm%?ib\t"); | |
3838 | break; | |
3839 | ||
3840 | case 3: | |
3841 | strcpy (buf, "ldm%?da\t"); | |
3842 | break; | |
3843 | ||
3844 | case 4: | |
3845 | strcpy (buf, "ldm%?db\t"); | |
3846 | break; | |
3847 | ||
3848 | case 5: | |
3849 | if (offset >= 0) | |
3850 | sprintf (buf, "add%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX, | |
3851 | reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg], | |
3852 | (long) offset); | |
3853 | else | |
3854 | sprintf (buf, "sub%%?\t%s%s, %s%s, #%ld", REGISTER_PREFIX, | |
3855 | reg_names[regs[0]], REGISTER_PREFIX, reg_names[base_reg], | |
3856 | (long) -offset); | |
3857 | output_asm_insn (buf, operands); | |
3858 | base_reg = regs[0]; | |
3859 | strcpy (buf, "ldm%?ia\t"); | |
3860 | break; | |
3861 | ||
3862 | default: | |
3863 | abort (); | |
3864 | } | |
3865 | ||
3866 | sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX, | |
3867 | reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]); | |
3868 | ||
3869 | for (i = 1; i < nops; i++) | |
3870 | sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX, | |
3871 | reg_names[regs[i]]); | |
3872 | ||
3873 | strcat (buf, "}\t%@ phole ldm"); | |
3874 | ||
3875 | output_asm_insn (buf, operands); | |
3876 | return ""; | |
3877 | } | |
3878 | ||
3879 | int | |
3880 | store_multiple_sequence (operands, nops, regs, base, load_offset) | |
62b10bbc | 3881 | rtx * operands; |
84ed5e79 | 3882 | int nops; |
62b10bbc NC |
3883 | int * regs; |
3884 | int * base; | |
3885 | HOST_WIDE_INT * load_offset; | |
84ed5e79 RE |
3886 | { |
3887 | int unsorted_regs[4]; | |
3888 | HOST_WIDE_INT unsorted_offsets[4]; | |
3889 | int order[4]; | |
ad076f4e | 3890 | int base_reg = -1; |
84ed5e79 RE |
3891 | int i; |
3892 | ||
3893 | /* Can only handle 2, 3, or 4 insns at present, though could be easily | |
3894 | extended if required. */ | |
3895 | if (nops < 2 || nops > 4) | |
3896 | abort (); | |
3897 | ||
3898 | /* Loop over the operands and check that the memory references are | |
3899 | suitable (ie immediate offsets from the same base register). At | |
3900 | the same time, extract the target register, and the memory | |
3901 | offsets. */ | |
3902 | for (i = 0; i < nops; i++) | |
3903 | { | |
3904 | rtx reg; | |
3905 | rtx offset; | |
3906 | ||
56636818 JL |
3907 | /* Convert a subreg of a mem into the mem itself. */ |
3908 | if (GET_CODE (operands[nops + i]) == SUBREG) | |
d5b7b3ae | 3909 | operands[nops + i] = alter_subreg (operands[nops + i]); |
56636818 | 3910 | |
84ed5e79 RE |
3911 | if (GET_CODE (operands[nops + i]) != MEM) |
3912 | abort (); | |
3913 | ||
3914 | /* Don't reorder volatile memory references; it doesn't seem worth | |
3915 | looking for the case where the order is ok anyway. */ | |
3916 | if (MEM_VOLATILE_P (operands[nops + i])) | |
3917 | return 0; | |
3918 | ||
3919 | offset = const0_rtx; | |
3920 | ||
3921 | if ((GET_CODE (reg = XEXP (operands[nops + i], 0)) == REG | |
3922 | || (GET_CODE (reg) == SUBREG | |
3923 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
3924 | || (GET_CODE (XEXP (operands[nops + i], 0)) == PLUS | |
3925 | && ((GET_CODE (reg = XEXP (XEXP (operands[nops + i], 0), 0)) | |
3926 | == REG) | |
3927 | || (GET_CODE (reg) == SUBREG | |
3928 | && GET_CODE (reg = SUBREG_REG (reg)) == REG)) | |
3929 | && (GET_CODE (offset = XEXP (XEXP (operands[nops + i], 0), 1)) | |
3930 | == CONST_INT))) | |
3931 | { | |
3932 | if (i == 0) | |
3933 | { | |
62b10bbc | 3934 | base_reg = REGNO (reg); |
84ed5e79 RE |
3935 | unsorted_regs[0] = (GET_CODE (operands[i]) == REG |
3936 | ? REGNO (operands[i]) | |
3937 | : REGNO (SUBREG_REG (operands[i]))); | |
3938 | order[0] = 0; | |
3939 | } | |
3940 | else | |
3941 | { | |
6354dc9b | 3942 | if (base_reg != (int) REGNO (reg)) |
84ed5e79 RE |
3943 | /* Not addressed from the same base register. */ |
3944 | return 0; | |
3945 | ||
3946 | unsorted_regs[i] = (GET_CODE (operands[i]) == REG | |
3947 | ? REGNO (operands[i]) | |
3948 | : REGNO (SUBREG_REG (operands[i]))); | |
3949 | if (unsorted_regs[i] < unsorted_regs[order[0]]) | |
3950 | order[0] = i; | |
3951 | } | |
3952 | ||
3953 | /* If it isn't an integer register, then we can't do this. */ | |
3954 | if (unsorted_regs[i] < 0 || unsorted_regs[i] > 14) | |
3955 | return 0; | |
3956 | ||
3957 | unsorted_offsets[i] = INTVAL (offset); | |
3958 | } | |
3959 | else | |
3960 | /* Not a suitable memory address. */ | |
3961 | return 0; | |
3962 | } | |
3963 | ||
3964 | /* All the useful information has now been extracted from the | |
3965 | operands into unsorted_regs and unsorted_offsets; additionally, | |
3966 | order[0] has been set to the lowest numbered register in the | |
3967 | list. Sort the registers into order, and check that the memory | |
3968 | offsets are ascending and adjacent. */ | |
3969 | ||
3970 | for (i = 1; i < nops; i++) | |
3971 | { | |
3972 | int j; | |
3973 | ||
3974 | order[i] = order[i - 1]; | |
3975 | for (j = 0; j < nops; j++) | |
3976 | if (unsorted_regs[j] > unsorted_regs[order[i - 1]] | |
3977 | && (order[i] == order[i - 1] | |
3978 | || unsorted_regs[j] < unsorted_regs[order[i]])) | |
3979 | order[i] = j; | |
3980 | ||
3981 | /* Have we found a suitable register? if not, one must be used more | |
3982 | than once. */ | |
3983 | if (order[i] == order[i - 1]) | |
3984 | return 0; | |
3985 | ||
3986 | /* Is the memory address adjacent and ascending? */ | |
3987 | if (unsorted_offsets[order[i]] != unsorted_offsets[order[i - 1]] + 4) | |
3988 | return 0; | |
3989 | } | |
3990 | ||
3991 | if (base) | |
3992 | { | |
3993 | *base = base_reg; | |
3994 | ||
3995 | for (i = 0; i < nops; i++) | |
3996 | regs[i] = unsorted_regs[order[i]]; | |
3997 | ||
3998 | *load_offset = unsorted_offsets[order[0]]; | |
3999 | } | |
4000 | ||
4001 | if (unsorted_offsets[order[0]] == 0) | |
4002 | return 1; /* stmia */ | |
4003 | ||
4004 | if (unsorted_offsets[order[0]] == 4) | |
4005 | return 2; /* stmib */ | |
4006 | ||
4007 | if (unsorted_offsets[order[nops - 1]] == 0) | |
4008 | return 3; /* stmda */ | |
4009 | ||
4010 | if (unsorted_offsets[order[nops - 1]] == -4) | |
4011 | return 4; /* stmdb */ | |
4012 | ||
4013 | return 0; | |
4014 | } | |
4015 | ||
cd2b33d0 | 4016 | const char * |
84ed5e79 | 4017 | emit_stm_seq (operands, nops) |
62b10bbc | 4018 | rtx * operands; |
84ed5e79 RE |
4019 | int nops; |
4020 | { | |
4021 | int regs[4]; | |
4022 | int base_reg; | |
4023 | HOST_WIDE_INT offset; | |
4024 | char buf[100]; | |
4025 | int i; | |
4026 | ||
4027 | switch (store_multiple_sequence (operands, nops, regs, &base_reg, &offset)) | |
4028 | { | |
4029 | case 1: | |
4030 | strcpy (buf, "stm%?ia\t"); | |
4031 | break; | |
4032 | ||
4033 | case 2: | |
4034 | strcpy (buf, "stm%?ib\t"); | |
4035 | break; | |
4036 | ||
4037 | case 3: | |
4038 | strcpy (buf, "stm%?da\t"); | |
4039 | break; | |
4040 | ||
4041 | case 4: | |
4042 | strcpy (buf, "stm%?db\t"); | |
4043 | break; | |
4044 | ||
4045 | default: | |
4046 | abort (); | |
4047 | } | |
4048 | ||
4049 | sprintf (buf + strlen (buf), "%s%s, {%s%s", REGISTER_PREFIX, | |
4050 | reg_names[base_reg], REGISTER_PREFIX, reg_names[regs[0]]); | |
4051 | ||
4052 | for (i = 1; i < nops; i++) | |
4053 | sprintf (buf + strlen (buf), ", %s%s", REGISTER_PREFIX, | |
4054 | reg_names[regs[i]]); | |
4055 | ||
4056 | strcat (buf, "}\t%@ phole stm"); | |
4057 | ||
4058 | output_asm_insn (buf, operands); | |
4059 | return ""; | |
4060 | } | |
4061 | ||
e2c671ba RE |
4062 | int |
4063 | multi_register_push (op, mode) | |
0a81f500 | 4064 | rtx op; |
74bbc178 | 4065 | enum machine_mode mode ATTRIBUTE_UNUSED; |
e2c671ba RE |
4066 | { |
4067 | if (GET_CODE (op) != PARALLEL | |
4068 | || (GET_CODE (XVECEXP (op, 0, 0)) != SET) | |
4069 | || (GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != UNSPEC) | |
b15bca31 | 4070 | || (XINT (SET_SRC (XVECEXP (op, 0, 0)), 1) != UNSPEC_PUSH_MULT)) |
e2c671ba RE |
4071 | return 0; |
4072 | ||
4073 | return 1; | |
4074 | } | |
ff9940b0 | 4075 | \f |
d7d01975 | 4076 | /* Routines for use with attributes. */ |
f3bb6135 | 4077 | |
31fdb4d5 | 4078 | /* Return nonzero if ATTR is a valid attribute for DECL. |
d7d01975 NC |
4079 | ATTRIBUTES are any existing attributes and ARGS are |
4080 | the arguments supplied with ATTR. | |
31fdb4d5 DE |
4081 | |
4082 | Supported attributes: | |
4083 | ||
d5b7b3ae RE |
4084 | naked: |
4085 | don't output any prologue or epilogue code, the user is assumed | |
4086 | to do the right thing. | |
4087 | ||
6d3d9133 NC |
4088 | isr or interrupt: |
4089 | Interrupt Service Routine. | |
4090 | ||
d5b7b3ae RE |
4091 | interfacearm: |
4092 | Always assume that this function will be entered in ARM mode, | |
4093 | not Thumb mode, and that the caller wishes to be returned to in | |
4094 | ARM mode. */ | |
31fdb4d5 | 4095 | int |
74bbc178 | 4096 | arm_valid_machine_decl_attribute (decl, attr, args) |
31fdb4d5 | 4097 | tree decl; |
31fdb4d5 DE |
4098 | tree attr; |
4099 | tree args; | |
4100 | { | |
6d3d9133 NC |
4101 | /* The interrupt attribute can take args, so check for it before |
4102 | rejecting other attributes on the grounds that they did have args. */ | |
4103 | if (is_attribute_p ("isr", attr) | |
4104 | || is_attribute_p ("interrupt", attr)) | |
4105 | return TREE_CODE (decl) == FUNCTION_DECL; | |
4106 | ||
31fdb4d5 DE |
4107 | if (args != NULL_TREE) |
4108 | return 0; | |
4109 | ||
4110 | if (is_attribute_p ("naked", attr)) | |
4111 | return TREE_CODE (decl) == FUNCTION_DECL; | |
d19fb8e3 | 4112 | |
d5b7b3ae RE |
4113 | #ifdef ARM_PE |
4114 | if (is_attribute_p ("interfacearm", attr)) | |
4115 | return TREE_CODE (decl) == FUNCTION_DECL; | |
4116 | #endif /* ARM_PE */ | |
4117 | ||
31fdb4d5 DE |
4118 | return 0; |
4119 | } | |
f3bb6135 | 4120 | \f |
6354dc9b | 4121 | /* Routines for use in generating RTL. */ |
f3bb6135 | 4122 | rtx |
56636818 | 4123 | arm_gen_load_multiple (base_regno, count, from, up, write_back, unchanging_p, |
c6df88cb | 4124 | in_struct_p, scalar_p) |
ff9940b0 RE |
4125 | int base_regno; |
4126 | int count; | |
4127 | rtx from; | |
4128 | int up; | |
4129 | int write_back; | |
56636818 JL |
4130 | int unchanging_p; |
4131 | int in_struct_p; | |
c6df88cb | 4132 | int scalar_p; |
ff9940b0 RE |
4133 | { |
4134 | int i = 0, j; | |
4135 | rtx result; | |
4136 | int sign = up ? 1 : -1; | |
56636818 | 4137 | rtx mem; |
ff9940b0 | 4138 | |
d19fb8e3 NC |
4139 | /* XScale has load-store double instructions, but they have stricter |
4140 | alignment requirements than load-store multiple, so we can not | |
4141 | use them. | |
4142 | ||
4143 | For XScale ldm requires 2 + NREGS cycles to complete and blocks | |
4144 | the pipeline until completion. | |
4145 | ||
4146 | NREGS CYCLES | |
4147 | 1 3 | |
4148 | 2 4 | |
4149 | 3 5 | |
4150 | 4 6 | |
4151 | ||
4152 | An ldr instruction takes 1-3 cycles, but does not block the | |
4153 | pipeline. | |
4154 | ||
4155 | NREGS CYCLES | |
4156 | 1 1-3 | |
4157 | 2 2-6 | |
4158 | 3 3-9 | |
4159 | 4 4-12 | |
4160 | ||
4161 | Best case ldr will always win. However, the more ldr instructions | |
4162 | we issue, the less likely we are to be able to schedule them well. | |
4163 | Using ldr instructions also increases code size. | |
4164 | ||
4165 | As a compromise, we use ldr for counts of 1 or 2 regs, and ldm | |
4166 | for counts of 3 or 4 regs. */ | |
4167 | if (arm_is_xscale && count <= 2 && ! optimize_size) | |
4168 | { | |
4169 | rtx seq; | |
4170 | ||
4171 | start_sequence (); | |
4172 | ||
4173 | for (i = 0; i < count; i++) | |
4174 | { | |
4175 | mem = gen_rtx_MEM (SImode, plus_constant (from, i * 4 * sign)); | |
4176 | RTX_UNCHANGING_P (mem) = unchanging_p; | |
4177 | MEM_IN_STRUCT_P (mem) = in_struct_p; | |
4178 | MEM_SCALAR_P (mem) = scalar_p; | |
4179 | emit_move_insn (gen_rtx_REG (SImode, base_regno + i), mem); | |
4180 | } | |
4181 | ||
4182 | if (write_back) | |
4183 | emit_move_insn (from, plus_constant (from, count * 4 * sign)); | |
4184 | ||
4185 | seq = gen_sequence (); | |
4186 | end_sequence (); | |
4187 | ||
4188 | return seq; | |
4189 | } | |
4190 | ||
43cffd11 | 4191 | result = gen_rtx_PARALLEL (VOIDmode, |
41e3f998 | 4192 | rtvec_alloc (count + (write_back ? 1 : 0))); |
ff9940b0 | 4193 | if (write_back) |
f3bb6135 | 4194 | { |
ff9940b0 | 4195 | XVECEXP (result, 0, 0) |
43cffd11 RE |
4196 | = gen_rtx_SET (GET_MODE (from), from, |
4197 | plus_constant (from, count * 4 * sign)); | |
ff9940b0 RE |
4198 | i = 1; |
4199 | count++; | |
f3bb6135 RE |
4200 | } |
4201 | ||
ff9940b0 | 4202 | for (j = 0; i < count; i++, j++) |
f3bb6135 | 4203 | { |
43cffd11 | 4204 | mem = gen_rtx_MEM (SImode, plus_constant (from, j * 4 * sign)); |
56636818 JL |
4205 | RTX_UNCHANGING_P (mem) = unchanging_p; |
4206 | MEM_IN_STRUCT_P (mem) = in_struct_p; | |
c6df88cb | 4207 | MEM_SCALAR_P (mem) = scalar_p; |
43cffd11 RE |
4208 | XVECEXP (result, 0, i) |
4209 | = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, base_regno + j), mem); | |
f3bb6135 RE |
4210 | } |
4211 | ||
ff9940b0 RE |
4212 | return result; |
4213 | } | |
4214 | ||
f3bb6135 | 4215 | rtx |
56636818 | 4216 | arm_gen_store_multiple (base_regno, count, to, up, write_back, unchanging_p, |
c6df88cb | 4217 | in_struct_p, scalar_p) |
ff9940b0 RE |
4218 | int base_regno; |
4219 | int count; | |
4220 | rtx to; | |
4221 | int up; | |
4222 | int write_back; | |
56636818 JL |
4223 | int unchanging_p; |
4224 | int in_struct_p; | |
c6df88cb | 4225 | int scalar_p; |
ff9940b0 RE |
4226 | { |
4227 | int i = 0, j; | |
4228 | rtx result; | |
4229 | int sign = up ? 1 : -1; | |
56636818 | 4230 | rtx mem; |
ff9940b0 | 4231 | |
d19fb8e3 NC |
4232 | /* See arm_gen_load_multiple for discussion of |
4233 | the pros/cons of ldm/stm usage for XScale. */ | |
4234 | if (arm_is_xscale && count <= 2 && ! optimize_size) | |
4235 | { | |
4236 | rtx seq; | |
4237 | ||
4238 | start_sequence (); | |
4239 | ||
4240 | for (i = 0; i < count; i++) | |
4241 | { | |
4242 | mem = gen_rtx_MEM (SImode, plus_constant (to, i * 4 * sign)); | |
4243 | RTX_UNCHANGING_P (mem) = unchanging_p; | |
4244 | MEM_IN_STRUCT_P (mem) = in_struct_p; | |
4245 | MEM_SCALAR_P (mem) = scalar_p; | |
4246 | emit_move_insn (mem, gen_rtx_REG (SImode, base_regno + i)); | |
4247 | } | |
4248 | ||
4249 | if (write_back) | |
4250 | emit_move_insn (to, plus_constant (to, count * 4 * sign)); | |
4251 | ||
4252 | seq = gen_sequence (); | |
4253 | end_sequence (); | |
4254 | ||
4255 | return seq; | |
4256 | } | |
4257 | ||
43cffd11 | 4258 | result = gen_rtx_PARALLEL (VOIDmode, |
41e3f998 | 4259 | rtvec_alloc (count + (write_back ? 1 : 0))); |
ff9940b0 | 4260 | if (write_back) |
f3bb6135 | 4261 | { |
ff9940b0 | 4262 | XVECEXP (result, 0, 0) |
43cffd11 RE |
4263 | = gen_rtx_SET (GET_MODE (to), to, |
4264 | plus_constant (to, count * 4 * sign)); | |
ff9940b0 RE |
4265 | i = 1; |
4266 | count++; | |
f3bb6135 RE |
4267 | } |
4268 | ||
ff9940b0 | 4269 | for (j = 0; i < count; i++, j++) |
f3bb6135 | 4270 | { |
43cffd11 | 4271 | mem = gen_rtx_MEM (SImode, plus_constant (to, j * 4 * sign)); |
56636818 JL |
4272 | RTX_UNCHANGING_P (mem) = unchanging_p; |
4273 | MEM_IN_STRUCT_P (mem) = in_struct_p; | |
c6df88cb | 4274 | MEM_SCALAR_P (mem) = scalar_p; |
56636818 | 4275 | |
43cffd11 RE |
4276 | XVECEXP (result, 0, i) |
4277 | = gen_rtx_SET (VOIDmode, mem, gen_rtx_REG (SImode, base_regno + j)); | |
f3bb6135 RE |
4278 | } |
4279 | ||
ff9940b0 RE |
4280 | return result; |
4281 | } | |
4282 | ||
880e2516 RE |
4283 | int |
4284 | arm_gen_movstrqi (operands) | |
62b10bbc | 4285 | rtx * operands; |
880e2516 RE |
4286 | { |
4287 | HOST_WIDE_INT in_words_to_go, out_words_to_go, last_bytes; | |
ad076f4e | 4288 | int i; |
880e2516 | 4289 | rtx src, dst; |
ad076f4e | 4290 | rtx st_src, st_dst, fin_src, fin_dst; |
880e2516 | 4291 | rtx part_bytes_reg = NULL; |
56636818 JL |
4292 | rtx mem; |
4293 | int dst_unchanging_p, dst_in_struct_p, src_unchanging_p, src_in_struct_p; | |
c6df88cb | 4294 | int dst_scalar_p, src_scalar_p; |
880e2516 RE |
4295 | |
4296 | if (GET_CODE (operands[2]) != CONST_INT | |
4297 | || GET_CODE (operands[3]) != CONST_INT | |
4298 | || INTVAL (operands[2]) > 64 | |
4299 | || INTVAL (operands[3]) & 3) | |
4300 | return 0; | |
4301 | ||
4302 | st_dst = XEXP (operands[0], 0); | |
4303 | st_src = XEXP (operands[1], 0); | |
56636818 JL |
4304 | |
4305 | dst_unchanging_p = RTX_UNCHANGING_P (operands[0]); | |
4306 | dst_in_struct_p = MEM_IN_STRUCT_P (operands[0]); | |
c6df88cb | 4307 | dst_scalar_p = MEM_SCALAR_P (operands[0]); |
56636818 JL |
4308 | src_unchanging_p = RTX_UNCHANGING_P (operands[1]); |
4309 | src_in_struct_p = MEM_IN_STRUCT_P (operands[1]); | |
c6df88cb | 4310 | src_scalar_p = MEM_SCALAR_P (operands[1]); |
56636818 | 4311 | |
880e2516 RE |
4312 | fin_dst = dst = copy_to_mode_reg (SImode, st_dst); |
4313 | fin_src = src = copy_to_mode_reg (SImode, st_src); | |
4314 | ||
d5b7b3ae | 4315 | in_words_to_go = NUM_INTS (INTVAL (operands[2])); |
880e2516 RE |
4316 | out_words_to_go = INTVAL (operands[2]) / 4; |
4317 | last_bytes = INTVAL (operands[2]) & 3; | |
4318 | ||
4319 | if (out_words_to_go != in_words_to_go && ((in_words_to_go - 1) & 3) != 0) | |
43cffd11 | 4320 | part_bytes_reg = gen_rtx_REG (SImode, (in_words_to_go - 1) & 3); |
880e2516 RE |
4321 | |
4322 | for (i = 0; in_words_to_go >= 2; i+=4) | |
4323 | { | |
bd9c7e23 | 4324 | if (in_words_to_go > 4) |
56636818 | 4325 | emit_insn (arm_gen_load_multiple (0, 4, src, TRUE, TRUE, |
c6df88cb MM |
4326 | src_unchanging_p, |
4327 | src_in_struct_p, | |
4328 | src_scalar_p)); | |
bd9c7e23 RE |
4329 | else |
4330 | emit_insn (arm_gen_load_multiple (0, in_words_to_go, src, TRUE, | |
56636818 | 4331 | FALSE, src_unchanging_p, |
c6df88cb | 4332 | src_in_struct_p, src_scalar_p)); |
bd9c7e23 | 4333 | |
880e2516 RE |
4334 | if (out_words_to_go) |
4335 | { | |
bd9c7e23 | 4336 | if (out_words_to_go > 4) |
56636818 JL |
4337 | emit_insn (arm_gen_store_multiple (0, 4, dst, TRUE, TRUE, |
4338 | dst_unchanging_p, | |
c6df88cb MM |
4339 | dst_in_struct_p, |
4340 | dst_scalar_p)); | |
bd9c7e23 RE |
4341 | else if (out_words_to_go != 1) |
4342 | emit_insn (arm_gen_store_multiple (0, out_words_to_go, | |
4343 | dst, TRUE, | |
4344 | (last_bytes == 0 | |
56636818 JL |
4345 | ? FALSE : TRUE), |
4346 | dst_unchanging_p, | |
c6df88cb MM |
4347 | dst_in_struct_p, |
4348 | dst_scalar_p)); | |
880e2516 RE |
4349 | else |
4350 | { | |
43cffd11 | 4351 | mem = gen_rtx_MEM (SImode, dst); |
56636818 JL |
4352 | RTX_UNCHANGING_P (mem) = dst_unchanging_p; |
4353 | MEM_IN_STRUCT_P (mem) = dst_in_struct_p; | |
c6df88cb | 4354 | MEM_SCALAR_P (mem) = dst_scalar_p; |
43cffd11 | 4355 | emit_move_insn (mem, gen_rtx_REG (SImode, 0)); |
bd9c7e23 RE |
4356 | if (last_bytes != 0) |
4357 | emit_insn (gen_addsi3 (dst, dst, GEN_INT (4))); | |
880e2516 RE |
4358 | } |
4359 | } | |
4360 | ||
4361 | in_words_to_go -= in_words_to_go < 4 ? in_words_to_go : 4; | |
4362 | out_words_to_go -= out_words_to_go < 4 ? out_words_to_go : 4; | |
4363 | } | |
4364 | ||
4365 | /* OUT_WORDS_TO_GO will be zero here if there are byte stores to do. */ | |
4366 | if (out_words_to_go) | |
62b10bbc NC |
4367 | { |
4368 | rtx sreg; | |
4369 | ||
4370 | mem = gen_rtx_MEM (SImode, src); | |
4371 | RTX_UNCHANGING_P (mem) = src_unchanging_p; | |
4372 | MEM_IN_STRUCT_P (mem) = src_in_struct_p; | |
4373 | MEM_SCALAR_P (mem) = src_scalar_p; | |
4374 | emit_move_insn (sreg = gen_reg_rtx (SImode), mem); | |
4375 | emit_move_insn (fin_src = gen_reg_rtx (SImode), plus_constant (src, 4)); | |
4376 | ||
4377 | mem = gen_rtx_MEM (SImode, dst); | |
4378 | RTX_UNCHANGING_P (mem) = dst_unchanging_p; | |
4379 | MEM_IN_STRUCT_P (mem) = dst_in_struct_p; | |
4380 | MEM_SCALAR_P (mem) = dst_scalar_p; | |
4381 | emit_move_insn (mem, sreg); | |
4382 | emit_move_insn (fin_dst = gen_reg_rtx (SImode), plus_constant (dst, 4)); | |
4383 | in_words_to_go--; | |
4384 | ||
4385 | if (in_words_to_go) /* Sanity check */ | |
4386 | abort (); | |
4387 | } | |
880e2516 RE |
4388 | |
4389 | if (in_words_to_go) | |
4390 | { | |
4391 | if (in_words_to_go < 0) | |
4392 | abort (); | |
4393 | ||
43cffd11 | 4394 | mem = gen_rtx_MEM (SImode, src); |
56636818 JL |
4395 | RTX_UNCHANGING_P (mem) = src_unchanging_p; |
4396 | MEM_IN_STRUCT_P (mem) = src_in_struct_p; | |
c6df88cb | 4397 | MEM_SCALAR_P (mem) = src_scalar_p; |
56636818 | 4398 | part_bytes_reg = copy_to_mode_reg (SImode, mem); |
880e2516 RE |
4399 | } |
4400 | ||
d5b7b3ae RE |
4401 | if (last_bytes && part_bytes_reg == NULL) |
4402 | abort (); | |
4403 | ||
880e2516 RE |
4404 | if (BYTES_BIG_ENDIAN && last_bytes) |
4405 | { | |
4406 | rtx tmp = gen_reg_rtx (SImode); | |
4407 | ||
6354dc9b | 4408 | /* The bytes we want are in the top end of the word. */ |
bee06f3d RE |
4409 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, |
4410 | GEN_INT (8 * (4 - last_bytes)))); | |
880e2516 RE |
4411 | part_bytes_reg = tmp; |
4412 | ||
4413 | while (last_bytes) | |
4414 | { | |
43cffd11 | 4415 | mem = gen_rtx_MEM (QImode, plus_constant (dst, last_bytes - 1)); |
56636818 JL |
4416 | RTX_UNCHANGING_P (mem) = dst_unchanging_p; |
4417 | MEM_IN_STRUCT_P (mem) = dst_in_struct_p; | |
c6df88cb | 4418 | MEM_SCALAR_P (mem) = dst_scalar_p; |
43cffd11 | 4419 | emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0)); |
62b10bbc | 4420 | |
880e2516 RE |
4421 | if (--last_bytes) |
4422 | { | |
4423 | tmp = gen_reg_rtx (SImode); | |
4424 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (8))); | |
4425 | part_bytes_reg = tmp; | |
4426 | } | |
4427 | } | |
4428 | ||
4429 | } | |
4430 | else | |
4431 | { | |
d5b7b3ae | 4432 | if (last_bytes > 1) |
880e2516 | 4433 | { |
d5b7b3ae | 4434 | mem = gen_rtx_MEM (HImode, dst); |
56636818 JL |
4435 | RTX_UNCHANGING_P (mem) = dst_unchanging_p; |
4436 | MEM_IN_STRUCT_P (mem) = dst_in_struct_p; | |
c6df88cb | 4437 | MEM_SCALAR_P (mem) = dst_scalar_p; |
d5b7b3ae RE |
4438 | emit_move_insn (mem, gen_rtx_SUBREG (HImode, part_bytes_reg, 0)); |
4439 | last_bytes -= 2; | |
4440 | if (last_bytes) | |
880e2516 RE |
4441 | { |
4442 | rtx tmp = gen_reg_rtx (SImode); | |
bd9c7e23 | 4443 | |
d5b7b3ae RE |
4444 | emit_insn (gen_addsi3 (dst, dst, GEN_INT (2))); |
4445 | emit_insn (gen_lshrsi3 (tmp, part_bytes_reg, GEN_INT (16))); | |
880e2516 RE |
4446 | part_bytes_reg = tmp; |
4447 | } | |
4448 | } | |
d5b7b3ae RE |
4449 | |
4450 | if (last_bytes) | |
4451 | { | |
4452 | mem = gen_rtx_MEM (QImode, dst); | |
4453 | RTX_UNCHANGING_P (mem) = dst_unchanging_p; | |
4454 | MEM_IN_STRUCT_P (mem) = dst_in_struct_p; | |
4455 | MEM_SCALAR_P (mem) = dst_scalar_p; | |
4456 | emit_move_insn (mem, gen_rtx_SUBREG (QImode, part_bytes_reg, 0)); | |
4457 | } | |
880e2516 RE |
4458 | } |
4459 | ||
4460 | return 1; | |
4461 | } | |
4462 | ||
5165176d RE |
4463 | /* Generate a memory reference for a half word, such that it will be loaded |
4464 | into the top 16 bits of the word. We can assume that the address is | |
4465 | known to be alignable and of the form reg, or plus (reg, const). */ | |
4466 | rtx | |
d5b7b3ae | 4467 | arm_gen_rotated_half_load (memref) |
5165176d RE |
4468 | rtx memref; |
4469 | { | |
4470 | HOST_WIDE_INT offset = 0; | |
4471 | rtx base = XEXP (memref, 0); | |
4472 | ||
4473 | if (GET_CODE (base) == PLUS) | |
4474 | { | |
4475 | offset = INTVAL (XEXP (base, 1)); | |
4476 | base = XEXP (base, 0); | |
4477 | } | |
4478 | ||
956d6950 | 4479 | /* If we aren't allowed to generate unaligned addresses, then fail. */ |
5f1e6755 | 4480 | if (TARGET_MMU_TRAPS |
5165176d RE |
4481 | && ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 0))) |
4482 | return NULL; | |
4483 | ||
43cffd11 | 4484 | base = gen_rtx_MEM (SImode, plus_constant (base, offset & ~2)); |
5165176d RE |
4485 | |
4486 | if ((BYTES_BIG_ENDIAN ? 1 : 0) ^ ((offset & 2) == 2)) | |
4487 | return base; | |
4488 | ||
43cffd11 | 4489 | return gen_rtx_ROTATE (SImode, base, GEN_INT (16)); |
5165176d RE |
4490 | } |
4491 | ||
1646cf41 RE |
4492 | /* Select a dominance comparison mode if possible. We support three forms. |
4493 | COND_OR == 0 => (X && Y) | |
4494 | COND_OR == 1 => ((! X( || Y) | |
4495 | COND_OR == 2 => (X || Y) | |
4496 | If we are unable to support a dominance comparsison we return CC mode. | |
4497 | This will then fail to match for the RTL expressions that generate this | |
4498 | call. */ | |
d19fb8e3 | 4499 | |
84ed5e79 | 4500 | static enum machine_mode |
74bbc178 | 4501 | select_dominance_cc_mode (x, y, cond_or) |
84ed5e79 RE |
4502 | rtx x; |
4503 | rtx y; | |
4504 | HOST_WIDE_INT cond_or; | |
4505 | { | |
4506 | enum rtx_code cond1, cond2; | |
4507 | int swapped = 0; | |
4508 | ||
4509 | /* Currently we will probably get the wrong result if the individual | |
4510 | comparisons are not simple. This also ensures that it is safe to | |
956d6950 | 4511 | reverse a comparison if necessary. */ |
84ed5e79 RE |
4512 | if ((arm_select_cc_mode (cond1 = GET_CODE (x), XEXP (x, 0), XEXP (x, 1)) |
4513 | != CCmode) | |
4514 | || (arm_select_cc_mode (cond2 = GET_CODE (y), XEXP (y, 0), XEXP (y, 1)) | |
4515 | != CCmode)) | |
4516 | return CCmode; | |
4517 | ||
1646cf41 RE |
4518 | /* The if_then_else variant of this tests the second condition if the |
4519 | first passes, but is true if the first fails. Reverse the first | |
4520 | condition to get a true "inclusive-or" expression. */ | |
4521 | if (cond_or == 1) | |
84ed5e79 RE |
4522 | cond1 = reverse_condition (cond1); |
4523 | ||
4524 | /* If the comparisons are not equal, and one doesn't dominate the other, | |
4525 | then we can't do this. */ | |
4526 | if (cond1 != cond2 | |
5895f793 RE |
4527 | && !comparison_dominates_p (cond1, cond2) |
4528 | && (swapped = 1, !comparison_dominates_p (cond2, cond1))) | |
84ed5e79 RE |
4529 | return CCmode; |
4530 | ||
4531 | if (swapped) | |
4532 | { | |
4533 | enum rtx_code temp = cond1; | |
4534 | cond1 = cond2; | |
4535 | cond2 = temp; | |
4536 | } | |
4537 | ||
4538 | switch (cond1) | |
4539 | { | |
4540 | case EQ: | |
5895f793 | 4541 | if (cond2 == EQ || !cond_or) |
84ed5e79 RE |
4542 | return CC_DEQmode; |
4543 | ||
4544 | switch (cond2) | |
4545 | { | |
4546 | case LE: return CC_DLEmode; | |
4547 | case LEU: return CC_DLEUmode; | |
4548 | case GE: return CC_DGEmode; | |
4549 | case GEU: return CC_DGEUmode; | |
ad076f4e | 4550 | default: break; |
84ed5e79 RE |
4551 | } |
4552 | ||
4553 | break; | |
4554 | ||
4555 | case LT: | |
5895f793 | 4556 | if (cond2 == LT || !cond_or) |
84ed5e79 RE |
4557 | return CC_DLTmode; |
4558 | if (cond2 == LE) | |
4559 | return CC_DLEmode; | |
4560 | if (cond2 == NE) | |
4561 | return CC_DNEmode; | |
4562 | break; | |
4563 | ||
4564 | case GT: | |
5895f793 | 4565 | if (cond2 == GT || !cond_or) |
84ed5e79 RE |
4566 | return CC_DGTmode; |
4567 | if (cond2 == GE) | |
4568 | return CC_DGEmode; | |
4569 | if (cond2 == NE) | |
4570 | return CC_DNEmode; | |
4571 | break; | |
4572 | ||
4573 | case LTU: | |
5895f793 | 4574 | if (cond2 == LTU || !cond_or) |
84ed5e79 RE |
4575 | return CC_DLTUmode; |
4576 | if (cond2 == LEU) | |
4577 | return CC_DLEUmode; | |
4578 | if (cond2 == NE) | |
4579 | return CC_DNEmode; | |
4580 | break; | |
4581 | ||
4582 | case GTU: | |
5895f793 | 4583 | if (cond2 == GTU || !cond_or) |
84ed5e79 RE |
4584 | return CC_DGTUmode; |
4585 | if (cond2 == GEU) | |
4586 | return CC_DGEUmode; | |
4587 | if (cond2 == NE) | |
4588 | return CC_DNEmode; | |
4589 | break; | |
4590 | ||
4591 | /* The remaining cases only occur when both comparisons are the | |
4592 | same. */ | |
4593 | case NE: | |
4594 | return CC_DNEmode; | |
4595 | ||
4596 | case LE: | |
4597 | return CC_DLEmode; | |
4598 | ||
4599 | case GE: | |
4600 | return CC_DGEmode; | |
4601 | ||
4602 | case LEU: | |
4603 | return CC_DLEUmode; | |
4604 | ||
4605 | case GEU: | |
4606 | return CC_DGEUmode; | |
ad076f4e RE |
4607 | |
4608 | default: | |
4609 | break; | |
84ed5e79 RE |
4610 | } |
4611 | ||
4612 | abort (); | |
4613 | } | |
4614 | ||
4615 | enum machine_mode | |
4616 | arm_select_cc_mode (op, x, y) | |
4617 | enum rtx_code op; | |
4618 | rtx x; | |
4619 | rtx y; | |
4620 | { | |
4621 | /* All floating point compares return CCFP if it is an equality | |
4622 | comparison, and CCFPE otherwise. */ | |
4623 | if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT) | |
e45b72c4 RE |
4624 | { |
4625 | switch (op) | |
4626 | { | |
4627 | case EQ: | |
4628 | case NE: | |
4629 | case UNORDERED: | |
4630 | case ORDERED: | |
4631 | case UNLT: | |
4632 | case UNLE: | |
4633 | case UNGT: | |
4634 | case UNGE: | |
4635 | case UNEQ: | |
4636 | case LTGT: | |
4637 | return CCFPmode; | |
4638 | ||
4639 | case LT: | |
4640 | case LE: | |
4641 | case GT: | |
4642 | case GE: | |
4643 | return CCFPEmode; | |
4644 | ||
4645 | default: | |
4646 | abort (); | |
4647 | } | |
4648 | } | |
84ed5e79 RE |
4649 | |
4650 | /* A compare with a shifted operand. Because of canonicalization, the | |
4651 | comparison will have to be swapped when we emit the assembler. */ | |
4652 | if (GET_MODE (y) == SImode && GET_CODE (y) == REG | |
4653 | && (GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT | |
4654 | || GET_CODE (x) == LSHIFTRT || GET_CODE (x) == ROTATE | |
4655 | || GET_CODE (x) == ROTATERT)) | |
4656 | return CC_SWPmode; | |
4657 | ||
956d6950 JL |
4658 | /* This is a special case that is used by combine to allow a |
4659 | comparison of a shifted byte load to be split into a zero-extend | |
84ed5e79 | 4660 | followed by a comparison of the shifted integer (only valid for |
956d6950 | 4661 | equalities and unsigned inequalities). */ |
84ed5e79 RE |
4662 | if (GET_MODE (x) == SImode |
4663 | && GET_CODE (x) == ASHIFT | |
4664 | && GET_CODE (XEXP (x, 1)) == CONST_INT && INTVAL (XEXP (x, 1)) == 24 | |
4665 | && GET_CODE (XEXP (x, 0)) == SUBREG | |
4666 | && GET_CODE (SUBREG_REG (XEXP (x, 0))) == MEM | |
4667 | && GET_MODE (SUBREG_REG (XEXP (x, 0))) == QImode | |
4668 | && (op == EQ || op == NE | |
4669 | || op == GEU || op == GTU || op == LTU || op == LEU) | |
4670 | && GET_CODE (y) == CONST_INT) | |
4671 | return CC_Zmode; | |
4672 | ||
1646cf41 RE |
4673 | /* A construct for a conditional compare, if the false arm contains |
4674 | 0, then both conditions must be true, otherwise either condition | |
4675 | must be true. Not all conditions are possible, so CCmode is | |
4676 | returned if it can't be done. */ | |
4677 | if (GET_CODE (x) == IF_THEN_ELSE | |
4678 | && (XEXP (x, 2) == const0_rtx | |
4679 | || XEXP (x, 2) == const1_rtx) | |
4680 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<' | |
4681 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<') | |
4682 | return select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), | |
4683 | INTVAL (XEXP (x, 2))); | |
4684 | ||
4685 | /* Alternate canonicalizations of the above. These are somewhat cleaner. */ | |
4686 | if (GET_CODE (x) == AND | |
4687 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<' | |
4688 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<') | |
4689 | return select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), 0); | |
4690 | ||
4691 | if (GET_CODE (x) == IOR | |
4692 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 0))) == '<' | |
4693 | && GET_RTX_CLASS (GET_CODE (XEXP (x, 1))) == '<') | |
4694 | return select_dominance_cc_mode (XEXP (x, 0), XEXP (x, 1), 2); | |
4695 | ||
84ed5e79 RE |
4696 | /* An operation that sets the condition codes as a side-effect, the |
4697 | V flag is not set correctly, so we can only use comparisons where | |
4698 | this doesn't matter. (For LT and GE we can use "mi" and "pl" | |
4699 | instead. */ | |
4700 | if (GET_MODE (x) == SImode | |
4701 | && y == const0_rtx | |
4702 | && (op == EQ || op == NE || op == LT || op == GE) | |
4703 | && (GET_CODE (x) == PLUS || GET_CODE (x) == MINUS | |
4704 | || GET_CODE (x) == AND || GET_CODE (x) == IOR | |
4705 | || GET_CODE (x) == XOR || GET_CODE (x) == MULT | |
4706 | || GET_CODE (x) == NOT || GET_CODE (x) == NEG | |
4707 | || GET_CODE (x) == LSHIFTRT | |
4708 | || GET_CODE (x) == ASHIFT || GET_CODE (x) == ASHIFTRT | |
4709 | || GET_CODE (x) == ROTATERT || GET_CODE (x) == ZERO_EXTRACT)) | |
4710 | return CC_NOOVmode; | |
4711 | ||
84ed5e79 RE |
4712 | if (GET_MODE (x) == QImode && (op == EQ || op == NE)) |
4713 | return CC_Zmode; | |
4714 | ||
bd9c7e23 RE |
4715 | if (GET_MODE (x) == SImode && (op == LTU || op == GEU) |
4716 | && GET_CODE (x) == PLUS | |
4717 | && (rtx_equal_p (XEXP (x, 0), y) || rtx_equal_p (XEXP (x, 1), y))) | |
4718 | return CC_Cmode; | |
4719 | ||
84ed5e79 RE |
4720 | return CCmode; |
4721 | } | |
4722 | ||
ff9940b0 RE |
4723 | /* X and Y are two things to compare using CODE. Emit the compare insn and |
4724 | return the rtx for register 0 in the proper mode. FP means this is a | |
4725 | floating point compare: I don't think that it is needed on the arm. */ | |
4726 | ||
4727 | rtx | |
d5b7b3ae | 4728 | arm_gen_compare_reg (code, x, y) |
ff9940b0 RE |
4729 | enum rtx_code code; |
4730 | rtx x, y; | |
4731 | { | |
4732 | enum machine_mode mode = SELECT_CC_MODE (code, x, y); | |
d5b7b3ae | 4733 | rtx cc_reg = gen_rtx_REG (mode, CC_REGNUM); |
ff9940b0 | 4734 | |
43cffd11 RE |
4735 | emit_insn (gen_rtx_SET (VOIDmode, cc_reg, |
4736 | gen_rtx_COMPARE (mode, x, y))); | |
ff9940b0 RE |
4737 | |
4738 | return cc_reg; | |
4739 | } | |
4740 | ||
0a81f500 RE |
4741 | void |
4742 | arm_reload_in_hi (operands) | |
62b10bbc | 4743 | rtx * operands; |
0a81f500 | 4744 | { |
f9cc092a RE |
4745 | rtx ref = operands[1]; |
4746 | rtx base, scratch; | |
4747 | HOST_WIDE_INT offset = 0; | |
4748 | ||
4749 | if (GET_CODE (ref) == SUBREG) | |
4750 | { | |
4751 | offset = SUBREG_WORD (ref) * UNITS_PER_WORD; | |
4752 | if (BYTES_BIG_ENDIAN) | |
4753 | offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref))) | |
4754 | - MIN (UNITS_PER_WORD, | |
4755 | GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref))))); | |
4756 | ref = SUBREG_REG (ref); | |
4757 | } | |
4758 | ||
4759 | if (GET_CODE (ref) == REG) | |
4760 | { | |
4761 | /* We have a pseudo which has been spilt onto the stack; there | |
4762 | are two cases here: the first where there is a simple | |
4763 | stack-slot replacement and a second where the stack-slot is | |
4764 | out of range, or is used as a subreg. */ | |
4765 | if (reg_equiv_mem[REGNO (ref)]) | |
4766 | { | |
4767 | ref = reg_equiv_mem[REGNO (ref)]; | |
4768 | base = find_replacement (&XEXP (ref, 0)); | |
4769 | } | |
4770 | else | |
6354dc9b | 4771 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f9cc092a RE |
4772 | base = reg_equiv_address[REGNO (ref)]; |
4773 | } | |
4774 | else | |
4775 | base = find_replacement (&XEXP (ref, 0)); | |
0a81f500 | 4776 | |
e5e809f4 JL |
4777 | /* Handle the case where the address is too complex to be offset by 1. */ |
4778 | if (GET_CODE (base) == MINUS | |
4779 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
4780 | { | |
f9cc092a | 4781 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); |
e5e809f4 | 4782 | |
43cffd11 | 4783 | emit_insn (gen_rtx_SET (VOIDmode, base_plus, base)); |
e5e809f4 JL |
4784 | base = base_plus; |
4785 | } | |
f9cc092a RE |
4786 | else if (GET_CODE (base) == PLUS) |
4787 | { | |
6354dc9b | 4788 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
4789 | HOST_WIDE_INT hi, lo; |
4790 | ||
4791 | offset += INTVAL (XEXP (base, 1)); | |
4792 | base = XEXP (base, 0); | |
4793 | ||
6354dc9b | 4794 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
4795 | /* Valid range for lo is -4095 -> 4095 */ |
4796 | lo = (offset >= 0 | |
4797 | ? (offset & 0xfff) | |
4798 | : -((-offset) & 0xfff)); | |
4799 | ||
4800 | /* Corner case, if lo is the max offset then we would be out of range | |
4801 | once we have added the additional 1 below, so bump the msb into the | |
4802 | pre-loading insn(s). */ | |
4803 | if (lo == 4095) | |
4804 | lo &= 0x7ff; | |
4805 | ||
e5951263 NC |
4806 | hi = ((((offset - lo) & HOST_INT (0xffffffff)) |
4807 | ^ HOST_INT (0x80000000)) | |
4808 | - HOST_INT (0x80000000)); | |
f9cc092a RE |
4809 | |
4810 | if (hi + lo != offset) | |
4811 | abort (); | |
4812 | ||
4813 | if (hi != 0) | |
4814 | { | |
4815 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
4816 | ||
4817 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 4818 | that require more than one insn. */ |
f9cc092a RE |
4819 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
4820 | base = base_plus; | |
4821 | offset = lo; | |
4822 | } | |
4823 | } | |
e5e809f4 | 4824 | |
f9cc092a RE |
4825 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); |
4826 | emit_insn (gen_zero_extendqisi2 (scratch, | |
4827 | gen_rtx_MEM (QImode, | |
4828 | plus_constant (base, | |
4829 | offset)))); | |
43cffd11 RE |
4830 | emit_insn (gen_zero_extendqisi2 (gen_rtx_SUBREG (SImode, operands[0], 0), |
4831 | gen_rtx_MEM (QImode, | |
f9cc092a RE |
4832 | plus_constant (base, |
4833 | offset + 1)))); | |
5895f793 | 4834 | if (!BYTES_BIG_ENDIAN) |
43cffd11 RE |
4835 | emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0), |
4836 | gen_rtx_IOR (SImode, | |
4837 | gen_rtx_ASHIFT | |
4838 | (SImode, | |
4839 | gen_rtx_SUBREG (SImode, operands[0], 0), | |
4840 | GEN_INT (8)), | |
f9cc092a | 4841 | scratch))); |
0a81f500 | 4842 | else |
43cffd11 RE |
4843 | emit_insn (gen_rtx_SET (VOIDmode, gen_rtx_SUBREG (SImode, operands[0], 0), |
4844 | gen_rtx_IOR (SImode, | |
f9cc092a | 4845 | gen_rtx_ASHIFT (SImode, scratch, |
43cffd11 RE |
4846 | GEN_INT (8)), |
4847 | gen_rtx_SUBREG (SImode, operands[0], | |
4848 | 0)))); | |
0a81f500 RE |
4849 | } |
4850 | ||
f9cc092a RE |
4851 | /* Handle storing a half-word to memory during reload by synthesising as two |
4852 | byte stores. Take care not to clobber the input values until after we | |
4853 | have moved them somewhere safe. This code assumes that if the DImode | |
4854 | scratch in operands[2] overlaps either the input value or output address | |
4855 | in some way, then that value must die in this insn (we absolutely need | |
4856 | two scratch registers for some corner cases). */ | |
f3bb6135 | 4857 | void |
af48348a | 4858 | arm_reload_out_hi (operands) |
62b10bbc | 4859 | rtx * operands; |
af48348a | 4860 | { |
f9cc092a RE |
4861 | rtx ref = operands[0]; |
4862 | rtx outval = operands[1]; | |
4863 | rtx base, scratch; | |
4864 | HOST_WIDE_INT offset = 0; | |
4865 | ||
4866 | if (GET_CODE (ref) == SUBREG) | |
4867 | { | |
4868 | offset = SUBREG_WORD (ref) * UNITS_PER_WORD; | |
4869 | if (BYTES_BIG_ENDIAN) | |
4870 | offset -= (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (ref))) | |
4871 | - MIN (UNITS_PER_WORD, | |
4872 | GET_MODE_SIZE (GET_MODE (SUBREG_REG (ref))))); | |
4873 | ref = SUBREG_REG (ref); | |
4874 | } | |
4875 | ||
4876 | ||
4877 | if (GET_CODE (ref) == REG) | |
4878 | { | |
4879 | /* We have a pseudo which has been spilt onto the stack; there | |
4880 | are two cases here: the first where there is a simple | |
4881 | stack-slot replacement and a second where the stack-slot is | |
4882 | out of range, or is used as a subreg. */ | |
4883 | if (reg_equiv_mem[REGNO (ref)]) | |
4884 | { | |
4885 | ref = reg_equiv_mem[REGNO (ref)]; | |
4886 | base = find_replacement (&XEXP (ref, 0)); | |
4887 | } | |
4888 | else | |
6354dc9b | 4889 | /* The slot is out of range, or was dressed up in a SUBREG. */ |
f9cc092a RE |
4890 | base = reg_equiv_address[REGNO (ref)]; |
4891 | } | |
4892 | else | |
4893 | base = find_replacement (&XEXP (ref, 0)); | |
4894 | ||
4895 | scratch = gen_rtx_REG (SImode, REGNO (operands[2])); | |
4896 | ||
4897 | /* Handle the case where the address is too complex to be offset by 1. */ | |
4898 | if (GET_CODE (base) == MINUS | |
4899 | || (GET_CODE (base) == PLUS && GET_CODE (XEXP (base, 1)) != CONST_INT)) | |
4900 | { | |
4901 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
4902 | ||
4903 | /* Be careful not to destroy OUTVAL. */ | |
4904 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
4905 | { | |
4906 | /* Updating base_plus might destroy outval, see if we can | |
4907 | swap the scratch and base_plus. */ | |
5895f793 | 4908 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
4909 | { |
4910 | rtx tmp = scratch; | |
4911 | scratch = base_plus; | |
4912 | base_plus = tmp; | |
4913 | } | |
4914 | else | |
4915 | { | |
4916 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
4917 | ||
4918 | /* Be conservative and copy OUTVAL into the scratch now, | |
4919 | this should only be necessary if outval is a subreg | |
4920 | of something larger than a word. */ | |
4921 | /* XXX Might this clobber base? I can't see how it can, | |
4922 | since scratch is known to overlap with OUTVAL, and | |
4923 | must be wider than a word. */ | |
4924 | emit_insn (gen_movhi (scratch_hi, outval)); | |
4925 | outval = scratch_hi; | |
4926 | } | |
4927 | } | |
4928 | ||
4929 | emit_insn (gen_rtx_SET (VOIDmode, base_plus, base)); | |
4930 | base = base_plus; | |
4931 | } | |
4932 | else if (GET_CODE (base) == PLUS) | |
4933 | { | |
6354dc9b | 4934 | /* The addend must be CONST_INT, or we would have dealt with it above. */ |
f9cc092a RE |
4935 | HOST_WIDE_INT hi, lo; |
4936 | ||
4937 | offset += INTVAL (XEXP (base, 1)); | |
4938 | base = XEXP (base, 0); | |
4939 | ||
6354dc9b | 4940 | /* Rework the address into a legal sequence of insns. */ |
f9cc092a RE |
4941 | /* Valid range for lo is -4095 -> 4095 */ |
4942 | lo = (offset >= 0 | |
4943 | ? (offset & 0xfff) | |
4944 | : -((-offset) & 0xfff)); | |
4945 | ||
4946 | /* Corner case, if lo is the max offset then we would be out of range | |
4947 | once we have added the additional 1 below, so bump the msb into the | |
4948 | pre-loading insn(s). */ | |
4949 | if (lo == 4095) | |
4950 | lo &= 0x7ff; | |
4951 | ||
e5951263 NC |
4952 | hi = ((((offset - lo) & HOST_INT (0xffffffff)) |
4953 | ^ HOST_INT (0x80000000)) | |
5895f793 | 4954 | - HOST_INT (0x80000000)); |
f9cc092a RE |
4955 | |
4956 | if (hi + lo != offset) | |
4957 | abort (); | |
4958 | ||
4959 | if (hi != 0) | |
4960 | { | |
4961 | rtx base_plus = gen_rtx_REG (SImode, REGNO (operands[2]) + 1); | |
4962 | ||
4963 | /* Be careful not to destroy OUTVAL. */ | |
4964 | if (reg_overlap_mentioned_p (base_plus, outval)) | |
4965 | { | |
4966 | /* Updating base_plus might destroy outval, see if we | |
4967 | can swap the scratch and base_plus. */ | |
5895f793 | 4968 | if (!reg_overlap_mentioned_p (scratch, outval)) |
f9cc092a RE |
4969 | { |
4970 | rtx tmp = scratch; | |
4971 | scratch = base_plus; | |
4972 | base_plus = tmp; | |
4973 | } | |
4974 | else | |
4975 | { | |
4976 | rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2])); | |
4977 | ||
4978 | /* Be conservative and copy outval into scratch now, | |
4979 | this should only be necessary if outval is a | |
4980 | subreg of something larger than a word. */ | |
4981 | /* XXX Might this clobber base? I can't see how it | |
4982 | can, since scratch is known to overlap with | |
4983 | outval. */ | |
4984 | emit_insn (gen_movhi (scratch_hi, outval)); | |
4985 | outval = scratch_hi; | |
4986 | } | |
4987 | } | |
4988 | ||
4989 | /* Get the base address; addsi3 knows how to handle constants | |
6354dc9b | 4990 | that require more than one insn. */ |
f9cc092a RE |
4991 | emit_insn (gen_addsi3 (base_plus, base, GEN_INT (hi))); |
4992 | base = base_plus; | |
4993 | offset = lo; | |
4994 | } | |
4995 | } | |
af48348a | 4996 | |
b5cc037f RE |
4997 | if (BYTES_BIG_ENDIAN) |
4998 | { | |
f9cc092a RE |
4999 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
5000 | plus_constant (base, offset + 1)), | |
5001 | gen_rtx_SUBREG (QImode, outval, 0))); | |
5002 | emit_insn (gen_lshrsi3 (scratch, | |
5003 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 5004 | GEN_INT (8))); |
f9cc092a RE |
5005 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5006 | gen_rtx_SUBREG (QImode, scratch, 0))); | |
b5cc037f RE |
5007 | } |
5008 | else | |
5009 | { | |
f9cc092a RE |
5010 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, plus_constant (base, offset)), |
5011 | gen_rtx_SUBREG (QImode, outval, 0))); | |
5012 | emit_insn (gen_lshrsi3 (scratch, | |
5013 | gen_rtx_SUBREG (SImode, outval, 0), | |
b5cc037f | 5014 | GEN_INT (8))); |
f9cc092a RE |
5015 | emit_insn (gen_movqi (gen_rtx_MEM (QImode, |
5016 | plus_constant (base, offset + 1)), | |
5017 | gen_rtx_SUBREG (QImode, scratch, 0))); | |
b5cc037f | 5018 | } |
af48348a | 5019 | } |
2b835d68 | 5020 | \f |
d5b7b3ae RE |
5021 | /* Print a symbolic form of X to the debug file, F. */ |
5022 | static void | |
5023 | arm_print_value (f, x) | |
5024 | FILE * f; | |
5025 | rtx x; | |
5026 | { | |
5027 | switch (GET_CODE (x)) | |
5028 | { | |
5029 | case CONST_INT: | |
5030 | fprintf (f, HOST_WIDE_INT_PRINT_HEX, INTVAL (x)); | |
5031 | return; | |
5032 | ||
5033 | case CONST_DOUBLE: | |
5034 | fprintf (f, "<0x%lx,0x%lx>", (long)XWINT (x, 2), (long)XWINT (x, 3)); | |
5035 | return; | |
5036 | ||
5037 | case CONST_STRING: | |
5038 | fprintf (f, "\"%s\"", XSTR (x, 0)); | |
5039 | return; | |
5040 | ||
5041 | case SYMBOL_REF: | |
5042 | fprintf (f, "`%s'", XSTR (x, 0)); | |
5043 | return; | |
5044 | ||
5045 | case LABEL_REF: | |
5046 | fprintf (f, "L%d", INSN_UID (XEXP (x, 0))); | |
5047 | return; | |
5048 | ||
5049 | case CONST: | |
5050 | arm_print_value (f, XEXP (x, 0)); | |
5051 | return; | |
5052 | ||
5053 | case PLUS: | |
5054 | arm_print_value (f, XEXP (x, 0)); | |
5055 | fprintf (f, "+"); | |
5056 | arm_print_value (f, XEXP (x, 1)); | |
5057 | return; | |
5058 | ||
5059 | case PC: | |
5060 | fprintf (f, "pc"); | |
5061 | return; | |
5062 | ||
5063 | default: | |
5064 | fprintf (f, "????"); | |
5065 | return; | |
5066 | } | |
5067 | } | |
5068 | \f | |
2b835d68 | 5069 | /* Routines for manipulation of the constant pool. */ |
2b835d68 | 5070 | |
949d79eb RE |
5071 | /* Arm instructions cannot load a large constant directly into a |
5072 | register; they have to come from a pc relative load. The constant | |
5073 | must therefore be placed in the addressable range of the pc | |
5074 | relative load. Depending on the precise pc relative load | |
5075 | instruction the range is somewhere between 256 bytes and 4k. This | |
5076 | means that we often have to dump a constant inside a function, and | |
2b835d68 RE |
5077 | generate code to branch around it. |
5078 | ||
949d79eb RE |
5079 | It is important to minimize this, since the branches will slow |
5080 | things down and make the code larger. | |
2b835d68 | 5081 | |
949d79eb RE |
5082 | Normally we can hide the table after an existing unconditional |
5083 | branch so that there is no interruption of the flow, but in the | |
5084 | worst case the code looks like this: | |
2b835d68 RE |
5085 | |
5086 | ldr rn, L1 | |
949d79eb | 5087 | ... |
2b835d68 RE |
5088 | b L2 |
5089 | align | |
5090 | L1: .long value | |
5091 | L2: | |
949d79eb | 5092 | ... |
2b835d68 | 5093 | |
2b835d68 | 5094 | ldr rn, L3 |
949d79eb | 5095 | ... |
2b835d68 RE |
5096 | b L4 |
5097 | align | |
2b835d68 RE |
5098 | L3: .long value |
5099 | L4: | |
949d79eb RE |
5100 | ... |
5101 | ||
5102 | We fix this by performing a scan after scheduling, which notices | |
5103 | which instructions need to have their operands fetched from the | |
5104 | constant table and builds the table. | |
5105 | ||
5106 | The algorithm starts by building a table of all the constants that | |
5107 | need fixing up and all the natural barriers in the function (places | |
5108 | where a constant table can be dropped without breaking the flow). | |
5109 | For each fixup we note how far the pc-relative replacement will be | |
5110 | able to reach and the offset of the instruction into the function. | |
5111 | ||
5112 | Having built the table we then group the fixes together to form | |
5113 | tables that are as large as possible (subject to addressing | |
5114 | constraints) and emit each table of constants after the last | |
5115 | barrier that is within range of all the instructions in the group. | |
5116 | If a group does not contain a barrier, then we forcibly create one | |
5117 | by inserting a jump instruction into the flow. Once the table has | |
5118 | been inserted, the insns are then modified to reference the | |
5119 | relevant entry in the pool. | |
5120 | ||
6354dc9b | 5121 | Possible enhancements to the algorithm (not implemented) are: |
949d79eb | 5122 | |
d5b7b3ae | 5123 | 1) For some processors and object formats, there may be benefit in |
949d79eb RE |
5124 | aligning the pools to the start of cache lines; this alignment |
5125 | would need to be taken into account when calculating addressability | |
6354dc9b | 5126 | of a pool. */ |
2b835d68 | 5127 | |
d5b7b3ae RE |
5128 | /* These typedefs are located at the start of this file, so that |
5129 | they can be used in the prototypes there. This comment is to | |
5130 | remind readers of that fact so that the following structures | |
5131 | can be understood more easily. | |
5132 | ||
5133 | typedef struct minipool_node Mnode; | |
5134 | typedef struct minipool_fixup Mfix; */ | |
5135 | ||
5136 | struct minipool_node | |
5137 | { | |
5138 | /* Doubly linked chain of entries. */ | |
5139 | Mnode * next; | |
5140 | Mnode * prev; | |
5141 | /* The maximum offset into the code that this entry can be placed. While | |
5142 | pushing fixes for forward references, all entries are sorted in order | |
5143 | of increasing max_address. */ | |
5144 | HOST_WIDE_INT max_address; | |
5145 | /* Similarly for a entry inserted for a backwards ref. */ | |
5146 | HOST_WIDE_INT min_address; | |
5147 | /* The number of fixes referencing this entry. This can become zero | |
5148 | if we "unpush" an entry. In this case we ignore the entry when we | |
5149 | come to emit the code. */ | |
5150 | int refcount; | |
5151 | /* The offset from the start of the minipool. */ | |
5152 | HOST_WIDE_INT offset; | |
5153 | /* The value in table. */ | |
5154 | rtx value; | |
5155 | /* The mode of value. */ | |
5156 | enum machine_mode mode; | |
5157 | int fix_size; | |
5158 | }; | |
5159 | ||
5160 | struct minipool_fixup | |
2b835d68 | 5161 | { |
d5b7b3ae RE |
5162 | Mfix * next; |
5163 | rtx insn; | |
5164 | HOST_WIDE_INT address; | |
5165 | rtx * loc; | |
5166 | enum machine_mode mode; | |
5167 | int fix_size; | |
5168 | rtx value; | |
5169 | Mnode * minipool; | |
5170 | HOST_WIDE_INT forwards; | |
5171 | HOST_WIDE_INT backwards; | |
5172 | }; | |
2b835d68 | 5173 | |
d5b7b3ae RE |
5174 | /* Fixes less than a word need padding out to a word boundary. */ |
5175 | #define MINIPOOL_FIX_SIZE(mode) \ | |
5176 | (GET_MODE_SIZE ((mode)) >= 4 ? GET_MODE_SIZE ((mode)) : 4) | |
2b835d68 | 5177 | |
d5b7b3ae RE |
5178 | static Mnode * minipool_vector_head; |
5179 | static Mnode * minipool_vector_tail; | |
5180 | static rtx minipool_vector_label; | |
332072db | 5181 | |
d5b7b3ae RE |
5182 | /* The linked list of all minipool fixes required for this function. */ |
5183 | Mfix * minipool_fix_head; | |
5184 | Mfix * minipool_fix_tail; | |
5185 | /* The fix entry for the current minipool, once it has been placed. */ | |
5186 | Mfix * minipool_barrier; | |
5187 | ||
5188 | /* Determines if INSN is the start of a jump table. Returns the end | |
5189 | of the TABLE or NULL_RTX. */ | |
5190 | static rtx | |
5191 | is_jump_table (insn) | |
5192 | rtx insn; | |
2b835d68 | 5193 | { |
d5b7b3ae | 5194 | rtx table; |
da6558fd | 5195 | |
d5b7b3ae RE |
5196 | if (GET_CODE (insn) == JUMP_INSN |
5197 | && JUMP_LABEL (insn) != NULL | |
5198 | && ((table = next_real_insn (JUMP_LABEL (insn))) | |
5199 | == next_real_insn (insn)) | |
5200 | && table != NULL | |
5201 | && GET_CODE (table) == JUMP_INSN | |
5202 | && (GET_CODE (PATTERN (table)) == ADDR_VEC | |
5203 | || GET_CODE (PATTERN (table)) == ADDR_DIFF_VEC)) | |
5204 | return table; | |
5205 | ||
5206 | return NULL_RTX; | |
2b835d68 RE |
5207 | } |
5208 | ||
d5b7b3ae RE |
5209 | static HOST_WIDE_INT |
5210 | get_jump_table_size (insn) | |
5211 | rtx insn; | |
2b835d68 | 5212 | { |
d5b7b3ae RE |
5213 | rtx body = PATTERN (insn); |
5214 | int elt = GET_CODE (body) == ADDR_DIFF_VEC ? 1 : 0; | |
2b835d68 | 5215 | |
d5b7b3ae RE |
5216 | return GET_MODE_SIZE (GET_MODE (body)) * XVECLEN (body, elt); |
5217 | } | |
2b835d68 | 5218 | |
d5b7b3ae RE |
5219 | /* Move a minipool fix MP from its current location to before MAX_MP. |
5220 | If MAX_MP is NULL, then MP doesn't need moving, but the addressing | |
5221 | contrains may need updating. */ | |
5222 | static Mnode * | |
5223 | move_minipool_fix_forward_ref (mp, max_mp, max_address) | |
5224 | Mnode * mp; | |
5225 | Mnode * max_mp; | |
5226 | HOST_WIDE_INT max_address; | |
5227 | { | |
5228 | /* This should never be true and the code below assumes these are | |
5229 | different. */ | |
5230 | if (mp == max_mp) | |
5231 | abort (); | |
5232 | ||
5233 | if (max_mp == NULL) | |
5234 | { | |
5235 | if (max_address < mp->max_address) | |
5236 | mp->max_address = max_address; | |
5237 | } | |
5238 | else | |
2b835d68 | 5239 | { |
d5b7b3ae RE |
5240 | if (max_address > max_mp->max_address - mp->fix_size) |
5241 | mp->max_address = max_mp->max_address - mp->fix_size; | |
5242 | else | |
5243 | mp->max_address = max_address; | |
2b835d68 | 5244 | |
d5b7b3ae RE |
5245 | /* Unlink MP from its current position. Since max_mp is non-null, |
5246 | mp->prev must be non-null. */ | |
5247 | mp->prev->next = mp->next; | |
5248 | if (mp->next != NULL) | |
5249 | mp->next->prev = mp->prev; | |
5250 | else | |
5251 | minipool_vector_tail = mp->prev; | |
2b835d68 | 5252 | |
d5b7b3ae RE |
5253 | /* Re-insert it before MAX_MP. */ |
5254 | mp->next = max_mp; | |
5255 | mp->prev = max_mp->prev; | |
5256 | max_mp->prev = mp; | |
5257 | ||
5258 | if (mp->prev != NULL) | |
5259 | mp->prev->next = mp; | |
5260 | else | |
5261 | minipool_vector_head = mp; | |
5262 | } | |
2b835d68 | 5263 | |
d5b7b3ae RE |
5264 | /* Save the new entry. */ |
5265 | max_mp = mp; | |
5266 | ||
5267 | /* Scan over the preceeding entries and adjust their addresses as | |
5268 | required. */ | |
5269 | while (mp->prev != NULL | |
5270 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
5271 | { | |
5272 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
5273 | mp = mp->prev; | |
2b835d68 RE |
5274 | } |
5275 | ||
d5b7b3ae | 5276 | return max_mp; |
2b835d68 RE |
5277 | } |
5278 | ||
d5b7b3ae RE |
5279 | /* Add a constant to the minipool for a forward reference. Returns the |
5280 | node added or NULL if the constant will not fit in this pool. */ | |
5281 | static Mnode * | |
5282 | add_minipool_forward_ref (fix) | |
5283 | Mfix * fix; | |
5284 | { | |
5285 | /* If set, max_mp is the first pool_entry that has a lower | |
5286 | constraint than the one we are trying to add. */ | |
5287 | Mnode * max_mp = NULL; | |
5288 | HOST_WIDE_INT max_address = fix->address + fix->forwards; | |
5289 | Mnode * mp; | |
5290 | ||
5291 | /* If this fix's address is greater than the address of the first | |
5292 | entry, then we can't put the fix in this pool. We subtract the | |
5293 | size of the current fix to ensure that if the table is fully | |
5294 | packed we still have enough room to insert this value by suffling | |
5295 | the other fixes forwards. */ | |
5296 | if (minipool_vector_head && | |
5297 | fix->address >= minipool_vector_head->max_address - fix->fix_size) | |
5298 | return NULL; | |
2b835d68 | 5299 | |
d5b7b3ae RE |
5300 | /* Scan the pool to see if a constant with the same value has |
5301 | already been added. While we are doing this, also note the | |
5302 | location where we must insert the constant if it doesn't already | |
5303 | exist. */ | |
5304 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
5305 | { | |
5306 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
5307 | && fix->mode == mp->mode | |
5308 | && (GET_CODE (fix->value) != CODE_LABEL | |
5309 | || (CODE_LABEL_NUMBER (fix->value) | |
5310 | == CODE_LABEL_NUMBER (mp->value))) | |
5311 | && rtx_equal_p (fix->value, mp->value)) | |
5312 | { | |
5313 | /* More than one fix references this entry. */ | |
5314 | mp->refcount++; | |
5315 | return move_minipool_fix_forward_ref (mp, max_mp, max_address); | |
5316 | } | |
5317 | ||
5318 | /* Note the insertion point if necessary. */ | |
5319 | if (max_mp == NULL | |
5320 | && mp->max_address > max_address) | |
5321 | max_mp = mp; | |
5322 | } | |
5323 | ||
5324 | /* The value is not currently in the minipool, so we need to create | |
5325 | a new entry for it. If MAX_MP is NULL, the entry will be put on | |
5326 | the end of the list since the placement is less constrained than | |
5327 | any existing entry. Otherwise, we insert the new fix before | |
5328 | MAX_MP and, if neceesary, adjust the constraints on the other | |
5329 | entries. */ | |
5330 | mp = xmalloc (sizeof (* mp)); | |
5331 | mp->fix_size = fix->fix_size; | |
5332 | mp->mode = fix->mode; | |
5333 | mp->value = fix->value; | |
5334 | mp->refcount = 1; | |
5335 | /* Not yet required for a backwards ref. */ | |
5336 | mp->min_address = -65536; | |
5337 | ||
5338 | if (max_mp == NULL) | |
5339 | { | |
5340 | mp->max_address = max_address; | |
5341 | mp->next = NULL; | |
5342 | mp->prev = minipool_vector_tail; | |
5343 | ||
5344 | if (mp->prev == NULL) | |
5345 | { | |
5346 | minipool_vector_head = mp; | |
5347 | minipool_vector_label = gen_label_rtx (); | |
7551cbc7 | 5348 | } |
2b835d68 | 5349 | else |
d5b7b3ae | 5350 | mp->prev->next = mp; |
2b835d68 | 5351 | |
d5b7b3ae RE |
5352 | minipool_vector_tail = mp; |
5353 | } | |
5354 | else | |
5355 | { | |
5356 | if (max_address > max_mp->max_address - mp->fix_size) | |
5357 | mp->max_address = max_mp->max_address - mp->fix_size; | |
5358 | else | |
5359 | mp->max_address = max_address; | |
5360 | ||
5361 | mp->next = max_mp; | |
5362 | mp->prev = max_mp->prev; | |
5363 | max_mp->prev = mp; | |
5364 | if (mp->prev != NULL) | |
5365 | mp->prev->next = mp; | |
5366 | else | |
5367 | minipool_vector_head = mp; | |
5368 | } | |
5369 | ||
5370 | /* Save the new entry. */ | |
5371 | max_mp = mp; | |
5372 | ||
5373 | /* Scan over the preceeding entries and adjust their addresses as | |
5374 | required. */ | |
5375 | while (mp->prev != NULL | |
5376 | && mp->prev->max_address > mp->max_address - mp->prev->fix_size) | |
5377 | { | |
5378 | mp->prev->max_address = mp->max_address - mp->prev->fix_size; | |
5379 | mp = mp->prev; | |
2b835d68 RE |
5380 | } |
5381 | ||
d5b7b3ae RE |
5382 | return max_mp; |
5383 | } | |
5384 | ||
5385 | static Mnode * | |
5386 | move_minipool_fix_backward_ref (mp, min_mp, min_address) | |
5387 | Mnode * mp; | |
5388 | Mnode * min_mp; | |
5389 | HOST_WIDE_INT min_address; | |
5390 | { | |
5391 | HOST_WIDE_INT offset; | |
5392 | ||
5393 | /* This should never be true, and the code below assumes these are | |
5394 | different. */ | |
5395 | if (mp == min_mp) | |
5396 | abort (); | |
5397 | ||
5398 | if (min_mp == NULL) | |
2b835d68 | 5399 | { |
d5b7b3ae RE |
5400 | if (min_address > mp->min_address) |
5401 | mp->min_address = min_address; | |
5402 | } | |
5403 | else | |
5404 | { | |
5405 | /* We will adjust this below if it is too loose. */ | |
5406 | mp->min_address = min_address; | |
5407 | ||
5408 | /* Unlink MP from its current position. Since min_mp is non-null, | |
5409 | mp->next must be non-null. */ | |
5410 | mp->next->prev = mp->prev; | |
5411 | if (mp->prev != NULL) | |
5412 | mp->prev->next = mp->next; | |
5413 | else | |
5414 | minipool_vector_head = mp->next; | |
5415 | ||
5416 | /* Reinsert it after MIN_MP. */ | |
5417 | mp->prev = min_mp; | |
5418 | mp->next = min_mp->next; | |
5419 | min_mp->next = mp; | |
5420 | if (mp->next != NULL) | |
5421 | mp->next->prev = mp; | |
2b835d68 | 5422 | else |
d5b7b3ae RE |
5423 | minipool_vector_tail = mp; |
5424 | } | |
5425 | ||
5426 | min_mp = mp; | |
5427 | ||
5428 | offset = 0; | |
5429 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
5430 | { | |
5431 | mp->offset = offset; | |
5432 | if (mp->refcount > 0) | |
5433 | offset += mp->fix_size; | |
5434 | ||
5435 | if (mp->next && mp->next->min_address < mp->min_address + mp->fix_size) | |
5436 | mp->next->min_address = mp->min_address + mp->fix_size; | |
5437 | } | |
5438 | ||
5439 | return min_mp; | |
5440 | } | |
5441 | ||
5442 | /* Add a constant to the minipool for a backward reference. Returns the | |
5443 | node added or NULL if the constant will not fit in this pool. | |
5444 | ||
5445 | Note that the code for insertion for a backwards reference can be | |
5446 | somewhat confusing because the calculated offsets for each fix do | |
5447 | not take into account the size of the pool (which is still under | |
5448 | construction. */ | |
5449 | static Mnode * | |
5450 | add_minipool_backward_ref (fix) | |
5451 | Mfix * fix; | |
5452 | { | |
5453 | /* If set, min_mp is the last pool_entry that has a lower constraint | |
5454 | than the one we are trying to add. */ | |
5455 | Mnode * min_mp = NULL; | |
5456 | /* This can be negative, since it is only a constraint. */ | |
5457 | HOST_WIDE_INT min_address = fix->address - fix->backwards; | |
5458 | Mnode * mp; | |
5459 | ||
5460 | /* If we can't reach the current pool from this insn, or if we can't | |
5461 | insert this entry at the end of the pool without pushing other | |
5462 | fixes out of range, then we don't try. This ensures that we | |
5463 | can't fail later on. */ | |
5464 | if (min_address >= minipool_barrier->address | |
5465 | || (minipool_vector_tail->min_address + fix->fix_size | |
5466 | >= minipool_barrier->address)) | |
5467 | return NULL; | |
5468 | ||
5469 | /* Scan the pool to see if a constant with the same value has | |
5470 | already been added. While we are doing this, also note the | |
5471 | location where we must insert the constant if it doesn't already | |
5472 | exist. */ | |
5473 | for (mp = minipool_vector_tail; mp != NULL; mp = mp->prev) | |
5474 | { | |
5475 | if (GET_CODE (fix->value) == GET_CODE (mp->value) | |
5476 | && fix->mode == mp->mode | |
5477 | && (GET_CODE (fix->value) != CODE_LABEL | |
5478 | || (CODE_LABEL_NUMBER (fix->value) | |
5479 | == CODE_LABEL_NUMBER (mp->value))) | |
5480 | && rtx_equal_p (fix->value, mp->value) | |
5481 | /* Check that there is enough slack to move this entry to the | |
5482 | end of the table (this is conservative). */ | |
5483 | && (mp->max_address | |
5484 | > (minipool_barrier->address | |
5485 | + minipool_vector_tail->offset | |
5486 | + minipool_vector_tail->fix_size))) | |
5487 | { | |
5488 | mp->refcount++; | |
5489 | return move_minipool_fix_backward_ref (mp, min_mp, min_address); | |
5490 | } | |
5491 | ||
5492 | if (min_mp != NULL) | |
5493 | mp->min_address += fix->fix_size; | |
5494 | else | |
5495 | { | |
5496 | /* Note the insertion point if necessary. */ | |
5497 | if (mp->min_address < min_address) | |
5498 | min_mp = mp; | |
5499 | else if (mp->max_address | |
5500 | < minipool_barrier->address + mp->offset + fix->fix_size) | |
5501 | { | |
5502 | /* Inserting before this entry would push the fix beyond | |
5503 | its maximum address (which can happen if we have | |
5504 | re-located a forwards fix); force the new fix to come | |
5505 | after it. */ | |
5506 | min_mp = mp; | |
5507 | min_address = mp->min_address + fix->fix_size; | |
5508 | } | |
5509 | } | |
5510 | } | |
5511 | ||
5512 | /* We need to create a new entry. */ | |
5513 | mp = xmalloc (sizeof (* mp)); | |
5514 | mp->fix_size = fix->fix_size; | |
5515 | mp->mode = fix->mode; | |
5516 | mp->value = fix->value; | |
5517 | mp->refcount = 1; | |
5518 | mp->max_address = minipool_barrier->address + 65536; | |
5519 | ||
5520 | mp->min_address = min_address; | |
5521 | ||
5522 | if (min_mp == NULL) | |
5523 | { | |
5524 | mp->prev = NULL; | |
5525 | mp->next = minipool_vector_head; | |
5526 | ||
5527 | if (mp->next == NULL) | |
5528 | { | |
5529 | minipool_vector_tail = mp; | |
5530 | minipool_vector_label = gen_label_rtx (); | |
5531 | } | |
5532 | else | |
5533 | mp->next->prev = mp; | |
5534 | ||
5535 | minipool_vector_head = mp; | |
5536 | } | |
5537 | else | |
5538 | { | |
5539 | mp->next = min_mp->next; | |
5540 | mp->prev = min_mp; | |
5541 | min_mp->next = mp; | |
da6558fd | 5542 | |
d5b7b3ae RE |
5543 | if (mp->next != NULL) |
5544 | mp->next->prev = mp; | |
5545 | else | |
5546 | minipool_vector_tail = mp; | |
5547 | } | |
5548 | ||
5549 | /* Save the new entry. */ | |
5550 | min_mp = mp; | |
5551 | ||
5552 | if (mp->prev) | |
5553 | mp = mp->prev; | |
5554 | else | |
5555 | mp->offset = 0; | |
5556 | ||
5557 | /* Scan over the following entries and adjust their offsets. */ | |
5558 | while (mp->next != NULL) | |
5559 | { | |
5560 | if (mp->next->min_address < mp->min_address + mp->fix_size) | |
5561 | mp->next->min_address = mp->min_address + mp->fix_size; | |
5562 | ||
5563 | if (mp->refcount) | |
5564 | mp->next->offset = mp->offset + mp->fix_size; | |
5565 | else | |
5566 | mp->next->offset = mp->offset; | |
5567 | ||
5568 | mp = mp->next; | |
5569 | } | |
5570 | ||
5571 | return min_mp; | |
5572 | } | |
5573 | ||
5574 | static void | |
5575 | assign_minipool_offsets (barrier) | |
5576 | Mfix * barrier; | |
5577 | { | |
5578 | HOST_WIDE_INT offset = 0; | |
5579 | Mnode * mp; | |
5580 | ||
5581 | minipool_barrier = barrier; | |
5582 | ||
5583 | for (mp = minipool_vector_head; mp != NULL; mp = mp->next) | |
5584 | { | |
5585 | mp->offset = offset; | |
da6558fd | 5586 | |
d5b7b3ae RE |
5587 | if (mp->refcount > 0) |
5588 | offset += mp->fix_size; | |
5589 | } | |
5590 | } | |
5591 | ||
5592 | /* Output the literal table */ | |
5593 | static void | |
5594 | dump_minipool (scan) | |
5595 | rtx scan; | |
5596 | { | |
5597 | Mnode * mp; | |
5598 | Mnode * nmp; | |
5599 | ||
5600 | if (rtl_dump_file) | |
5601 | fprintf (rtl_dump_file, | |
5602 | ";; Emitting minipool after insn %u; address %ld\n", | |
5603 | INSN_UID (scan), (unsigned long) minipool_barrier->address); | |
5604 | ||
5605 | scan = emit_label_after (gen_label_rtx (), scan); | |
5606 | scan = emit_insn_after (gen_align_4 (), scan); | |
5607 | scan = emit_label_after (minipool_vector_label, scan); | |
5608 | ||
5609 | for (mp = minipool_vector_head; mp != NULL; mp = nmp) | |
5610 | { | |
5611 | if (mp->refcount > 0) | |
5612 | { | |
5613 | if (rtl_dump_file) | |
5614 | { | |
5615 | fprintf (rtl_dump_file, | |
5616 | ";; Offset %u, min %ld, max %ld ", | |
5617 | (unsigned) mp->offset, (unsigned long) mp->min_address, | |
5618 | (unsigned long) mp->max_address); | |
5619 | arm_print_value (rtl_dump_file, mp->value); | |
5620 | fputc ('\n', rtl_dump_file); | |
5621 | } | |
5622 | ||
5623 | switch (mp->fix_size) | |
5624 | { | |
5625 | #ifdef HAVE_consttable_1 | |
5626 | case 1: | |
5627 | scan = emit_insn_after (gen_consttable_1 (mp->value), scan); | |
5628 | break; | |
5629 | ||
5630 | #endif | |
5631 | #ifdef HAVE_consttable_2 | |
5632 | case 2: | |
5633 | scan = emit_insn_after (gen_consttable_2 (mp->value), scan); | |
5634 | break; | |
5635 | ||
5636 | #endif | |
5637 | #ifdef HAVE_consttable_4 | |
5638 | case 4: | |
5639 | scan = emit_insn_after (gen_consttable_4 (mp->value), scan); | |
5640 | break; | |
5641 | ||
5642 | #endif | |
5643 | #ifdef HAVE_consttable_8 | |
5644 | case 8: | |
5645 | scan = emit_insn_after (gen_consttable_8 (mp->value), scan); | |
5646 | break; | |
5647 | ||
5648 | #endif | |
5649 | default: | |
5650 | abort (); | |
5651 | break; | |
5652 | } | |
5653 | } | |
5654 | ||
5655 | nmp = mp->next; | |
5656 | free (mp); | |
2b835d68 RE |
5657 | } |
5658 | ||
d5b7b3ae RE |
5659 | minipool_vector_head = minipool_vector_tail = NULL; |
5660 | scan = emit_insn_after (gen_consttable_end (), scan); | |
5661 | scan = emit_barrier_after (scan); | |
2b835d68 RE |
5662 | } |
5663 | ||
d5b7b3ae RE |
5664 | /* Return the cost of forcibly inserting a barrier after INSN. */ |
5665 | static int | |
5666 | arm_barrier_cost (insn) | |
5667 | rtx insn; | |
949d79eb | 5668 | { |
d5b7b3ae RE |
5669 | /* Basing the location of the pool on the loop depth is preferable, |
5670 | but at the moment, the basic block information seems to be | |
5671 | corrupt by this stage of the compilation. */ | |
5672 | int base_cost = 50; | |
5673 | rtx next = next_nonnote_insn (insn); | |
5674 | ||
5675 | if (next != NULL && GET_CODE (next) == CODE_LABEL) | |
5676 | base_cost -= 20; | |
5677 | ||
5678 | switch (GET_CODE (insn)) | |
5679 | { | |
5680 | case CODE_LABEL: | |
5681 | /* It will always be better to place the table before the label, rather | |
5682 | than after it. */ | |
5683 | return 50; | |
949d79eb | 5684 | |
d5b7b3ae RE |
5685 | case INSN: |
5686 | case CALL_INSN: | |
5687 | return base_cost; | |
5688 | ||
5689 | case JUMP_INSN: | |
5690 | return base_cost - 10; | |
5691 | ||
5692 | default: | |
5693 | return base_cost + 10; | |
5694 | } | |
5695 | } | |
5696 | ||
5697 | /* Find the best place in the insn stream in the range | |
5698 | (FIX->address,MAX_ADDRESS) to forcibly insert a minipool barrier. | |
5699 | Create the barrier by inserting a jump and add a new fix entry for | |
5700 | it. */ | |
5701 | static Mfix * | |
5702 | create_fix_barrier (fix, max_address) | |
5703 | Mfix * fix; | |
5704 | HOST_WIDE_INT max_address; | |
5705 | { | |
5706 | HOST_WIDE_INT count = 0; | |
5707 | rtx barrier; | |
5708 | rtx from = fix->insn; | |
5709 | rtx selected = from; | |
5710 | int selected_cost; | |
5711 | HOST_WIDE_INT selected_address; | |
5712 | Mfix * new_fix; | |
5713 | HOST_WIDE_INT max_count = max_address - fix->address; | |
5714 | rtx label = gen_label_rtx (); | |
5715 | ||
5716 | selected_cost = arm_barrier_cost (from); | |
5717 | selected_address = fix->address; | |
5718 | ||
5719 | while (from && count < max_count) | |
5720 | { | |
5721 | rtx tmp; | |
5722 | int new_cost; | |
5723 | ||
5724 | /* This code shouldn't have been called if there was a natural barrier | |
5725 | within range. */ | |
5726 | if (GET_CODE (from) == BARRIER) | |
5727 | abort (); | |
5728 | ||
5729 | /* Count the length of this insn. */ | |
5730 | count += get_attr_length (from); | |
5731 | ||
5732 | /* If there is a jump table, add its length. */ | |
5733 | tmp = is_jump_table (from); | |
5734 | if (tmp != NULL) | |
5735 | { | |
5736 | count += get_jump_table_size (tmp); | |
5737 | ||
5738 | /* Jump tables aren't in a basic block, so base the cost on | |
5739 | the dispatch insn. If we select this location, we will | |
5740 | still put the pool after the table. */ | |
5741 | new_cost = arm_barrier_cost (from); | |
5742 | ||
5743 | if (count < max_count && new_cost <= selected_cost) | |
5744 | { | |
5745 | selected = tmp; | |
5746 | selected_cost = new_cost; | |
5747 | selected_address = fix->address + count; | |
5748 | } | |
5749 | ||
5750 | /* Continue after the dispatch table. */ | |
5751 | from = NEXT_INSN (tmp); | |
5752 | continue; | |
5753 | } | |
5754 | ||
5755 | new_cost = arm_barrier_cost (from); | |
5756 | ||
5757 | if (count < max_count && new_cost <= selected_cost) | |
5758 | { | |
5759 | selected = from; | |
5760 | selected_cost = new_cost; | |
5761 | selected_address = fix->address + count; | |
5762 | } | |
5763 | ||
5764 | from = NEXT_INSN (from); | |
5765 | } | |
5766 | ||
5767 | /* Create a new JUMP_INSN that branches around a barrier. */ | |
5768 | from = emit_jump_insn_after (gen_jump (label), selected); | |
5769 | JUMP_LABEL (from) = label; | |
5770 | barrier = emit_barrier_after (from); | |
5771 | emit_label_after (label, barrier); | |
5772 | ||
5773 | /* Create a minipool barrier entry for the new barrier. */ | |
c7319d87 | 5774 | new_fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* new_fix)); |
d5b7b3ae RE |
5775 | new_fix->insn = barrier; |
5776 | new_fix->address = selected_address; | |
5777 | new_fix->next = fix->next; | |
5778 | fix->next = new_fix; | |
5779 | ||
5780 | return new_fix; | |
5781 | } | |
5782 | ||
5783 | /* Record that there is a natural barrier in the insn stream at | |
5784 | ADDRESS. */ | |
949d79eb RE |
5785 | static void |
5786 | push_minipool_barrier (insn, address) | |
2b835d68 | 5787 | rtx insn; |
d5b7b3ae | 5788 | HOST_WIDE_INT address; |
2b835d68 | 5789 | { |
c7319d87 | 5790 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
ad076f4e | 5791 | |
949d79eb RE |
5792 | fix->insn = insn; |
5793 | fix->address = address; | |
2b835d68 | 5794 | |
949d79eb RE |
5795 | fix->next = NULL; |
5796 | if (minipool_fix_head != NULL) | |
5797 | minipool_fix_tail->next = fix; | |
5798 | else | |
5799 | minipool_fix_head = fix; | |
5800 | ||
5801 | minipool_fix_tail = fix; | |
5802 | } | |
2b835d68 | 5803 | |
d5b7b3ae RE |
5804 | /* Record INSN, which will need fixing up to load a value from the |
5805 | minipool. ADDRESS is the offset of the insn since the start of the | |
5806 | function; LOC is a pointer to the part of the insn which requires | |
5807 | fixing; VALUE is the constant that must be loaded, which is of type | |
5808 | MODE. */ | |
949d79eb RE |
5809 | static void |
5810 | push_minipool_fix (insn, address, loc, mode, value) | |
5811 | rtx insn; | |
d5b7b3ae RE |
5812 | HOST_WIDE_INT address; |
5813 | rtx * loc; | |
949d79eb RE |
5814 | enum machine_mode mode; |
5815 | rtx value; | |
5816 | { | |
c7319d87 | 5817 | Mfix * fix = (Mfix *) obstack_alloc (&minipool_obstack, sizeof (* fix)); |
949d79eb RE |
5818 | |
5819 | #ifdef AOF_ASSEMBLER | |
5820 | /* PIC symbol refereneces need to be converted into offsets into the | |
5821 | based area. */ | |
d5b7b3ae RE |
5822 | /* XXX This shouldn't be done here. */ |
5823 | if (flag_pic && GET_CODE (value) == SYMBOL_REF) | |
949d79eb RE |
5824 | value = aof_pic_entry (value); |
5825 | #endif /* AOF_ASSEMBLER */ | |
5826 | ||
5827 | fix->insn = insn; | |
5828 | fix->address = address; | |
5829 | fix->loc = loc; | |
5830 | fix->mode = mode; | |
d5b7b3ae | 5831 | fix->fix_size = MINIPOOL_FIX_SIZE (mode); |
949d79eb | 5832 | fix->value = value; |
d5b7b3ae RE |
5833 | fix->forwards = get_attr_pool_range (insn); |
5834 | fix->backwards = get_attr_neg_pool_range (insn); | |
5835 | fix->minipool = NULL; | |
949d79eb RE |
5836 | |
5837 | /* If an insn doesn't have a range defined for it, then it isn't | |
5838 | expecting to be reworked by this code. Better to abort now than | |
5839 | to generate duff assembly code. */ | |
d5b7b3ae | 5840 | if (fix->forwards == 0 && fix->backwards == 0) |
949d79eb RE |
5841 | abort (); |
5842 | ||
d5b7b3ae RE |
5843 | if (rtl_dump_file) |
5844 | { | |
5845 | fprintf (rtl_dump_file, | |
5846 | ";; %smode fixup for i%d; addr %lu, range (%ld,%ld): ", | |
5847 | GET_MODE_NAME (mode), | |
5848 | INSN_UID (insn), (unsigned long) address, | |
5849 | -1 * (long)fix->backwards, (long)fix->forwards); | |
5850 | arm_print_value (rtl_dump_file, fix->value); | |
5851 | fprintf (rtl_dump_file, "\n"); | |
5852 | } | |
5853 | ||
6354dc9b | 5854 | /* Add it to the chain of fixes. */ |
949d79eb | 5855 | fix->next = NULL; |
d5b7b3ae | 5856 | |
949d79eb RE |
5857 | if (minipool_fix_head != NULL) |
5858 | minipool_fix_tail->next = fix; | |
5859 | else | |
5860 | minipool_fix_head = fix; | |
5861 | ||
5862 | minipool_fix_tail = fix; | |
5863 | } | |
5864 | ||
d5b7b3ae | 5865 | /* Scan INSN and note any of its operands that need fixing. */ |
949d79eb RE |
5866 | static void |
5867 | note_invalid_constants (insn, address) | |
5868 | rtx insn; | |
d5b7b3ae | 5869 | HOST_WIDE_INT address; |
949d79eb RE |
5870 | { |
5871 | int opno; | |
5872 | ||
d5b7b3ae | 5873 | extract_insn (insn); |
949d79eb | 5874 | |
5895f793 | 5875 | if (!constrain_operands (1)) |
949d79eb RE |
5876 | fatal_insn_not_found (insn); |
5877 | ||
d5b7b3ae RE |
5878 | /* Fill in recog_op_alt with information about the constraints of this |
5879 | insn. */ | |
949d79eb RE |
5880 | preprocess_constraints (); |
5881 | ||
1ccbefce | 5882 | for (opno = 0; opno < recog_data.n_operands; opno++) |
949d79eb | 5883 | { |
6354dc9b | 5884 | /* Things we need to fix can only occur in inputs. */ |
36ab44c7 | 5885 | if (recog_data.operand_type[opno] != OP_IN) |
949d79eb RE |
5886 | continue; |
5887 | ||
5888 | /* If this alternative is a memory reference, then any mention | |
5889 | of constants in this alternative is really to fool reload | |
5890 | into allowing us to accept one there. We need to fix them up | |
5891 | now so that we output the right code. */ | |
5892 | if (recog_op_alt[opno][which_alternative].memory_ok) | |
5893 | { | |
1ccbefce | 5894 | rtx op = recog_data.operand[opno]; |
949d79eb RE |
5895 | |
5896 | if (CONSTANT_P (op)) | |
1ccbefce RH |
5897 | push_minipool_fix (insn, address, recog_data.operand_loc[opno], |
5898 | recog_data.operand_mode[opno], op); | |
d5b7b3ae RE |
5899 | #if 0 |
5900 | /* RWE: Now we look correctly at the operands for the insn, | |
5901 | this shouldn't be needed any more. */ | |
949d79eb | 5902 | #ifndef AOF_ASSEMBLER |
d5b7b3ae | 5903 | /* XXX Is this still needed? */ |
b15bca31 | 5904 | else if (GET_CODE (op) == UNSPEC && XINT (op, 1) == UNSPEC_PIC_SYM) |
1ccbefce RH |
5905 | push_minipool_fix (insn, address, recog_data.operand_loc[opno], |
5906 | recog_data.operand_mode[opno], | |
5907 | XVECEXP (op, 0, 0)); | |
949d79eb | 5908 | #endif |
d5b7b3ae RE |
5909 | #endif |
5910 | else if (GET_CODE (op) == MEM | |
949d79eb RE |
5911 | && GET_CODE (XEXP (op, 0)) == SYMBOL_REF |
5912 | && CONSTANT_POOL_ADDRESS_P (XEXP (op, 0))) | |
1ccbefce RH |
5913 | push_minipool_fix (insn, address, recog_data.operand_loc[opno], |
5914 | recog_data.operand_mode[opno], | |
949d79eb RE |
5915 | get_pool_constant (XEXP (op, 0))); |
5916 | } | |
2b835d68 | 5917 | } |
2b835d68 RE |
5918 | } |
5919 | ||
5920 | void | |
5921 | arm_reorg (first) | |
5922 | rtx first; | |
5923 | { | |
5924 | rtx insn; | |
d5b7b3ae RE |
5925 | HOST_WIDE_INT address = 0; |
5926 | Mfix * fix; | |
ad076f4e | 5927 | |
949d79eb | 5928 | minipool_fix_head = minipool_fix_tail = NULL; |
2b835d68 | 5929 | |
949d79eb RE |
5930 | /* The first insn must always be a note, or the code below won't |
5931 | scan it properly. */ | |
5932 | if (GET_CODE (first) != NOTE) | |
5933 | abort (); | |
5934 | ||
5935 | /* Scan all the insns and record the operands that will need fixing. */ | |
5936 | for (insn = next_nonnote_insn (first); insn; insn = next_nonnote_insn (insn)) | |
2b835d68 | 5937 | { |
949d79eb | 5938 | if (GET_CODE (insn) == BARRIER) |
d5b7b3ae | 5939 | push_minipool_barrier (insn, address); |
949d79eb RE |
5940 | else if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN |
5941 | || GET_CODE (insn) == JUMP_INSN) | |
5942 | { | |
5943 | rtx table; | |
5944 | ||
5945 | note_invalid_constants (insn, address); | |
5946 | address += get_attr_length (insn); | |
d5b7b3ae | 5947 | |
949d79eb RE |
5948 | /* If the insn is a vector jump, add the size of the table |
5949 | and skip the table. */ | |
d5b7b3ae | 5950 | if ((table = is_jump_table (insn)) != NULL) |
2b835d68 | 5951 | { |
d5b7b3ae | 5952 | address += get_jump_table_size (table); |
949d79eb RE |
5953 | insn = table; |
5954 | } | |
5955 | } | |
5956 | } | |
332072db | 5957 | |
d5b7b3ae RE |
5958 | fix = minipool_fix_head; |
5959 | ||
949d79eb | 5960 | /* Now scan the fixups and perform the required changes. */ |
d5b7b3ae | 5961 | while (fix) |
949d79eb | 5962 | { |
d5b7b3ae RE |
5963 | Mfix * ftmp; |
5964 | Mfix * fdel; | |
5965 | Mfix * last_added_fix; | |
5966 | Mfix * last_barrier = NULL; | |
5967 | Mfix * this_fix; | |
949d79eb RE |
5968 | |
5969 | /* Skip any further barriers before the next fix. */ | |
5970 | while (fix && GET_CODE (fix->insn) == BARRIER) | |
5971 | fix = fix->next; | |
5972 | ||
d5b7b3ae | 5973 | /* No more fixes. */ |
949d79eb RE |
5974 | if (fix == NULL) |
5975 | break; | |
332072db | 5976 | |
d5b7b3ae | 5977 | last_added_fix = NULL; |
2b835d68 | 5978 | |
d5b7b3ae | 5979 | for (ftmp = fix; ftmp; ftmp = ftmp->next) |
949d79eb | 5980 | { |
949d79eb | 5981 | if (GET_CODE (ftmp->insn) == BARRIER) |
949d79eb | 5982 | { |
d5b7b3ae RE |
5983 | if (ftmp->address >= minipool_vector_head->max_address) |
5984 | break; | |
2b835d68 | 5985 | |
d5b7b3ae | 5986 | last_barrier = ftmp; |
2b835d68 | 5987 | } |
d5b7b3ae RE |
5988 | else if ((ftmp->minipool = add_minipool_forward_ref (ftmp)) == NULL) |
5989 | break; | |
5990 | ||
5991 | last_added_fix = ftmp; /* Keep track of the last fix added. */ | |
2b835d68 | 5992 | } |
949d79eb | 5993 | |
d5b7b3ae RE |
5994 | /* If we found a barrier, drop back to that; any fixes that we |
5995 | could have reached but come after the barrier will now go in | |
5996 | the next mini-pool. */ | |
949d79eb RE |
5997 | if (last_barrier != NULL) |
5998 | { | |
d5b7b3ae RE |
5999 | /* Reduce the refcount for those fixes that won't go into this |
6000 | pool after all. */ | |
6001 | for (fdel = last_barrier->next; | |
6002 | fdel && fdel != ftmp; | |
6003 | fdel = fdel->next) | |
6004 | { | |
6005 | fdel->minipool->refcount--; | |
6006 | fdel->minipool = NULL; | |
6007 | } | |
6008 | ||
949d79eb RE |
6009 | ftmp = last_barrier; |
6010 | } | |
6011 | else | |
2bfa88dc | 6012 | { |
d5b7b3ae RE |
6013 | /* ftmp is first fix that we can't fit into this pool and |
6014 | there no natural barriers that we could use. Insert a | |
6015 | new barrier in the code somewhere between the previous | |
6016 | fix and this one, and arrange to jump around it. */ | |
6017 | HOST_WIDE_INT max_address; | |
6018 | ||
6019 | /* The last item on the list of fixes must be a barrier, so | |
6020 | we can never run off the end of the list of fixes without | |
6021 | last_barrier being set. */ | |
6022 | if (ftmp == NULL) | |
6023 | abort (); | |
6024 | ||
6025 | max_address = minipool_vector_head->max_address; | |
2bfa88dc RE |
6026 | /* Check that there isn't another fix that is in range that |
6027 | we couldn't fit into this pool because the pool was | |
6028 | already too large: we need to put the pool before such an | |
6029 | instruction. */ | |
d5b7b3ae RE |
6030 | if (ftmp->address < max_address) |
6031 | max_address = ftmp->address; | |
6032 | ||
6033 | last_barrier = create_fix_barrier (last_added_fix, max_address); | |
6034 | } | |
6035 | ||
6036 | assign_minipool_offsets (last_barrier); | |
6037 | ||
6038 | while (ftmp) | |
6039 | { | |
6040 | if (GET_CODE (ftmp->insn) != BARRIER | |
6041 | && ((ftmp->minipool = add_minipool_backward_ref (ftmp)) | |
6042 | == NULL)) | |
6043 | break; | |
2bfa88dc | 6044 | |
d5b7b3ae | 6045 | ftmp = ftmp->next; |
2bfa88dc | 6046 | } |
949d79eb RE |
6047 | |
6048 | /* Scan over the fixes we have identified for this pool, fixing them | |
6049 | up and adding the constants to the pool itself. */ | |
d5b7b3ae | 6050 | for (this_fix = fix; this_fix && ftmp != this_fix; |
949d79eb RE |
6051 | this_fix = this_fix->next) |
6052 | if (GET_CODE (this_fix->insn) != BARRIER) | |
6053 | { | |
949d79eb RE |
6054 | rtx addr |
6055 | = plus_constant (gen_rtx_LABEL_REF (VOIDmode, | |
6056 | minipool_vector_label), | |
d5b7b3ae | 6057 | this_fix->minipool->offset); |
949d79eb RE |
6058 | *this_fix->loc = gen_rtx_MEM (this_fix->mode, addr); |
6059 | } | |
6060 | ||
d5b7b3ae | 6061 | dump_minipool (last_barrier->insn); |
949d79eb | 6062 | fix = ftmp; |
2b835d68 | 6063 | } |
4b632bf1 | 6064 | |
949d79eb RE |
6065 | /* From now on we must synthesize any constants that we can't handle |
6066 | directly. This can happen if the RTL gets split during final | |
6067 | instruction generation. */ | |
4b632bf1 | 6068 | after_arm_reorg = 1; |
c7319d87 RE |
6069 | |
6070 | /* Free the minipool memory. */ | |
6071 | obstack_free (&minipool_obstack, minipool_startobj); | |
2b835d68 | 6072 | } |
cce8749e CH |
6073 | \f |
6074 | /* Routines to output assembly language. */ | |
6075 | ||
f3bb6135 | 6076 | /* If the rtx is the correct value then return the string of the number. |
ff9940b0 | 6077 | In this way we can ensure that valid double constants are generated even |
6354dc9b | 6078 | when cross compiling. */ |
cd2b33d0 | 6079 | const char * |
ff9940b0 | 6080 | fp_immediate_constant (x) |
b5cc037f | 6081 | rtx x; |
ff9940b0 RE |
6082 | { |
6083 | REAL_VALUE_TYPE r; | |
6084 | int i; | |
6085 | ||
6086 | if (!fpa_consts_inited) | |
6087 | init_fpa_table (); | |
6088 | ||
6089 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
6090 | for (i = 0; i < 8; i++) | |
6091 | if (REAL_VALUES_EQUAL (r, values_fpa[i])) | |
6092 | return strings_fpa[i]; | |
f3bb6135 | 6093 | |
ff9940b0 RE |
6094 | abort (); |
6095 | } | |
6096 | ||
9997d19d | 6097 | /* As for fp_immediate_constant, but value is passed directly, not in rtx. */ |
cd2b33d0 | 6098 | static const char * |
9997d19d | 6099 | fp_const_from_val (r) |
62b10bbc | 6100 | REAL_VALUE_TYPE * r; |
9997d19d RE |
6101 | { |
6102 | int i; | |
6103 | ||
5895f793 | 6104 | if (!fpa_consts_inited) |
9997d19d RE |
6105 | init_fpa_table (); |
6106 | ||
6107 | for (i = 0; i < 8; i++) | |
6108 | if (REAL_VALUES_EQUAL (*r, values_fpa[i])) | |
6109 | return strings_fpa[i]; | |
6110 | ||
6111 | abort (); | |
6112 | } | |
ff9940b0 | 6113 | |
cce8749e CH |
6114 | /* Output the operands of a LDM/STM instruction to STREAM. |
6115 | MASK is the ARM register set mask of which only bits 0-15 are important. | |
6d3d9133 NC |
6116 | REG is the base register, either the frame pointer or the stack pointer, |
6117 | INSTR is the possibly suffixed load or store instruction. */ | |
cce8749e | 6118 | |
d5b7b3ae | 6119 | static void |
6d3d9133 | 6120 | print_multi_reg (stream, instr, reg, mask) |
62b10bbc | 6121 | FILE * stream; |
cd2b33d0 | 6122 | const char * instr; |
dd18ae56 NC |
6123 | int reg; |
6124 | int mask; | |
cce8749e CH |
6125 | { |
6126 | int i; | |
6127 | int not_first = FALSE; | |
6128 | ||
1d5473cb | 6129 | fputc ('\t', stream); |
dd18ae56 | 6130 | asm_fprintf (stream, instr, reg); |
1d5473cb | 6131 | fputs (", {", stream); |
62b10bbc | 6132 | |
d5b7b3ae | 6133 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
cce8749e CH |
6134 | if (mask & (1 << i)) |
6135 | { | |
6136 | if (not_first) | |
6137 | fprintf (stream, ", "); | |
62b10bbc | 6138 | |
dd18ae56 | 6139 | asm_fprintf (stream, "%r", i); |
cce8749e CH |
6140 | not_first = TRUE; |
6141 | } | |
f3bb6135 | 6142 | |
6d3d9133 | 6143 | fprintf (stream, "}%s\n", TARGET_APCS_32 ? "" : "^"); |
f3bb6135 | 6144 | } |
cce8749e | 6145 | |
6354dc9b | 6146 | /* Output a 'call' insn. */ |
cce8749e | 6147 | |
cd2b33d0 | 6148 | const char * |
cce8749e | 6149 | output_call (operands) |
62b10bbc | 6150 | rtx * operands; |
cce8749e | 6151 | { |
6354dc9b | 6152 | /* Handle calls to lr using ip (which may be clobbered in subr anyway). */ |
cce8749e | 6153 | |
62b10bbc | 6154 | if (REGNO (operands[0]) == LR_REGNUM) |
cce8749e | 6155 | { |
62b10bbc | 6156 | operands[0] = gen_rtx_REG (SImode, IP_REGNUM); |
1d5473cb | 6157 | output_asm_insn ("mov%?\t%0, %|lr", operands); |
cce8749e | 6158 | } |
62b10bbc | 6159 | |
1d5473cb | 6160 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); |
da6558fd | 6161 | |
6cfc7210 | 6162 | if (TARGET_INTERWORK) |
da6558fd NC |
6163 | output_asm_insn ("bx%?\t%0", operands); |
6164 | else | |
6165 | output_asm_insn ("mov%?\t%|pc, %0", operands); | |
6166 | ||
f3bb6135 RE |
6167 | return ""; |
6168 | } | |
cce8749e | 6169 | |
ff9940b0 RE |
6170 | static int |
6171 | eliminate_lr2ip (x) | |
62b10bbc | 6172 | rtx * x; |
ff9940b0 RE |
6173 | { |
6174 | int something_changed = 0; | |
62b10bbc | 6175 | rtx x0 = * x; |
ff9940b0 RE |
6176 | int code = GET_CODE (x0); |
6177 | register int i, j; | |
6f7d635c | 6178 | register const char * fmt; |
ff9940b0 RE |
6179 | |
6180 | switch (code) | |
6181 | { | |
6182 | case REG: | |
62b10bbc | 6183 | if (REGNO (x0) == LR_REGNUM) |
ff9940b0 | 6184 | { |
62b10bbc | 6185 | *x = gen_rtx_REG (SImode, IP_REGNUM); |
ff9940b0 RE |
6186 | return 1; |
6187 | } | |
6188 | return 0; | |
6189 | default: | |
6354dc9b | 6190 | /* Scan through the sub-elements and change any references there. */ |
ff9940b0 | 6191 | fmt = GET_RTX_FORMAT (code); |
62b10bbc | 6192 | |
ff9940b0 RE |
6193 | for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) |
6194 | if (fmt[i] == 'e') | |
6195 | something_changed |= eliminate_lr2ip (&XEXP (x0, i)); | |
6196 | else if (fmt[i] == 'E') | |
6197 | for (j = 0; j < XVECLEN (x0, i); j++) | |
6198 | something_changed |= eliminate_lr2ip (&XVECEXP (x0, i, j)); | |
62b10bbc | 6199 | |
ff9940b0 RE |
6200 | return something_changed; |
6201 | } | |
6202 | } | |
6203 | ||
6354dc9b | 6204 | /* Output a 'call' insn that is a reference in memory. */ |
ff9940b0 | 6205 | |
cd2b33d0 | 6206 | const char * |
ff9940b0 | 6207 | output_call_mem (operands) |
62b10bbc | 6208 | rtx * operands; |
ff9940b0 | 6209 | { |
6354dc9b NC |
6210 | operands[0] = copy_rtx (operands[0]); /* Be ultra careful. */ |
6211 | /* Handle calls using lr by using ip (which may be clobbered in subr anyway). */ | |
ff9940b0 | 6212 | if (eliminate_lr2ip (&operands[0])) |
1d5473cb | 6213 | output_asm_insn ("mov%?\t%|ip, %|lr", operands); |
f3bb6135 | 6214 | |
6cfc7210 | 6215 | if (TARGET_INTERWORK) |
da6558fd NC |
6216 | { |
6217 | output_asm_insn ("ldr%?\t%|ip, %0", operands); | |
6218 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
6219 | output_asm_insn ("bx%?\t%|ip", operands); | |
6220 | } | |
6221 | else | |
6222 | { | |
6223 | output_asm_insn ("mov%?\t%|lr, %|pc", operands); | |
6224 | output_asm_insn ("ldr%?\t%|pc, %0", operands); | |
6225 | } | |
6226 | ||
f3bb6135 RE |
6227 | return ""; |
6228 | } | |
ff9940b0 RE |
6229 | |
6230 | ||
6231 | /* Output a move from arm registers to an fpu registers. | |
6232 | OPERANDS[0] is an fpu register. | |
6233 | OPERANDS[1] is the first registers of an arm register pair. */ | |
6234 | ||
cd2b33d0 | 6235 | const char * |
ff9940b0 | 6236 | output_mov_long_double_fpu_from_arm (operands) |
62b10bbc | 6237 | rtx * operands; |
ff9940b0 RE |
6238 | { |
6239 | int arm_reg0 = REGNO (operands[1]); | |
6240 | rtx ops[3]; | |
6241 | ||
62b10bbc NC |
6242 | if (arm_reg0 == IP_REGNUM) |
6243 | abort (); | |
f3bb6135 | 6244 | |
43cffd11 RE |
6245 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
6246 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
6247 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
ff9940b0 | 6248 | |
1d5473cb RE |
6249 | output_asm_insn ("stm%?fd\t%|sp!, {%0, %1, %2}", ops); |
6250 | output_asm_insn ("ldf%?e\t%0, [%|sp], #12", operands); | |
62b10bbc | 6251 | |
f3bb6135 RE |
6252 | return ""; |
6253 | } | |
ff9940b0 RE |
6254 | |
6255 | /* Output a move from an fpu register to arm registers. | |
6256 | OPERANDS[0] is the first registers of an arm register pair. | |
6257 | OPERANDS[1] is an fpu register. */ | |
6258 | ||
cd2b33d0 | 6259 | const char * |
ff9940b0 | 6260 | output_mov_long_double_arm_from_fpu (operands) |
62b10bbc | 6261 | rtx * operands; |
ff9940b0 RE |
6262 | { |
6263 | int arm_reg0 = REGNO (operands[0]); | |
6264 | rtx ops[3]; | |
6265 | ||
62b10bbc NC |
6266 | if (arm_reg0 == IP_REGNUM) |
6267 | abort (); | |
f3bb6135 | 6268 | |
43cffd11 RE |
6269 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
6270 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
6271 | ops[2] = gen_rtx_REG (SImode, 2 + arm_reg0); | |
ff9940b0 | 6272 | |
1d5473cb RE |
6273 | output_asm_insn ("stf%?e\t%1, [%|sp, #-12]!", operands); |
6274 | output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1, %2}", ops); | |
f3bb6135 RE |
6275 | return ""; |
6276 | } | |
ff9940b0 RE |
6277 | |
6278 | /* Output a move from arm registers to arm registers of a long double | |
6279 | OPERANDS[0] is the destination. | |
6280 | OPERANDS[1] is the source. */ | |
cd2b33d0 | 6281 | const char * |
ff9940b0 | 6282 | output_mov_long_double_arm_from_arm (operands) |
62b10bbc | 6283 | rtx * operands; |
ff9940b0 | 6284 | { |
6354dc9b | 6285 | /* We have to be careful here because the two might overlap. */ |
ff9940b0 RE |
6286 | int dest_start = REGNO (operands[0]); |
6287 | int src_start = REGNO (operands[1]); | |
6288 | rtx ops[2]; | |
6289 | int i; | |
6290 | ||
6291 | if (dest_start < src_start) | |
6292 | { | |
6293 | for (i = 0; i < 3; i++) | |
6294 | { | |
43cffd11 RE |
6295 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
6296 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 6297 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
6298 | } |
6299 | } | |
6300 | else | |
6301 | { | |
6302 | for (i = 2; i >= 0; i--) | |
6303 | { | |
43cffd11 RE |
6304 | ops[0] = gen_rtx_REG (SImode, dest_start + i); |
6305 | ops[1] = gen_rtx_REG (SImode, src_start + i); | |
9997d19d | 6306 | output_asm_insn ("mov%?\t%0, %1", ops); |
ff9940b0 RE |
6307 | } |
6308 | } | |
f3bb6135 | 6309 | |
ff9940b0 RE |
6310 | return ""; |
6311 | } | |
6312 | ||
6313 | ||
cce8749e CH |
6314 | /* Output a move from arm registers to an fpu registers. |
6315 | OPERANDS[0] is an fpu register. | |
6316 | OPERANDS[1] is the first registers of an arm register pair. */ | |
6317 | ||
cd2b33d0 | 6318 | const char * |
cce8749e | 6319 | output_mov_double_fpu_from_arm (operands) |
62b10bbc | 6320 | rtx * operands; |
cce8749e CH |
6321 | { |
6322 | int arm_reg0 = REGNO (operands[1]); | |
6323 | rtx ops[2]; | |
6324 | ||
62b10bbc NC |
6325 | if (arm_reg0 == IP_REGNUM) |
6326 | abort (); | |
6327 | ||
43cffd11 RE |
6328 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
6329 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
1d5473cb RE |
6330 | output_asm_insn ("stm%?fd\t%|sp!, {%0, %1}", ops); |
6331 | output_asm_insn ("ldf%?d\t%0, [%|sp], #8", operands); | |
f3bb6135 RE |
6332 | return ""; |
6333 | } | |
cce8749e CH |
6334 | |
6335 | /* Output a move from an fpu register to arm registers. | |
6336 | OPERANDS[0] is the first registers of an arm register pair. | |
6337 | OPERANDS[1] is an fpu register. */ | |
6338 | ||
cd2b33d0 | 6339 | const char * |
cce8749e | 6340 | output_mov_double_arm_from_fpu (operands) |
62b10bbc | 6341 | rtx * operands; |
cce8749e CH |
6342 | { |
6343 | int arm_reg0 = REGNO (operands[0]); | |
6344 | rtx ops[2]; | |
6345 | ||
62b10bbc NC |
6346 | if (arm_reg0 == IP_REGNUM) |
6347 | abort (); | |
f3bb6135 | 6348 | |
43cffd11 RE |
6349 | ops[0] = gen_rtx_REG (SImode, arm_reg0); |
6350 | ops[1] = gen_rtx_REG (SImode, 1 + arm_reg0); | |
1d5473cb RE |
6351 | output_asm_insn ("stf%?d\t%1, [%|sp, #-8]!", operands); |
6352 | output_asm_insn ("ldm%?fd\t%|sp!, {%0, %1}", ops); | |
f3bb6135 RE |
6353 | return ""; |
6354 | } | |
cce8749e CH |
6355 | |
6356 | /* Output a move between double words. | |
6357 | It must be REG<-REG, REG<-CONST_DOUBLE, REG<-CONST_INT, REG<-MEM | |
6358 | or MEM<-REG and all MEMs must be offsettable addresses. */ | |
6359 | ||
cd2b33d0 | 6360 | const char * |
cce8749e | 6361 | output_move_double (operands) |
aec3cfba | 6362 | rtx * operands; |
cce8749e CH |
6363 | { |
6364 | enum rtx_code code0 = GET_CODE (operands[0]); | |
6365 | enum rtx_code code1 = GET_CODE (operands[1]); | |
56636818 | 6366 | rtx otherops[3]; |
cce8749e CH |
6367 | |
6368 | if (code0 == REG) | |
6369 | { | |
6370 | int reg0 = REGNO (operands[0]); | |
6371 | ||
43cffd11 | 6372 | otherops[0] = gen_rtx_REG (SImode, 1 + reg0); |
aec3cfba | 6373 | |
cce8749e CH |
6374 | if (code1 == REG) |
6375 | { | |
6376 | int reg1 = REGNO (operands[1]); | |
62b10bbc NC |
6377 | if (reg1 == IP_REGNUM) |
6378 | abort (); | |
f3bb6135 | 6379 | |
6354dc9b | 6380 | /* Ensure the second source is not overwritten. */ |
c1c2bc04 | 6381 | if (reg1 == reg0 + (WORDS_BIG_ENDIAN ? -1 : 1)) |
6cfc7210 | 6382 | output_asm_insn ("mov%?\t%Q0, %Q1\n\tmov%?\t%R0, %R1", operands); |
cce8749e | 6383 | else |
6cfc7210 | 6384 | output_asm_insn ("mov%?\t%R0, %R1\n\tmov%?\t%Q0, %Q1", operands); |
cce8749e CH |
6385 | } |
6386 | else if (code1 == CONST_DOUBLE) | |
6387 | { | |
226a5051 RE |
6388 | if (GET_MODE (operands[1]) == DFmode) |
6389 | { | |
6390 | long l[2]; | |
6391 | union real_extract u; | |
6392 | ||
4e135bdd | 6393 | memcpy (&u, &CONST_DOUBLE_LOW (operands[1]), sizeof (u)); |
226a5051 | 6394 | REAL_VALUE_TO_TARGET_DOUBLE (u.d, l); |
d5b7b3ae RE |
6395 | otherops[1] = GEN_INT (l[1]); |
6396 | operands[1] = GEN_INT (l[0]); | |
226a5051 | 6397 | } |
c1c2bc04 RE |
6398 | else if (GET_MODE (operands[1]) != VOIDmode) |
6399 | abort (); | |
6400 | else if (WORDS_BIG_ENDIAN) | |
6401 | { | |
6402 | ||
6403 | otherops[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1])); | |
6404 | operands[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1])); | |
6405 | } | |
226a5051 RE |
6406 | else |
6407 | { | |
c1c2bc04 | 6408 | |
226a5051 RE |
6409 | otherops[1] = GEN_INT (CONST_DOUBLE_HIGH (operands[1])); |
6410 | operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1])); | |
6411 | } | |
6cfc7210 | 6412 | |
c1c2bc04 RE |
6413 | output_mov_immediate (operands); |
6414 | output_mov_immediate (otherops); | |
cce8749e CH |
6415 | } |
6416 | else if (code1 == CONST_INT) | |
6417 | { | |
56636818 JL |
6418 | #if HOST_BITS_PER_WIDE_INT > 32 |
6419 | /* If HOST_WIDE_INT is more than 32 bits, the intval tells us | |
6420 | what the upper word is. */ | |
6421 | if (WORDS_BIG_ENDIAN) | |
6422 | { | |
6423 | otherops[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1]))); | |
6424 | operands[1] = GEN_INT (INTVAL (operands[1]) >> 32); | |
6425 | } | |
6426 | else | |
6427 | { | |
6428 | otherops[1] = GEN_INT (INTVAL (operands[1]) >> 32); | |
6429 | operands[1] = GEN_INT (ARM_SIGN_EXTEND (INTVAL (operands[1]))); | |
6430 | } | |
6431 | #else | |
6354dc9b | 6432 | /* Sign extend the intval into the high-order word. */ |
c1c2bc04 RE |
6433 | if (WORDS_BIG_ENDIAN) |
6434 | { | |
6435 | otherops[1] = operands[1]; | |
6436 | operands[1] = (INTVAL (operands[1]) < 0 | |
6437 | ? constm1_rtx : const0_rtx); | |
6438 | } | |
ff9940b0 | 6439 | else |
c1c2bc04 | 6440 | otherops[1] = INTVAL (operands[1]) < 0 ? constm1_rtx : const0_rtx; |
56636818 | 6441 | #endif |
c1c2bc04 RE |
6442 | output_mov_immediate (otherops); |
6443 | output_mov_immediate (operands); | |
cce8749e CH |
6444 | } |
6445 | else if (code1 == MEM) | |
6446 | { | |
ff9940b0 | 6447 | switch (GET_CODE (XEXP (operands[1], 0))) |
cce8749e | 6448 | { |
ff9940b0 | 6449 | case REG: |
9997d19d | 6450 | output_asm_insn ("ldm%?ia\t%m1, %M0", operands); |
ff9940b0 | 6451 | break; |
2b835d68 | 6452 | |
ff9940b0 | 6453 | case PRE_INC: |
6354dc9b | 6454 | abort (); /* Should never happen now. */ |
ff9940b0 | 6455 | break; |
2b835d68 | 6456 | |
ff9940b0 | 6457 | case PRE_DEC: |
2b835d68 | 6458 | output_asm_insn ("ldm%?db\t%m1!, %M0", operands); |
ff9940b0 | 6459 | break; |
2b835d68 | 6460 | |
ff9940b0 | 6461 | case POST_INC: |
9997d19d | 6462 | output_asm_insn ("ldm%?ia\t%m1!, %M0", operands); |
ff9940b0 | 6463 | break; |
2b835d68 | 6464 | |
ff9940b0 | 6465 | case POST_DEC: |
6354dc9b | 6466 | abort (); /* Should never happen now. */ |
ff9940b0 | 6467 | break; |
2b835d68 RE |
6468 | |
6469 | case LABEL_REF: | |
6470 | case CONST: | |
6471 | output_asm_insn ("adr%?\t%0, %1", operands); | |
6472 | output_asm_insn ("ldm%?ia\t%0, %M0", operands); | |
6473 | break; | |
6474 | ||
ff9940b0 | 6475 | default: |
aec3cfba NC |
6476 | if (arm_add_operand (XEXP (XEXP (operands[1], 0), 1), |
6477 | GET_MODE (XEXP (XEXP (operands[1], 0), 1)))) | |
cce8749e | 6478 | { |
2b835d68 RE |
6479 | otherops[0] = operands[0]; |
6480 | otherops[1] = XEXP (XEXP (operands[1], 0), 0); | |
6481 | otherops[2] = XEXP (XEXP (operands[1], 0), 1); | |
6482 | if (GET_CODE (XEXP (operands[1], 0)) == PLUS) | |
6483 | { | |
6484 | if (GET_CODE (otherops[2]) == CONST_INT) | |
6485 | { | |
6486 | switch (INTVAL (otherops[2])) | |
6487 | { | |
6488 | case -8: | |
6489 | output_asm_insn ("ldm%?db\t%1, %M0", otherops); | |
6490 | return ""; | |
6491 | case -4: | |
6492 | output_asm_insn ("ldm%?da\t%1, %M0", otherops); | |
6493 | return ""; | |
6494 | case 4: | |
6495 | output_asm_insn ("ldm%?ib\t%1, %M0", otherops); | |
6496 | return ""; | |
6497 | } | |
6498 | if (!(const_ok_for_arm (INTVAL (otherops[2])))) | |
6499 | output_asm_insn ("sub%?\t%0, %1, #%n2", otherops); | |
6500 | else | |
6501 | output_asm_insn ("add%?\t%0, %1, %2", otherops); | |
6502 | } | |
6503 | else | |
6504 | output_asm_insn ("add%?\t%0, %1, %2", otherops); | |
6505 | } | |
6506 | else | |
6507 | output_asm_insn ("sub%?\t%0, %1, %2", otherops); | |
6cfc7210 | 6508 | |
2b835d68 RE |
6509 | return "ldm%?ia\t%0, %M0"; |
6510 | } | |
6511 | else | |
6512 | { | |
6513 | otherops[1] = adj_offsettable_operand (operands[1], 4); | |
6514 | /* Take care of overlapping base/data reg. */ | |
6515 | if (reg_mentioned_p (operands[0], operands[1])) | |
6516 | { | |
6517 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
6518 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
6519 | } | |
6520 | else | |
6521 | { | |
6522 | output_asm_insn ("ldr%?\t%0, %1", operands); | |
6523 | output_asm_insn ("ldr%?\t%0, %1", otherops); | |
6524 | } | |
cce8749e CH |
6525 | } |
6526 | } | |
6527 | } | |
2b835d68 | 6528 | else |
6354dc9b | 6529 | abort (); /* Constraints should prevent this. */ |
cce8749e CH |
6530 | } |
6531 | else if (code0 == MEM && code1 == REG) | |
6532 | { | |
62b10bbc NC |
6533 | if (REGNO (operands[1]) == IP_REGNUM) |
6534 | abort (); | |
2b835d68 | 6535 | |
ff9940b0 RE |
6536 | switch (GET_CODE (XEXP (operands[0], 0))) |
6537 | { | |
6538 | case REG: | |
9997d19d | 6539 | output_asm_insn ("stm%?ia\t%m0, %M1", operands); |
ff9940b0 | 6540 | break; |
2b835d68 | 6541 | |
ff9940b0 | 6542 | case PRE_INC: |
6354dc9b | 6543 | abort (); /* Should never happen now. */ |
ff9940b0 | 6544 | break; |
2b835d68 | 6545 | |
ff9940b0 | 6546 | case PRE_DEC: |
2b835d68 | 6547 | output_asm_insn ("stm%?db\t%m0!, %M1", operands); |
ff9940b0 | 6548 | break; |
2b835d68 | 6549 | |
ff9940b0 | 6550 | case POST_INC: |
9997d19d | 6551 | output_asm_insn ("stm%?ia\t%m0!, %M1", operands); |
ff9940b0 | 6552 | break; |
2b835d68 | 6553 | |
ff9940b0 | 6554 | case POST_DEC: |
6354dc9b | 6555 | abort (); /* Should never happen now. */ |
ff9940b0 | 6556 | break; |
2b835d68 RE |
6557 | |
6558 | case PLUS: | |
6559 | if (GET_CODE (XEXP (XEXP (operands[0], 0), 1)) == CONST_INT) | |
6560 | { | |
6561 | switch (INTVAL (XEXP (XEXP (operands[0], 0), 1))) | |
6562 | { | |
6563 | case -8: | |
6564 | output_asm_insn ("stm%?db\t%m0, %M1", operands); | |
6565 | return ""; | |
6566 | ||
6567 | case -4: | |
6568 | output_asm_insn ("stm%?da\t%m0, %M1", operands); | |
6569 | return ""; | |
6570 | ||
6571 | case 4: | |
6572 | output_asm_insn ("stm%?ib\t%m0, %M1", operands); | |
6573 | return ""; | |
6574 | } | |
6575 | } | |
6576 | /* Fall through */ | |
6577 | ||
ff9940b0 | 6578 | default: |
cce8749e | 6579 | otherops[0] = adj_offsettable_operand (operands[0], 4); |
43cffd11 | 6580 | otherops[1] = gen_rtx_REG (SImode, 1 + REGNO (operands[1])); |
9997d19d RE |
6581 | output_asm_insn ("str%?\t%1, %0", operands); |
6582 | output_asm_insn ("str%?\t%1, %0", otherops); | |
cce8749e CH |
6583 | } |
6584 | } | |
2b835d68 | 6585 | else |
62b10bbc | 6586 | abort (); /* Constraints should prevent this */ |
cce8749e | 6587 | |
9997d19d RE |
6588 | return ""; |
6589 | } | |
cce8749e CH |
6590 | |
6591 | ||
6592 | /* Output an arbitrary MOV reg, #n. | |
6593 | OPERANDS[0] is a register. OPERANDS[1] is a const_int. */ | |
6594 | ||
cd2b33d0 | 6595 | const char * |
cce8749e | 6596 | output_mov_immediate (operands) |
62b10bbc | 6597 | rtx * operands; |
cce8749e | 6598 | { |
f3bb6135 | 6599 | HOST_WIDE_INT n = INTVAL (operands[1]); |
cce8749e CH |
6600 | int n_ones = 0; |
6601 | int i; | |
6602 | ||
6603 | /* Try to use one MOV */ | |
cce8749e | 6604 | if (const_ok_for_arm (n)) |
f3bb6135 | 6605 | { |
9997d19d | 6606 | output_asm_insn ("mov%?\t%0, %1", operands); |
f3bb6135 RE |
6607 | return ""; |
6608 | } | |
cce8749e CH |
6609 | |
6610 | /* Try to use one MVN */ | |
f3bb6135 | 6611 | if (const_ok_for_arm (~n)) |
cce8749e | 6612 | { |
f3bb6135 | 6613 | operands[1] = GEN_INT (~n); |
9997d19d | 6614 | output_asm_insn ("mvn%?\t%0, %1", operands); |
f3bb6135 | 6615 | return ""; |
cce8749e CH |
6616 | } |
6617 | ||
6354dc9b | 6618 | /* If all else fails, make it out of ORRs or BICs as appropriate. */ |
cce8749e CH |
6619 | |
6620 | for (i=0; i < 32; i++) | |
6621 | if (n & 1 << i) | |
6622 | n_ones++; | |
6623 | ||
6354dc9b | 6624 | if (n_ones > 16) /* Shorter to use MVN with BIC in this case. */ |
e5951263 | 6625 | output_multi_immediate (operands, "mvn%?\t%0, %1", "bic%?\t%0, %0, %1", 1, ~n); |
cce8749e | 6626 | else |
d5b7b3ae | 6627 | output_multi_immediate (operands, "mov%?\t%0, %1", "orr%?\t%0, %0, %1", 1, n); |
f3bb6135 RE |
6628 | |
6629 | return ""; | |
6630 | } | |
cce8749e CH |
6631 | |
6632 | ||
6633 | /* Output an ADD r, s, #n where n may be too big for one instruction. If | |
6634 | adding zero to one register, output nothing. */ | |
6635 | ||
cd2b33d0 | 6636 | const char * |
cce8749e | 6637 | output_add_immediate (operands) |
62b10bbc | 6638 | rtx * operands; |
cce8749e | 6639 | { |
f3bb6135 | 6640 | HOST_WIDE_INT n = INTVAL (operands[2]); |
cce8749e CH |
6641 | |
6642 | if (n != 0 || REGNO (operands[0]) != REGNO (operands[1])) | |
6643 | { | |
6644 | if (n < 0) | |
6645 | output_multi_immediate (operands, | |
9997d19d RE |
6646 | "sub%?\t%0, %1, %2", "sub%?\t%0, %0, %2", 2, |
6647 | -n); | |
cce8749e CH |
6648 | else |
6649 | output_multi_immediate (operands, | |
9997d19d RE |
6650 | "add%?\t%0, %1, %2", "add%?\t%0, %0, %2", 2, |
6651 | n); | |
cce8749e | 6652 | } |
f3bb6135 RE |
6653 | |
6654 | return ""; | |
6655 | } | |
cce8749e | 6656 | |
cce8749e CH |
6657 | /* Output a multiple immediate operation. |
6658 | OPERANDS is the vector of operands referred to in the output patterns. | |
6659 | INSTR1 is the output pattern to use for the first constant. | |
6660 | INSTR2 is the output pattern to use for subsequent constants. | |
6661 | IMMED_OP is the index of the constant slot in OPERANDS. | |
6662 | N is the constant value. */ | |
6663 | ||
cd2b33d0 | 6664 | static const char * |
cce8749e | 6665 | output_multi_immediate (operands, instr1, instr2, immed_op, n) |
62b10bbc | 6666 | rtx * operands; |
cd2b33d0 NC |
6667 | const char * instr1; |
6668 | const char * instr2; | |
f3bb6135 RE |
6669 | int immed_op; |
6670 | HOST_WIDE_INT n; | |
cce8749e | 6671 | { |
f3bb6135 | 6672 | #if HOST_BITS_PER_WIDE_INT > 32 |
e5951263 | 6673 | n &= HOST_UINT (0xffffffff); |
f3bb6135 RE |
6674 | #endif |
6675 | ||
cce8749e CH |
6676 | if (n == 0) |
6677 | { | |
6678 | operands[immed_op] = const0_rtx; | |
6354dc9b | 6679 | output_asm_insn (instr1, operands); /* Quick and easy output. */ |
cce8749e CH |
6680 | } |
6681 | else | |
6682 | { | |
6683 | int i; | |
cd2b33d0 | 6684 | const char * instr = instr1; |
cce8749e | 6685 | |
6354dc9b | 6686 | /* Note that n is never zero here (which would give no output). */ |
cce8749e CH |
6687 | for (i = 0; i < 32; i += 2) |
6688 | { | |
6689 | if (n & (3 << i)) | |
6690 | { | |
f3bb6135 RE |
6691 | operands[immed_op] = GEN_INT (n & (255 << i)); |
6692 | output_asm_insn (instr, operands); | |
cce8749e CH |
6693 | instr = instr2; |
6694 | i += 6; | |
6695 | } | |
6696 | } | |
6697 | } | |
cd2b33d0 | 6698 | |
f3bb6135 | 6699 | return ""; |
9997d19d | 6700 | } |
cce8749e CH |
6701 | |
6702 | ||
6703 | /* Return the appropriate ARM instruction for the operation code. | |
6704 | The returned result should not be overwritten. OP is the rtx of the | |
6705 | operation. SHIFT_FIRST_ARG is TRUE if the first argument of the operator | |
6706 | was shifted. */ | |
6707 | ||
cd2b33d0 | 6708 | const char * |
cce8749e CH |
6709 | arithmetic_instr (op, shift_first_arg) |
6710 | rtx op; | |
f3bb6135 | 6711 | int shift_first_arg; |
cce8749e | 6712 | { |
9997d19d | 6713 | switch (GET_CODE (op)) |
cce8749e CH |
6714 | { |
6715 | case PLUS: | |
f3bb6135 RE |
6716 | return "add"; |
6717 | ||
cce8749e | 6718 | case MINUS: |
f3bb6135 RE |
6719 | return shift_first_arg ? "rsb" : "sub"; |
6720 | ||
cce8749e | 6721 | case IOR: |
f3bb6135 RE |
6722 | return "orr"; |
6723 | ||
cce8749e | 6724 | case XOR: |
f3bb6135 RE |
6725 | return "eor"; |
6726 | ||
cce8749e | 6727 | case AND: |
f3bb6135 RE |
6728 | return "and"; |
6729 | ||
cce8749e | 6730 | default: |
f3bb6135 | 6731 | abort (); |
cce8749e | 6732 | } |
f3bb6135 | 6733 | } |
cce8749e CH |
6734 | |
6735 | ||
6736 | /* Ensure valid constant shifts and return the appropriate shift mnemonic | |
6737 | for the operation code. The returned result should not be overwritten. | |
6738 | OP is the rtx code of the shift. | |
9997d19d | 6739 | On exit, *AMOUNTP will be -1 if the shift is by a register, or a constant |
6354dc9b | 6740 | shift. */ |
cce8749e | 6741 | |
cd2b33d0 | 6742 | static const char * |
9997d19d RE |
6743 | shift_op (op, amountp) |
6744 | rtx op; | |
6745 | HOST_WIDE_INT *amountp; | |
cce8749e | 6746 | { |
cd2b33d0 | 6747 | const char * mnem; |
e2c671ba | 6748 | enum rtx_code code = GET_CODE (op); |
cce8749e | 6749 | |
9997d19d RE |
6750 | if (GET_CODE (XEXP (op, 1)) == REG || GET_CODE (XEXP (op, 1)) == SUBREG) |
6751 | *amountp = -1; | |
6752 | else if (GET_CODE (XEXP (op, 1)) == CONST_INT) | |
6753 | *amountp = INTVAL (XEXP (op, 1)); | |
6754 | else | |
6755 | abort (); | |
6756 | ||
e2c671ba | 6757 | switch (code) |
cce8749e CH |
6758 | { |
6759 | case ASHIFT: | |
6760 | mnem = "asl"; | |
6761 | break; | |
f3bb6135 | 6762 | |
cce8749e CH |
6763 | case ASHIFTRT: |
6764 | mnem = "asr"; | |
cce8749e | 6765 | break; |
f3bb6135 | 6766 | |
cce8749e CH |
6767 | case LSHIFTRT: |
6768 | mnem = "lsr"; | |
cce8749e | 6769 | break; |
f3bb6135 | 6770 | |
9997d19d RE |
6771 | case ROTATERT: |
6772 | mnem = "ror"; | |
9997d19d RE |
6773 | break; |
6774 | ||
ff9940b0 | 6775 | case MULT: |
e2c671ba RE |
6776 | /* We never have to worry about the amount being other than a |
6777 | power of 2, since this case can never be reloaded from a reg. */ | |
9997d19d RE |
6778 | if (*amountp != -1) |
6779 | *amountp = int_log2 (*amountp); | |
6780 | else | |
6781 | abort (); | |
f3bb6135 RE |
6782 | return "asl"; |
6783 | ||
cce8749e | 6784 | default: |
f3bb6135 | 6785 | abort (); |
cce8749e CH |
6786 | } |
6787 | ||
e2c671ba RE |
6788 | if (*amountp != -1) |
6789 | { | |
6790 | /* This is not 100% correct, but follows from the desire to merge | |
6791 | multiplication by a power of 2 with the recognizer for a | |
6792 | shift. >=32 is not a valid shift for "asl", so we must try and | |
6793 | output a shift that produces the correct arithmetical result. | |
ddd5a7c1 | 6794 | Using lsr #32 is identical except for the fact that the carry bit |
e2c671ba RE |
6795 | is not set correctly if we set the flags; but we never use the |
6796 | carry bit from such an operation, so we can ignore that. */ | |
6797 | if (code == ROTATERT) | |
6798 | *amountp &= 31; /* Rotate is just modulo 32 */ | |
6799 | else if (*amountp != (*amountp & 31)) | |
6800 | { | |
6801 | if (code == ASHIFT) | |
6802 | mnem = "lsr"; | |
6803 | *amountp = 32; | |
6804 | } | |
6805 | ||
6806 | /* Shifts of 0 are no-ops. */ | |
6807 | if (*amountp == 0) | |
6808 | return NULL; | |
6809 | } | |
6810 | ||
9997d19d RE |
6811 | return mnem; |
6812 | } | |
cce8749e CH |
6813 | |
6814 | ||
6354dc9b | 6815 | /* Obtain the shift from the POWER of two. */ |
18af7313 | 6816 | static HOST_WIDE_INT |
cce8749e | 6817 | int_log2 (power) |
f3bb6135 | 6818 | HOST_WIDE_INT power; |
cce8749e | 6819 | { |
f3bb6135 | 6820 | HOST_WIDE_INT shift = 0; |
cce8749e | 6821 | |
e5951263 | 6822 | while ((((HOST_INT (1)) << shift) & power) == 0) |
cce8749e CH |
6823 | { |
6824 | if (shift > 31) | |
f3bb6135 | 6825 | abort (); |
cce8749e CH |
6826 | shift++; |
6827 | } | |
f3bb6135 RE |
6828 | |
6829 | return shift; | |
6830 | } | |
cce8749e | 6831 | |
cce8749e CH |
6832 | /* Output a .ascii pseudo-op, keeping track of lengths. This is because |
6833 | /bin/as is horribly restrictive. */ | |
6cfc7210 | 6834 | #define MAX_ASCII_LEN 51 |
cce8749e CH |
6835 | |
6836 | void | |
6837 | output_ascii_pseudo_op (stream, p, len) | |
62b10bbc | 6838 | FILE * stream; |
3cce094d | 6839 | const unsigned char * p; |
cce8749e CH |
6840 | int len; |
6841 | { | |
6842 | int i; | |
6cfc7210 | 6843 | int len_so_far = 0; |
cce8749e | 6844 | |
6cfc7210 NC |
6845 | fputs ("\t.ascii\t\"", stream); |
6846 | ||
cce8749e CH |
6847 | for (i = 0; i < len; i++) |
6848 | { | |
6849 | register int c = p[i]; | |
6850 | ||
6cfc7210 | 6851 | if (len_so_far >= MAX_ASCII_LEN) |
cce8749e | 6852 | { |
6cfc7210 | 6853 | fputs ("\"\n\t.ascii\t\"", stream); |
cce8749e | 6854 | len_so_far = 0; |
cce8749e CH |
6855 | } |
6856 | ||
6cfc7210 | 6857 | switch (c) |
cce8749e | 6858 | { |
6cfc7210 NC |
6859 | case TARGET_TAB: |
6860 | fputs ("\\t", stream); | |
6861 | len_so_far += 2; | |
6862 | break; | |
6863 | ||
6864 | case TARGET_FF: | |
6865 | fputs ("\\f", stream); | |
6866 | len_so_far += 2; | |
6867 | break; | |
6868 | ||
6869 | case TARGET_BS: | |
6870 | fputs ("\\b", stream); | |
6871 | len_so_far += 2; | |
6872 | break; | |
6873 | ||
6874 | case TARGET_CR: | |
6875 | fputs ("\\r", stream); | |
6876 | len_so_far += 2; | |
6877 | break; | |
6878 | ||
6879 | case TARGET_NEWLINE: | |
6880 | fputs ("\\n", stream); | |
6881 | c = p [i + 1]; | |
6882 | if ((c >= ' ' && c <= '~') | |
6883 | || c == TARGET_TAB) | |
6884 | /* This is a good place for a line break. */ | |
6885 | len_so_far = MAX_ASCII_LEN; | |
6886 | else | |
6887 | len_so_far += 2; | |
6888 | break; | |
6889 | ||
6890 | case '\"': | |
6891 | case '\\': | |
6892 | putc ('\\', stream); | |
5895f793 | 6893 | len_so_far++; |
6cfc7210 | 6894 | /* drop through. */ |
f3bb6135 | 6895 | |
6cfc7210 NC |
6896 | default: |
6897 | if (c >= ' ' && c <= '~') | |
6898 | { | |
6899 | putc (c, stream); | |
5895f793 | 6900 | len_so_far++; |
6cfc7210 NC |
6901 | } |
6902 | else | |
6903 | { | |
6904 | fprintf (stream, "\\%03o", c); | |
6905 | len_so_far += 4; | |
6906 | } | |
6907 | break; | |
cce8749e | 6908 | } |
cce8749e | 6909 | } |
f3bb6135 | 6910 | |
cce8749e | 6911 | fputs ("\"\n", stream); |
f3bb6135 | 6912 | } |
cce8749e | 6913 | \f |
6d3d9133 NC |
6914 | /* Compute a bit mask of which registers need to be |
6915 | saved on the stack for the current function. */ | |
6916 | ||
6917 | static unsigned long | |
6918 | arm_compute_save_reg_mask () | |
6919 | { | |
6920 | unsigned int save_reg_mask = 0; | |
6921 | unsigned int reg; | |
6922 | unsigned long func_type = arm_current_func_type (); | |
6923 | ||
6924 | if (IS_NAKED (func_type)) | |
6925 | /* This should never really happen. */ | |
6926 | return 0; | |
6927 | ||
6928 | /* If we are creating a stack frame, then we must save the frame pointer, | |
6929 | IP (which will hold the old stack pointer), LR and the PC. */ | |
6930 | if (frame_pointer_needed) | |
6931 | save_reg_mask |= | |
6932 | (1 << ARM_HARD_FRAME_POINTER_REGNUM) | |
6933 | | (1 << IP_REGNUM) | |
6934 | | (1 << LR_REGNUM) | |
6935 | | (1 << PC_REGNUM); | |
6936 | ||
6937 | /* Volatile functions do not return, so there | |
6938 | is no need to save any other registers. */ | |
6939 | if (IS_VOLATILE (func_type)) | |
6940 | return save_reg_mask; | |
6941 | ||
6942 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_ISR) | |
6943 | { | |
6944 | /* FIQ handlers have registers r8 - r12 banked, so | |
6945 | we only need to check r0 - r7, they must save them. */ | |
6946 | for (reg = 0; reg < 8; reg++) | |
6947 | if (regs_ever_live[reg]) | |
6948 | save_reg_mask |= (1 << reg); | |
6949 | } | |
6950 | else | |
6951 | { | |
6952 | /* In the normal case we only need to save those registers | |
6953 | which are call saved and which are used by this function. */ | |
6954 | for (reg = 0; reg <= 10; reg++) | |
6955 | if (regs_ever_live[reg] && ! call_used_regs [reg]) | |
6956 | save_reg_mask |= (1 << reg); | |
6957 | ||
6958 | /* Handle the frame pointer as a special case. */ | |
6959 | if (! TARGET_APCS_FRAME | |
6960 | && ! frame_pointer_needed | |
6961 | && regs_ever_live[HARD_FRAME_POINTER_REGNUM] | |
6962 | && ! call_used_regs[HARD_FRAME_POINTER_REGNUM]) | |
6963 | save_reg_mask |= 1 << HARD_FRAME_POINTER_REGNUM; | |
6964 | ||
6965 | /* If we aren't loading the PIC register, | |
6966 | don't stack it even though it may be live. */ | |
6967 | if (flag_pic | |
6968 | && ! TARGET_SINGLE_PIC_BASE | |
6969 | && regs_ever_live[PIC_OFFSET_TABLE_REGNUM]) | |
6970 | save_reg_mask |= 1 << PIC_OFFSET_TABLE_REGNUM; | |
6971 | } | |
6972 | ||
6973 | /* Decide if we need to save the link register. | |
6974 | Interrupt routines have their own banked link register, | |
6975 | so they never need to save it. | |
6976 | Otheriwse if we do not use the link register we do not need to save | |
6977 | it. If we are pushing other registers onto the stack however, we | |
6978 | can save an instruction in the epilogue by pushing the link register | |
6979 | now and then popping it back into the PC. This incurs extra memory | |
6980 | accesses though, so we only do it when optimising for size, and only | |
6981 | if we know that we will not need a fancy return sequence. */ | |
6982 | if (! IS_INTERRUPT (func_type) | |
6983 | && (regs_ever_live [LR_REGNUM] | |
6984 | || (save_reg_mask | |
6985 | && optimize_size | |
6986 | && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL))) | |
6987 | save_reg_mask |= 1 << LR_REGNUM; | |
6988 | ||
6f7ebcbb NC |
6989 | if (cfun->machine->lr_save_eliminated) |
6990 | save_reg_mask &= ~ (1 << LR_REGNUM); | |
6991 | ||
6d3d9133 NC |
6992 | return save_reg_mask; |
6993 | } | |
6994 | ||
6995 | /* Generate a function exit sequence. If REALLY_RETURN is true, then do | |
6996 | everything bar the final return instruction. */ | |
ff9940b0 | 6997 | |
cd2b33d0 | 6998 | const char * |
84ed5e79 | 6999 | output_return_instruction (operand, really_return, reverse) |
f3bb6135 RE |
7000 | rtx operand; |
7001 | int really_return; | |
84ed5e79 | 7002 | int reverse; |
ff9940b0 | 7003 | { |
6d3d9133 | 7004 | char conditional[10]; |
ff9940b0 | 7005 | char instr[100]; |
6d3d9133 NC |
7006 | int reg; |
7007 | unsigned long live_regs_mask; | |
7008 | unsigned long func_type; | |
7009 | ||
7010 | func_type = arm_current_func_type (); | |
e2c671ba | 7011 | |
6d3d9133 | 7012 | if (IS_NAKED (func_type)) |
d5b7b3ae | 7013 | return ""; |
6d3d9133 NC |
7014 | |
7015 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) | |
e2c671ba | 7016 | { |
e2c671ba | 7017 | /* If this function was declared non-returning, and we have found a tail |
3a5a4282 PB |
7018 | call, then we have to trust that the called function won't return. */ |
7019 | if (really_return) | |
7020 | { | |
7021 | rtx ops[2]; | |
7022 | ||
7023 | /* Otherwise, trap an attempted return by aborting. */ | |
7024 | ops[0] = operand; | |
7025 | ops[1] = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" | |
7026 | : "abort"); | |
7027 | assemble_external_libcall (ops[1]); | |
7028 | output_asm_insn (reverse ? "bl%D0\t%a1" : "bl%d0\t%a1", ops); | |
7029 | } | |
7030 | ||
e2c671ba RE |
7031 | return ""; |
7032 | } | |
6d3d9133 | 7033 | |
5895f793 | 7034 | if (current_function_calls_alloca && !really_return) |
62b10bbc | 7035 | abort (); |
ff9940b0 | 7036 | |
6d3d9133 NC |
7037 | /* Construct the conditional part of the instruction(s) to be emitted. */ |
7038 | sprintf (conditional, "%%?%%%c0", reverse ? 'D' : 'd'); | |
d5b7b3ae | 7039 | |
6d3d9133 | 7040 | return_used_this_function = 1; |
ff9940b0 | 7041 | |
6d3d9133 | 7042 | live_regs_mask = arm_compute_save_reg_mask (); |
ff9940b0 | 7043 | |
3a5a4282 | 7044 | /* On some ARM architectures it is faster to use LDR rather than LDM to |
6d3d9133 NC |
7045 | load a single register. On other architectures, the cost is the same. |
7046 | In 26 bit mode we have to use LDM in order to be able to restore the CPSR. */ | |
7047 | if ((live_regs_mask == (1 << LR_REGNUM)) | |
7048 | && (! really_return || TARGET_APCS_32)) | |
7049 | { | |
7050 | if (! really_return) | |
7051 | sprintf (instr, "ldr%s\t%%|lr, [%%|sp], #4", conditional); | |
7052 | else | |
7053 | sprintf (instr, "ldr%s\t%%|pc, [%%|sp], #4", conditional); | |
7054 | } | |
7055 | else if (live_regs_mask) | |
7056 | { | |
7057 | if ((live_regs_mask & (1 << IP_REGNUM)) == (1 << IP_REGNUM)) | |
7058 | /* There are two possible reasons for the IP register being saved. | |
7059 | Either a stack frame was created, in which case IP contains the | |
7060 | old stack pointer, or an ISR routine corrupted it. If this in an | |
7061 | ISR routine then just restore IP, otherwise restore IP into SP. */ | |
7062 | if (! IS_INTERRUPT (func_type)) | |
7063 | { | |
7064 | live_regs_mask &= ~ (1 << IP_REGNUM); | |
7065 | live_regs_mask |= (1 << SP_REGNUM); | |
7066 | } | |
f3bb6135 | 7067 | |
6d3d9133 | 7068 | /* Generate the load multiple instruction to restore the registers. */ |
ff9940b0 | 7069 | if (frame_pointer_needed) |
6d3d9133 | 7070 | sprintf (instr, "ldm%sea\t%%|fp, {", conditional); |
ff9940b0 | 7071 | else |
6d3d9133 | 7072 | sprintf (instr, "ldm%sfd\t%%|sp!, {", conditional); |
f3bb6135 | 7073 | |
6d3d9133 NC |
7074 | for (reg = 0; reg <= SP_REGNUM; reg++) |
7075 | if (live_regs_mask & (1 << reg)) | |
7076 | { | |
1d5473cb | 7077 | strcat (instr, "%|"); |
6d3d9133 NC |
7078 | strcat (instr, reg_names[reg]); |
7079 | strcat (instr, ", "); | |
7080 | } | |
f3bb6135 | 7081 | |
6d3d9133 NC |
7082 | if ((live_regs_mask & (1 << LR_REGNUM)) == 0) |
7083 | { | |
7084 | /* If we are not restoring the LR register then we will | |
7085 | have added one too many commas to the list above. | |
7086 | Replace it with a closing brace. */ | |
7087 | instr [strlen (instr) - 2] = '}'; | |
7088 | } | |
ff9940b0 | 7089 | else |
1d5473cb RE |
7090 | { |
7091 | strcat (instr, "%|"); | |
6d3d9133 NC |
7092 | |
7093 | /* At this point there should only be one or two registers left in | |
7094 | live_regs_mask: always LR, and possibly PC if we created a stack | |
7095 | frame. LR contains the return address. If we do not have any | |
7096 | special requirements for function exit (eg interworking, or ISR) | |
7097 | then we can load this value directly into the PC and save an | |
7098 | instruction. */ | |
7099 | if (! TARGET_INTERWORK | |
7100 | && ! IS_INTERRUPT (func_type) | |
7101 | && really_return) | |
7102 | strcat (instr, reg_names [PC_REGNUM]); | |
da6558fd | 7103 | else |
6d3d9133 NC |
7104 | strcat (instr, reg_names [LR_REGNUM]); |
7105 | ||
7106 | strcat (instr, (TARGET_APCS_32 || !really_return) ? "}" : "}^"); | |
1d5473cb | 7107 | } |
da6558fd | 7108 | |
6d3d9133 | 7109 | if (really_return) |
da6558fd | 7110 | { |
6d3d9133 NC |
7111 | /* See if we need to generate an extra instruction to |
7112 | perform the actual function return. */ | |
7113 | switch ((int) ARM_FUNC_TYPE (func_type)) | |
7114 | { | |
7115 | case ARM_FT_ISR: | |
7116 | case ARM_FT_FIQ: | |
7117 | output_asm_insn (instr, & operand); | |
7118 | ||
7119 | strcpy (instr, "sub"); | |
7120 | strcat (instr, conditional); | |
7121 | strcat (instr, "s\t%|pc, %|lr, #4"); | |
7122 | break; | |
7123 | ||
7124 | case ARM_FT_EXCEPTION: | |
7125 | output_asm_insn (instr, & operand); | |
7126 | ||
7127 | strcpy (instr, "mov"); | |
7128 | strcat (instr, conditional); | |
7129 | strcat (instr, "s\t%|pc, %|lr"); | |
7130 | break; | |
7131 | ||
7132 | case ARM_FT_INTERWORKED: | |
7133 | output_asm_insn (instr, & operand); | |
da6558fd | 7134 | |
6d3d9133 NC |
7135 | strcpy (instr, "bx"); |
7136 | strcat (instr, conditional); | |
7137 | strcat (instr, "\t%|lr"); | |
7138 | break; | |
7139 | ||
7140 | default: | |
7141 | /* The return has already been handled | |
7142 | by loading the LR into the PC. */ | |
7143 | if ((live_regs_mask & (1 << LR_REGNUM)) == 0) | |
7144 | { | |
7145 | output_asm_insn (instr, & operand); | |
7146 | ||
7147 | strcpy (instr, "mov"); | |
7148 | strcat (instr, conditional); | |
7149 | if (! TARGET_APCS_32) | |
7150 | strcat (instr, "s"); | |
7151 | strcat (instr, "\t%|pc, %|lr"); | |
7152 | } | |
7153 | break; | |
7154 | } | |
da6558fd | 7155 | } |
ff9940b0 RE |
7156 | } |
7157 | else if (really_return) | |
7158 | { | |
6d3d9133 NC |
7159 | switch ((int) ARM_FUNC_TYPE (func_type)) |
7160 | { | |
7161 | case ARM_FT_ISR: | |
7162 | case ARM_FT_FIQ: | |
7163 | sprintf (instr, "sub%ss\t%%|pc, %%|lr, #4", conditional); | |
7164 | break; | |
7165 | ||
7166 | case ARM_FT_INTERWORKED: | |
7167 | sprintf (instr, "bx%s\t%%|lr", conditional); | |
7168 | break; | |
7169 | ||
7170 | case ARM_FT_EXCEPTION: | |
7171 | sprintf (instr, "mov%ss\t%%|pc, %%|lr", conditional); | |
7172 | break; | |
7173 | ||
7174 | default: | |
7175 | sprintf (instr, "mov%s%s\t%%|pc, %%|lr", | |
7176 | conditional, TARGET_APCS_32 ? "" : "s"); | |
7177 | break; | |
7178 | } | |
ff9940b0 | 7179 | } |
6d3d9133 NC |
7180 | else |
7181 | /* Nothing to load off the stack, and | |
7182 | no return instruction to generate. */ | |
7183 | return ""; | |
f3bb6135 | 7184 | |
6d3d9133 NC |
7185 | output_asm_insn (instr, & operand); |
7186 | ||
ff9940b0 RE |
7187 | return ""; |
7188 | } | |
7189 | ||
ef179a26 NC |
7190 | /* Write the function name into the code section, directly preceding |
7191 | the function prologue. | |
7192 | ||
7193 | Code will be output similar to this: | |
7194 | t0 | |
7195 | .ascii "arm_poke_function_name", 0 | |
7196 | .align | |
7197 | t1 | |
7198 | .word 0xff000000 + (t1 - t0) | |
7199 | arm_poke_function_name | |
7200 | mov ip, sp | |
7201 | stmfd sp!, {fp, ip, lr, pc} | |
7202 | sub fp, ip, #4 | |
7203 | ||
7204 | When performing a stack backtrace, code can inspect the value | |
7205 | of 'pc' stored at 'fp' + 0. If the trace function then looks | |
7206 | at location pc - 12 and the top 8 bits are set, then we know | |
7207 | that there is a function name embedded immediately preceding this | |
7208 | location and has length ((pc[-3]) & 0xff000000). | |
7209 | ||
7210 | We assume that pc is declared as a pointer to an unsigned long. | |
7211 | ||
7212 | It is of no benefit to output the function name if we are assembling | |
7213 | a leaf function. These function types will not contain a stack | |
7214 | backtrace structure, therefore it is not possible to determine the | |
7215 | function name. */ | |
7216 | ||
7217 | void | |
7218 | arm_poke_function_name (stream, name) | |
7219 | FILE * stream; | |
7220 | char * name; | |
7221 | { | |
7222 | unsigned long alignlength; | |
7223 | unsigned long length; | |
7224 | rtx x; | |
7225 | ||
d5b7b3ae RE |
7226 | length = strlen (name) + 1; |
7227 | alignlength = ROUND_UP (length); | |
ef179a26 | 7228 | |
949d79eb | 7229 | ASM_OUTPUT_ASCII (stream, name, length); |
ef179a26 | 7230 | ASM_OUTPUT_ALIGN (stream, 2); |
e5951263 | 7231 | x = GEN_INT (HOST_UINT(0xff000000) + alignlength); |
ef179a26 NC |
7232 | ASM_OUTPUT_INT (stream, x); |
7233 | } | |
7234 | ||
6d3d9133 NC |
7235 | /* Place some comments into the assembler stream |
7236 | describing the current function. */ | |
7237 | ||
cce8749e | 7238 | void |
d5b7b3ae | 7239 | output_arm_prologue (f, frame_size) |
6cfc7210 | 7240 | FILE * f; |
cce8749e CH |
7241 | int frame_size; |
7242 | { | |
6d3d9133 NC |
7243 | unsigned long func_type; |
7244 | ||
7245 | /* Sanity check. */ | |
abaa26e5 | 7246 | if (arm_ccfsm_state || arm_target_insn) |
6d3d9133 | 7247 | abort (); |
31fdb4d5 | 7248 | |
6d3d9133 NC |
7249 | func_type = arm_current_func_type (); |
7250 | ||
7251 | switch ((int) ARM_FUNC_TYPE (func_type)) | |
7252 | { | |
7253 | default: | |
7254 | case ARM_FT_NORMAL: | |
7255 | break; | |
7256 | case ARM_FT_INTERWORKED: | |
7257 | asm_fprintf (f, "\t%@ Function supports interworking.\n"); | |
7258 | break; | |
7259 | case ARM_FT_EXCEPTION_HANDLER: | |
7260 | asm_fprintf (f, "\t%@ C++ Exception Handler.\n"); | |
7261 | break; | |
7262 | case ARM_FT_ISR: | |
7263 | asm_fprintf (f, "\t%@ Interrupt Service Routine.\n"); | |
7264 | break; | |
7265 | case ARM_FT_FIQ: | |
7266 | asm_fprintf (f, "\t%@ Fast Interrupt Service Routine.\n"); | |
7267 | break; | |
7268 | case ARM_FT_EXCEPTION: | |
7269 | asm_fprintf (f, "\t%@ ARM Exception Handler.\n"); | |
7270 | break; | |
7271 | } | |
ff9940b0 | 7272 | |
6d3d9133 NC |
7273 | if (IS_NAKED (func_type)) |
7274 | asm_fprintf (f, "\t%@ Naked Function: prologue and epilogue provided by programmer.\n"); | |
7275 | ||
7276 | if (IS_VOLATILE (func_type)) | |
7277 | asm_fprintf (f, "\t%@ Volatile: function does not return.\n"); | |
7278 | ||
7279 | if (IS_NESTED (func_type)) | |
7280 | asm_fprintf (f, "\t%@ Nested: function declared inside another function.\n"); | |
7281 | ||
dd18ae56 NC |
7282 | asm_fprintf (f, "\t%@ args = %d, pretend = %d, frame = %d\n", |
7283 | current_function_args_size, | |
7284 | current_function_pretend_args_size, frame_size); | |
6d3d9133 | 7285 | |
dd18ae56 NC |
7286 | asm_fprintf (f, "\t%@ frame_needed = %d, current_function_anonymous_args = %d\n", |
7287 | frame_pointer_needed, | |
7288 | current_function_anonymous_args); | |
cce8749e | 7289 | |
6f7ebcbb NC |
7290 | if (cfun->machine->lr_save_eliminated) |
7291 | asm_fprintf (f, "\t%@ link register save eliminated.\n"); | |
7292 | ||
32de079a RE |
7293 | #ifdef AOF_ASSEMBLER |
7294 | if (flag_pic) | |
dd18ae56 | 7295 | asm_fprintf (f, "\tmov\t%r, %r\n", IP_REGNUM, PIC_OFFSET_TABLE_REGNUM); |
32de079a | 7296 | #endif |
6d3d9133 NC |
7297 | |
7298 | return_used_this_function = 0; | |
f3bb6135 | 7299 | } |
cce8749e | 7300 | |
cd2b33d0 | 7301 | const char * |
0616531f RE |
7302 | arm_output_epilogue (really_return) |
7303 | int really_return; | |
cce8749e | 7304 | { |
949d79eb | 7305 | int reg; |
6f7ebcbb | 7306 | unsigned long saved_regs_mask; |
6d3d9133 | 7307 | unsigned long func_type; |
6354dc9b | 7308 | /* If we need this, then it will always be at least this much. */ |
b111229a | 7309 | int floats_offset = 12; |
cce8749e | 7310 | rtx operands[3]; |
949d79eb | 7311 | int frame_size = get_frame_size (); |
d5b7b3ae | 7312 | FILE * f = asm_out_file; |
6d3d9133 | 7313 | rtx eh_ofs = cfun->machine->eh_epilogue_sp_ofs; |
cce8749e | 7314 | |
6d3d9133 NC |
7315 | /* If we have already generated the return instruction |
7316 | then it is futile to generate anything else. */ | |
b36ba79f | 7317 | if (use_return_insn (FALSE) && return_used_this_function) |
949d79eb | 7318 | return ""; |
cce8749e | 7319 | |
6d3d9133 | 7320 | func_type = arm_current_func_type (); |
d5b7b3ae | 7321 | |
6d3d9133 NC |
7322 | if (IS_NAKED (func_type)) |
7323 | /* Naked functions don't have epilogues. */ | |
7324 | return ""; | |
0616531f | 7325 | |
6d3d9133 | 7326 | if (IS_VOLATILE (func_type) && TARGET_ABORT_NORETURN) |
e2c671ba | 7327 | { |
86efdc8e | 7328 | rtx op; |
6d3d9133 NC |
7329 | |
7330 | /* A volatile function should never return. Call abort. */ | |
ed0e6530 | 7331 | op = gen_rtx_SYMBOL_REF (Pmode, NEED_PLT_RELOC ? "abort(PLT)" : "abort"); |
2b835d68 | 7332 | assemble_external_libcall (op); |
e2c671ba | 7333 | output_asm_insn ("bl\t%a0", &op); |
6d3d9133 | 7334 | |
949d79eb | 7335 | return ""; |
e2c671ba RE |
7336 | } |
7337 | ||
6d3d9133 NC |
7338 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_EXCEPTION_HANDLER |
7339 | && ! really_return) | |
7340 | /* If we are throwing an exception, then we really must | |
7341 | be doing a return, so we can't tail-call. */ | |
7342 | abort (); | |
7343 | ||
6f7ebcbb | 7344 | saved_regs_mask = arm_compute_save_reg_mask (); |
6d3d9133 NC |
7345 | |
7346 | /* Compute how far away the floats will be. */ | |
7347 | for (reg = 0; reg <= LAST_ARM_REGNUM; reg ++) | |
6f7ebcbb | 7348 | if (saved_regs_mask & (1 << reg)) |
6ed30148 | 7349 | floats_offset += 4; |
6d3d9133 | 7350 | |
ff9940b0 | 7351 | if (frame_pointer_needed) |
cce8749e | 7352 | { |
b111229a RE |
7353 | if (arm_fpu_arch == FP_SOFT2) |
7354 | { | |
d5b7b3ae | 7355 | for (reg = LAST_ARM_FP_REGNUM; reg >= FIRST_ARM_FP_REGNUM; reg--) |
5895f793 | 7356 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
b111229a RE |
7357 | { |
7358 | floats_offset += 12; | |
dd18ae56 NC |
7359 | asm_fprintf (f, "\tldfe\t%r, [%r, #-%d]\n", |
7360 | reg, FP_REGNUM, floats_offset); | |
b111229a RE |
7361 | } |
7362 | } | |
7363 | else | |
7364 | { | |
d5b7b3ae | 7365 | int start_reg = LAST_ARM_FP_REGNUM; |
b111229a | 7366 | |
d5b7b3ae | 7367 | for (reg = LAST_ARM_FP_REGNUM; reg >= FIRST_ARM_FP_REGNUM; reg--) |
b111229a | 7368 | { |
5895f793 | 7369 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
b111229a RE |
7370 | { |
7371 | floats_offset += 12; | |
6cfc7210 | 7372 | |
6354dc9b | 7373 | /* We can't unstack more than four registers at once. */ |
b111229a RE |
7374 | if (start_reg - reg == 3) |
7375 | { | |
dd18ae56 NC |
7376 | asm_fprintf (f, "\tlfm\t%r, 4, [%r, #-%d]\n", |
7377 | reg, FP_REGNUM, floats_offset); | |
b111229a RE |
7378 | start_reg = reg - 1; |
7379 | } | |
7380 | } | |
7381 | else | |
7382 | { | |
7383 | if (reg != start_reg) | |
dd18ae56 NC |
7384 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
7385 | reg + 1, start_reg - reg, | |
7386 | FP_REGNUM, floats_offset); | |
b111229a RE |
7387 | start_reg = reg - 1; |
7388 | } | |
7389 | } | |
7390 | ||
7391 | /* Just in case the last register checked also needs unstacking. */ | |
7392 | if (reg != start_reg) | |
dd18ae56 NC |
7393 | asm_fprintf (f, "\tlfm\t%r, %d, [%r, #-%d]\n", |
7394 | reg + 1, start_reg - reg, | |
7395 | FP_REGNUM, floats_offset); | |
b111229a | 7396 | } |
6d3d9133 | 7397 | |
6f7ebcbb | 7398 | /* saved_regs_mask should contain the IP, which at the time of stack |
6d3d9133 NC |
7399 | frame generation actually contains the old stack pointer. So a |
7400 | quick way to unwind the stack is just pop the IP register directly | |
7401 | into the stack pointer. */ | |
6f7ebcbb | 7402 | if ((saved_regs_mask & (1 << IP_REGNUM)) == 0) |
6d3d9133 | 7403 | abort (); |
6f7ebcbb NC |
7404 | saved_regs_mask &= ~ (1 << IP_REGNUM); |
7405 | saved_regs_mask |= (1 << SP_REGNUM); | |
6d3d9133 | 7406 | |
6f7ebcbb | 7407 | /* There are two registers left in saved_regs_mask - LR and PC. We |
6d3d9133 NC |
7408 | only need to restore the LR register (the return address), but to |
7409 | save time we can load it directly into the PC, unless we need a | |
7410 | special function exit sequence, or we are not really returning. */ | |
7411 | if (really_return && ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL) | |
7412 | /* Delete the LR from the register mask, so that the LR on | |
7413 | the stack is loaded into the PC in the register mask. */ | |
6f7ebcbb | 7414 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
b111229a | 7415 | else |
6f7ebcbb | 7416 | saved_regs_mask &= ~ (1 << PC_REGNUM); |
6d3d9133 | 7417 | |
6f7ebcbb | 7418 | print_multi_reg (f, "ldmea\t%r", FP_REGNUM, saved_regs_mask); |
cce8749e CH |
7419 | } |
7420 | else | |
7421 | { | |
d2288d8d | 7422 | /* Restore stack pointer if necessary. */ |
56636818 | 7423 | if (frame_size + current_function_outgoing_args_size != 0) |
d2288d8d TG |
7424 | { |
7425 | operands[0] = operands[1] = stack_pointer_rtx; | |
56636818 JL |
7426 | operands[2] = GEN_INT (frame_size |
7427 | + current_function_outgoing_args_size); | |
d2288d8d TG |
7428 | output_add_immediate (operands); |
7429 | } | |
7430 | ||
b111229a RE |
7431 | if (arm_fpu_arch == FP_SOFT2) |
7432 | { | |
d5b7b3ae | 7433 | for (reg = FIRST_ARM_FP_REGNUM; reg <= LAST_ARM_FP_REGNUM; reg++) |
5895f793 | 7434 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
dd18ae56 NC |
7435 | asm_fprintf (f, "\tldfe\t%r, [%r], #12\n", |
7436 | reg, SP_REGNUM); | |
b111229a RE |
7437 | } |
7438 | else | |
7439 | { | |
d5b7b3ae | 7440 | int start_reg = FIRST_ARM_FP_REGNUM; |
b111229a | 7441 | |
d5b7b3ae | 7442 | for (reg = FIRST_ARM_FP_REGNUM; reg <= LAST_ARM_FP_REGNUM; reg++) |
b111229a | 7443 | { |
5895f793 | 7444 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
b111229a RE |
7445 | { |
7446 | if (reg - start_reg == 3) | |
7447 | { | |
dd18ae56 NC |
7448 | asm_fprintf (f, "\tlfmfd\t%r, 4, [%r]!\n", |
7449 | start_reg, SP_REGNUM); | |
b111229a RE |
7450 | start_reg = reg + 1; |
7451 | } | |
7452 | } | |
7453 | else | |
7454 | { | |
7455 | if (reg != start_reg) | |
dd18ae56 NC |
7456 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
7457 | start_reg, reg - start_reg, | |
7458 | SP_REGNUM); | |
6cfc7210 | 7459 | |
b111229a RE |
7460 | start_reg = reg + 1; |
7461 | } | |
7462 | } | |
7463 | ||
7464 | /* Just in case the last register checked also needs unstacking. */ | |
7465 | if (reg != start_reg) | |
dd18ae56 NC |
7466 | asm_fprintf (f, "\tlfmfd\t%r, %d, [%r]!\n", |
7467 | start_reg, reg - start_reg, SP_REGNUM); | |
b111229a RE |
7468 | } |
7469 | ||
6d3d9133 NC |
7470 | /* If we can, restore the LR into the PC. */ |
7471 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_NORMAL | |
7472 | && really_return | |
7473 | && current_function_pretend_args_size == 0 | |
6f7ebcbb | 7474 | && saved_regs_mask & (1 << LR_REGNUM)) |
cce8749e | 7475 | { |
6f7ebcbb NC |
7476 | saved_regs_mask &= ~ (1 << LR_REGNUM); |
7477 | saved_regs_mask |= (1 << PC_REGNUM); | |
6d3d9133 | 7478 | } |
d5b7b3ae | 7479 | |
6d3d9133 NC |
7480 | /* Load the registers off the stack. If we only have one register |
7481 | to load use the LDR instruction - it is faster. */ | |
6f7ebcbb | 7482 | if (saved_regs_mask == (1 << LR_REGNUM)) |
6d3d9133 NC |
7483 | { |
7484 | /* The excpetion handler ignores the LR, so we do | |
7485 | not really need to load it off the stack. */ | |
7486 | if (eh_ofs) | |
7487 | asm_fprintf (f, "\tadd\t%r, %r, #4\n", SP_REGNUM, SP_REGNUM); | |
32de079a | 7488 | else |
6d3d9133 | 7489 | asm_fprintf (f, "\tldr\t%r, [%r], #4\n", LR_REGNUM, SP_REGNUM); |
cce8749e | 7490 | } |
6f7ebcbb NC |
7491 | else if (saved_regs_mask) |
7492 | print_multi_reg (f, "ldmfd\t%r!", SP_REGNUM, saved_regs_mask); | |
6d3d9133 NC |
7493 | |
7494 | if (current_function_pretend_args_size) | |
cce8749e | 7495 | { |
6d3d9133 NC |
7496 | /* Unwind the pre-pushed regs. */ |
7497 | operands[0] = operands[1] = stack_pointer_rtx; | |
7498 | operands[2] = GEN_INT (current_function_pretend_args_size); | |
7499 | output_add_immediate (operands); | |
7500 | } | |
7501 | } | |
32de079a | 7502 | |
9b598fa0 | 7503 | #if 0 |
6d3d9133 NC |
7504 | if (ARM_FUNC_TYPE (func_type) == ARM_FT_EXCEPTION_HANDLER) |
7505 | /* Adjust the stack to remove the exception handler stuff. */ | |
7506 | asm_fprintf (f, "\tadd\t%r, %r, %r\n", SP_REGNUM, SP_REGNUM, | |
7507 | REGNO (eh_ofs)); | |
9b598fa0 | 7508 | #endif |
b111229a | 7509 | |
6d3d9133 NC |
7510 | if (! really_return) |
7511 | return ""; | |
d5b7b3ae | 7512 | |
6d3d9133 NC |
7513 | /* Generate the return instruction. */ |
7514 | switch ((int) ARM_FUNC_TYPE (func_type)) | |
7515 | { | |
7516 | case ARM_FT_EXCEPTION_HANDLER: | |
7517 | /* Even in 26-bit mode we do a mov (rather than a movs) | |
7518 | because we don't have the PSR bits set in the address. */ | |
7519 | asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, EXCEPTION_LR_REGNUM); | |
7520 | break; | |
0616531f | 7521 | |
6d3d9133 NC |
7522 | case ARM_FT_ISR: |
7523 | case ARM_FT_FIQ: | |
7524 | asm_fprintf (f, "\tsubs\t%r, %r, #4\n", PC_REGNUM, LR_REGNUM); | |
7525 | break; | |
7526 | ||
7527 | case ARM_FT_EXCEPTION: | |
7528 | asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
7529 | break; | |
7530 | ||
7531 | case ARM_FT_INTERWORKED: | |
7532 | asm_fprintf (f, "\tbx\t%r\n", LR_REGNUM); | |
7533 | break; | |
7534 | ||
7535 | default: | |
7536 | if (frame_pointer_needed) | |
7537 | /* If we used the frame pointer then the return adddress | |
7538 | will have been loaded off the stack directly into the | |
7539 | PC, so there is no need to issue a MOV instruction | |
7540 | here. */ | |
7541 | ; | |
7542 | else if (current_function_pretend_args_size == 0 | |
6f7ebcbb | 7543 | && (saved_regs_mask & (1 << LR_REGNUM))) |
6d3d9133 NC |
7544 | /* Similarly we may have been able to load LR into the PC |
7545 | even if we did not create a stack frame. */ | |
7546 | ; | |
7547 | else if (TARGET_APCS_32) | |
7548 | asm_fprintf (f, "\tmov\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
7549 | else | |
7550 | asm_fprintf (f, "\tmovs\t%r, %r\n", PC_REGNUM, LR_REGNUM); | |
7551 | break; | |
cce8749e | 7552 | } |
f3bb6135 | 7553 | |
949d79eb RE |
7554 | return ""; |
7555 | } | |
7556 | ||
7557 | void | |
eb3921e8 | 7558 | output_func_epilogue (frame_size) |
949d79eb RE |
7559 | int frame_size; |
7560 | { | |
d5b7b3ae RE |
7561 | if (TARGET_THUMB) |
7562 | { | |
7563 | /* ??? Probably not safe to set this here, since it assumes that a | |
7564 | function will be emitted as assembly immediately after we generate | |
7565 | RTL for it. This does not happen for inline functions. */ | |
7566 | return_used_this_function = 0; | |
7567 | } | |
7568 | else | |
7569 | { | |
7570 | if (use_return_insn (FALSE) | |
7571 | && return_used_this_function | |
7572 | && (frame_size + current_function_outgoing_args_size) != 0 | |
5895f793 | 7573 | && !frame_pointer_needed) |
d5b7b3ae | 7574 | abort (); |
f3bb6135 | 7575 | |
d5b7b3ae RE |
7576 | /* Reset the ARM-specific per-function variables. */ |
7577 | current_function_anonymous_args = 0; | |
7578 | after_arm_reorg = 0; | |
7579 | } | |
f3bb6135 | 7580 | } |
e2c671ba | 7581 | |
2c849145 JM |
7582 | /* Generate and emit an insn that we will recognize as a push_multi. |
7583 | Unfortunately, since this insn does not reflect very well the actual | |
7584 | semantics of the operation, we need to annotate the insn for the benefit | |
7585 | of DWARF2 frame unwind information. */ | |
6d3d9133 | 7586 | |
2c849145 | 7587 | static rtx |
e2c671ba RE |
7588 | emit_multi_reg_push (mask) |
7589 | int mask; | |
7590 | { | |
7591 | int num_regs = 0; | |
9b598fa0 | 7592 | int num_dwarf_regs; |
e2c671ba RE |
7593 | int i, j; |
7594 | rtx par; | |
2c849145 | 7595 | rtx dwarf; |
87e27392 | 7596 | int dwarf_par_index; |
2c849145 | 7597 | rtx tmp, reg; |
e2c671ba | 7598 | |
d5b7b3ae | 7599 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba | 7600 | if (mask & (1 << i)) |
5895f793 | 7601 | num_regs++; |
e2c671ba RE |
7602 | |
7603 | if (num_regs == 0 || num_regs > 16) | |
7604 | abort (); | |
7605 | ||
9b598fa0 RE |
7606 | /* We don't record the PC in the dwarf frame information. */ |
7607 | num_dwarf_regs = num_regs; | |
7608 | if (mask & (1 << PC_REGNUM)) | |
7609 | num_dwarf_regs--; | |
7610 | ||
87e27392 NC |
7611 | /* For the body of the insn we are going to generate an UNSPEC in |
7612 | parallel with several USEs. This allows the insn to be recognised | |
7613 | by the push_multi pattern in the arm.md file. The insn looks | |
7614 | something like this: | |
7615 | ||
7616 | (parallel [ | |
b15bca31 RE |
7617 | (set (mem:BLK (pre_dec:BLK (reg:SI sp))) |
7618 | (unspec:BLK [(reg:SI r4)] UNSPEC_PUSH_MULT)) | |
87e27392 NC |
7619 | (use (reg:SI 11 fp)) |
7620 | (use (reg:SI 12 ip)) | |
7621 | (use (reg:SI 14 lr)) | |
7622 | (use (reg:SI 15 pc)) | |
7623 | ]) | |
7624 | ||
7625 | For the frame note however, we try to be more explicit and actually | |
7626 | show each register being stored into the stack frame, plus a (single) | |
7627 | decrement of the stack pointer. We do it this way in order to be | |
7628 | friendly to the stack unwinding code, which only wants to see a single | |
7629 | stack decrement per instruction. The RTL we generate for the note looks | |
7630 | something like this: | |
7631 | ||
7632 | (sequence [ | |
7633 | (set (reg:SI sp) (plus:SI (reg:SI sp) (const_int -20))) | |
7634 | (set (mem:SI (reg:SI sp)) (reg:SI r4)) | |
7635 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 4))) (reg:SI fp)) | |
7636 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 8))) (reg:SI ip)) | |
7637 | (set (mem:SI (plus:SI (reg:SI sp) (const_int 12))) (reg:SI lr)) | |
87e27392 NC |
7638 | ]) |
7639 | ||
7640 | This sequence is used both by the code to support stack unwinding for | |
7641 | exceptions handlers and the code to generate dwarf2 frame debugging. */ | |
7642 | ||
43cffd11 | 7643 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (num_regs)); |
9b598fa0 | 7644 | dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (num_dwarf_regs + 1)); |
2c849145 | 7645 | RTX_FRAME_RELATED_P (dwarf) = 1; |
87e27392 | 7646 | dwarf_par_index = 1; |
e2c671ba | 7647 | |
d5b7b3ae | 7648 | for (i = 0; i <= LAST_ARM_REGNUM; i++) |
e2c671ba RE |
7649 | { |
7650 | if (mask & (1 << i)) | |
7651 | { | |
2c849145 JM |
7652 | reg = gen_rtx_REG (SImode, i); |
7653 | ||
e2c671ba | 7654 | XVECEXP (par, 0, 0) |
43cffd11 RE |
7655 | = gen_rtx_SET (VOIDmode, |
7656 | gen_rtx_MEM (BLKmode, | |
7657 | gen_rtx_PRE_DEC (BLKmode, | |
7658 | stack_pointer_rtx)), | |
7659 | gen_rtx_UNSPEC (BLKmode, | |
2c849145 | 7660 | gen_rtvec (1, reg), |
9b598fa0 | 7661 | UNSPEC_PUSH_MULT)); |
2c849145 | 7662 | |
9b598fa0 RE |
7663 | if (i != PC_REGNUM) |
7664 | { | |
7665 | tmp = gen_rtx_SET (VOIDmode, | |
7666 | gen_rtx_MEM (SImode, stack_pointer_rtx), | |
7667 | reg); | |
7668 | RTX_FRAME_RELATED_P (tmp) = 1; | |
7669 | XVECEXP (dwarf, 0, dwarf_par_index) = tmp; | |
7670 | dwarf_par_index++; | |
7671 | } | |
2c849145 | 7672 | |
e2c671ba RE |
7673 | break; |
7674 | } | |
7675 | } | |
7676 | ||
7677 | for (j = 1, i++; j < num_regs; i++) | |
7678 | { | |
7679 | if (mask & (1 << i)) | |
7680 | { | |
2c849145 JM |
7681 | reg = gen_rtx_REG (SImode, i); |
7682 | ||
7683 | XVECEXP (par, 0, j) = gen_rtx_USE (VOIDmode, reg); | |
7684 | ||
9b598fa0 RE |
7685 | if (i != PC_REGNUM) |
7686 | { | |
7687 | tmp = gen_rtx_SET (VOIDmode, | |
7688 | gen_rtx_MEM (SImode, | |
7689 | plus_constant (stack_pointer_rtx, | |
7690 | 4 * j)), | |
7691 | reg); | |
7692 | RTX_FRAME_RELATED_P (tmp) = 1; | |
7693 | XVECEXP (dwarf, 0, dwarf_par_index++) = tmp; | |
7694 | } | |
7695 | ||
e2c671ba RE |
7696 | j++; |
7697 | } | |
7698 | } | |
b111229a | 7699 | |
2c849145 | 7700 | par = emit_insn (par); |
87e27392 NC |
7701 | |
7702 | tmp = gen_rtx_SET (SImode, | |
7703 | stack_pointer_rtx, | |
7704 | gen_rtx_PLUS (SImode, | |
7705 | stack_pointer_rtx, | |
7706 | GEN_INT (-4 * num_regs))); | |
7707 | RTX_FRAME_RELATED_P (tmp) = 1; | |
7708 | XVECEXP (dwarf, 0, 0) = tmp; | |
7709 | ||
2c849145 JM |
7710 | REG_NOTES (par) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf, |
7711 | REG_NOTES (par)); | |
7712 | return par; | |
b111229a RE |
7713 | } |
7714 | ||
2c849145 | 7715 | static rtx |
b111229a RE |
7716 | emit_sfm (base_reg, count) |
7717 | int base_reg; | |
7718 | int count; | |
7719 | { | |
7720 | rtx par; | |
2c849145 JM |
7721 | rtx dwarf; |
7722 | rtx tmp, reg; | |
b111229a RE |
7723 | int i; |
7724 | ||
43cffd11 | 7725 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
2c849145 JM |
7726 | dwarf = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
7727 | RTX_FRAME_RELATED_P (dwarf) = 1; | |
7728 | ||
7729 | reg = gen_rtx_REG (XFmode, base_reg++); | |
43cffd11 RE |
7730 | |
7731 | XVECEXP (par, 0, 0) | |
7732 | = gen_rtx_SET (VOIDmode, | |
7733 | gen_rtx_MEM (BLKmode, | |
7734 | gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)), | |
7735 | gen_rtx_UNSPEC (BLKmode, | |
2c849145 | 7736 | gen_rtvec (1, reg), |
b15bca31 | 7737 | UNSPEC_PUSH_MULT)); |
2c849145 JM |
7738 | tmp |
7739 | = gen_rtx_SET (VOIDmode, | |
7740 | gen_rtx_MEM (XFmode, | |
7741 | gen_rtx_PRE_DEC (BLKmode, stack_pointer_rtx)), | |
7742 | reg); | |
7743 | RTX_FRAME_RELATED_P (tmp) = 1; | |
7744 | XVECEXP (dwarf, 0, count - 1) = tmp; | |
7745 | ||
b111229a | 7746 | for (i = 1; i < count; i++) |
2c849145 JM |
7747 | { |
7748 | reg = gen_rtx_REG (XFmode, base_reg++); | |
7749 | XVECEXP (par, 0, i) = gen_rtx_USE (VOIDmode, reg); | |
7750 | ||
7751 | tmp = gen_rtx_SET (VOIDmode, | |
7752 | gen_rtx_MEM (XFmode, | |
7753 | gen_rtx_PRE_DEC (BLKmode, | |
7754 | stack_pointer_rtx)), | |
7755 | reg); | |
7756 | RTX_FRAME_RELATED_P (tmp) = 1; | |
7757 | XVECEXP (dwarf, 0, count - i - 1) = tmp; | |
7758 | } | |
b111229a | 7759 | |
2c849145 JM |
7760 | par = emit_insn (par); |
7761 | REG_NOTES (par) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, dwarf, | |
7762 | REG_NOTES (par)); | |
7763 | return par; | |
e2c671ba RE |
7764 | } |
7765 | ||
6d3d9133 NC |
7766 | /* Generate the prologue instructions for entry into an ARM function. */ |
7767 | ||
e2c671ba RE |
7768 | void |
7769 | arm_expand_prologue () | |
7770 | { | |
7771 | int reg; | |
6d3d9133 | 7772 | rtx amount; |
2c849145 | 7773 | rtx insn; |
68dfd979 | 7774 | rtx ip_rtx; |
6d3d9133 NC |
7775 | unsigned long live_regs_mask; |
7776 | unsigned long func_type; | |
68dfd979 | 7777 | int fp_offset = 0; |
d3236b4d | 7778 | |
6d3d9133 | 7779 | func_type = arm_current_func_type (); |
e2c671ba | 7780 | |
31fdb4d5 | 7781 | /* Naked functions don't have prologues. */ |
6d3d9133 | 7782 | if (IS_NAKED (func_type)) |
31fdb4d5 DE |
7783 | return; |
7784 | ||
6d3d9133 NC |
7785 | /* Compute which register we will have to save onto the stack. */ |
7786 | live_regs_mask = arm_compute_save_reg_mask (); | |
e2c671ba | 7787 | |
68dfd979 | 7788 | ip_rtx = gen_rtx_REG (SImode, IP_REGNUM); |
d3236b4d | 7789 | |
e2c671ba RE |
7790 | if (frame_pointer_needed) |
7791 | { | |
6d3d9133 | 7792 | if (IS_NESTED (func_type)) |
68dfd979 NC |
7793 | { |
7794 | /* The Static chain register is the same as the IP register | |
7795 | used as a scratch register during stack frame creation. | |
7796 | To get around this need to find somewhere to store IP | |
7797 | whilst the frame is being created. We try the following | |
7798 | places in order: | |
7799 | ||
6d3d9133 | 7800 | 1. The last argument register. |
68dfd979 NC |
7801 | 2. A slot on the stack above the frame. (This only |
7802 | works if the function is not a varargs function). | |
7803 | ||
6d3d9133 NC |
7804 | If neither of these places is available, we abort (for now). |
7805 | ||
34ce3d7b JM |
7806 | Note - we only need to tell the dwarf2 backend about the SP |
7807 | adjustment in the second variant; the static chain register | |
7808 | doesn't need to be unwound, as it doesn't contain a value | |
7809 | inherited from the caller. */ | |
d3236b4d | 7810 | |
68dfd979 NC |
7811 | if (regs_ever_live[3] == 0) |
7812 | { | |
7813 | insn = gen_rtx_REG (SImode, 3); | |
7814 | insn = gen_rtx_SET (SImode, insn, ip_rtx); | |
d3236b4d | 7815 | insn = emit_insn (insn); |
68dfd979 NC |
7816 | } |
7817 | else if (current_function_pretend_args_size == 0) | |
7818 | { | |
34ce3d7b | 7819 | rtx dwarf; |
68dfd979 NC |
7820 | insn = gen_rtx_PRE_DEC (SImode, stack_pointer_rtx); |
7821 | insn = gen_rtx_MEM (SImode, insn); | |
7822 | insn = gen_rtx_SET (VOIDmode, insn, ip_rtx); | |
7823 | insn = emit_insn (insn); | |
34ce3d7b | 7824 | |
68dfd979 | 7825 | fp_offset = 4; |
34ce3d7b JM |
7826 | |
7827 | /* Just tell the dwarf backend that we adjusted SP. */ | |
7828 | dwarf = gen_rtx_SET (VOIDmode, stack_pointer_rtx, | |
7829 | gen_rtx_PLUS (SImode, stack_pointer_rtx, | |
7830 | GEN_INT (-fp_offset))); | |
7831 | RTX_FRAME_RELATED_P (insn) = 1; | |
7832 | REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
7833 | dwarf, REG_NOTES (insn)); | |
68dfd979 NC |
7834 | } |
7835 | else | |
7836 | /* FIXME - the way to handle this situation is to allow | |
7837 | the pretend args to be dumped onto the stack, then | |
7838 | reuse r3 to save IP. This would involve moving the | |
f18969c0 | 7839 | copying of SP into IP until after the pretend args |
68dfd979 | 7840 | have been dumped, but this is not too hard. */ |
f18969c0 PB |
7841 | /* [See e.g. gcc.c-torture/execute/nest-stdar-1.c.] */ |
7842 | error ("Unable to find a temporary location for static chain register"); | |
68dfd979 NC |
7843 | } |
7844 | ||
68dfd979 NC |
7845 | if (fp_offset) |
7846 | { | |
7847 | insn = gen_rtx_PLUS (SImode, stack_pointer_rtx, GEN_INT (fp_offset)); | |
7848 | insn = gen_rtx_SET (SImode, ip_rtx, insn); | |
7849 | } | |
7850 | else | |
7851 | insn = gen_movsi (ip_rtx, stack_pointer_rtx); | |
7852 | ||
6d3d9133 | 7853 | insn = emit_insn (insn); |
8e56560e | 7854 | RTX_FRAME_RELATED_P (insn) = 1; |
e2c671ba RE |
7855 | } |
7856 | ||
7857 | if (current_function_pretend_args_size) | |
7858 | { | |
6d3d9133 NC |
7859 | /* Push the argument registers, or reserve space for them. */ |
7860 | if (current_function_anonymous_args) | |
2c849145 JM |
7861 | insn = emit_multi_reg_push |
7862 | ((0xf0 >> (current_function_pretend_args_size / 4)) & 0xf); | |
e2c671ba | 7863 | else |
2c849145 JM |
7864 | insn = emit_insn |
7865 | (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
7866 | GEN_INT (-current_function_pretend_args_size))); | |
7867 | RTX_FRAME_RELATED_P (insn) = 1; | |
e2c671ba RE |
7868 | } |
7869 | ||
7870 | if (live_regs_mask) | |
7871 | { | |
2c849145 JM |
7872 | insn = emit_multi_reg_push (live_regs_mask); |
7873 | RTX_FRAME_RELATED_P (insn) = 1; | |
e2c671ba | 7874 | } |
d5b7b3ae | 7875 | |
6d3d9133 | 7876 | if (! IS_VOLATILE (func_type)) |
b111229a | 7877 | { |
6d3d9133 | 7878 | /* Save any floating point call-saved registers used by this function. */ |
b111229a RE |
7879 | if (arm_fpu_arch == FP_SOFT2) |
7880 | { | |
d5b7b3ae | 7881 | for (reg = LAST_ARM_FP_REGNUM; reg >= FIRST_ARM_FP_REGNUM; reg --) |
5895f793 | 7882 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
2c849145 JM |
7883 | { |
7884 | insn = gen_rtx_PRE_DEC (XFmode, stack_pointer_rtx); | |
7885 | insn = gen_rtx_MEM (XFmode, insn); | |
7886 | insn = emit_insn (gen_rtx_SET (VOIDmode, insn, | |
7887 | gen_rtx_REG (XFmode, reg))); | |
7888 | RTX_FRAME_RELATED_P (insn) = 1; | |
7889 | } | |
b111229a RE |
7890 | } |
7891 | else | |
7892 | { | |
d5b7b3ae | 7893 | int start_reg = LAST_ARM_FP_REGNUM; |
b111229a | 7894 | |
d5b7b3ae | 7895 | for (reg = LAST_ARM_FP_REGNUM; reg >= FIRST_ARM_FP_REGNUM; reg --) |
b111229a | 7896 | { |
5895f793 | 7897 | if (regs_ever_live[reg] && !call_used_regs[reg]) |
b111229a RE |
7898 | { |
7899 | if (start_reg - reg == 3) | |
7900 | { | |
2c849145 JM |
7901 | insn = emit_sfm (reg, 4); |
7902 | RTX_FRAME_RELATED_P (insn) = 1; | |
b111229a RE |
7903 | start_reg = reg - 1; |
7904 | } | |
7905 | } | |
7906 | else | |
7907 | { | |
7908 | if (start_reg != reg) | |
2c849145 JM |
7909 | { |
7910 | insn = emit_sfm (reg + 1, start_reg - reg); | |
7911 | RTX_FRAME_RELATED_P (insn) = 1; | |
7912 | } | |
b111229a RE |
7913 | start_reg = reg - 1; |
7914 | } | |
7915 | } | |
7916 | ||
7917 | if (start_reg != reg) | |
2c849145 JM |
7918 | { |
7919 | insn = emit_sfm (reg + 1, start_reg - reg); | |
7920 | RTX_FRAME_RELATED_P (insn) = 1; | |
7921 | } | |
b111229a RE |
7922 | } |
7923 | } | |
e2c671ba RE |
7924 | |
7925 | if (frame_pointer_needed) | |
2c849145 | 7926 | { |
6d3d9133 | 7927 | /* Create the new frame pointer. */ |
68dfd979 NC |
7928 | insn = GEN_INT (-(4 + current_function_pretend_args_size + fp_offset)); |
7929 | insn = emit_insn (gen_addsi3 (hard_frame_pointer_rtx, ip_rtx, insn)); | |
2c849145 | 7930 | RTX_FRAME_RELATED_P (insn) = 1; |
68dfd979 | 7931 | |
6d3d9133 | 7932 | if (IS_NESTED (func_type)) |
68dfd979 NC |
7933 | { |
7934 | /* Recover the static chain register. */ | |
7935 | if (regs_ever_live [3] == 0) | |
7936 | { | |
7937 | insn = gen_rtx_REG (SImode, 3); | |
7938 | insn = gen_rtx_SET (SImode, ip_rtx, insn); | |
7939 | insn = emit_insn (insn); | |
68dfd979 NC |
7940 | } |
7941 | else /* if (current_function_pretend_args_size == 0) */ | |
7942 | { | |
7943 | insn = gen_rtx_PLUS (SImode, hard_frame_pointer_rtx, GEN_INT (4)); | |
7944 | insn = gen_rtx_MEM (SImode, insn); | |
7945 | insn = gen_rtx_SET (SImode, ip_rtx, insn); | |
7946 | insn = emit_insn (insn); | |
68dfd979 NC |
7947 | } |
7948 | } | |
2c849145 | 7949 | } |
e2c671ba | 7950 | |
6d3d9133 NC |
7951 | amount = GEN_INT (-(get_frame_size () |
7952 | + current_function_outgoing_args_size)); | |
7953 | ||
e2c671ba RE |
7954 | if (amount != const0_rtx) |
7955 | { | |
745b9093 JM |
7956 | /* This add can produce multiple insns for a large constant, so we |
7957 | need to get tricky. */ | |
7958 | rtx last = get_last_insn (); | |
2c849145 JM |
7959 | insn = emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
7960 | amount)); | |
745b9093 JM |
7961 | do |
7962 | { | |
7963 | last = last ? NEXT_INSN (last) : get_insns (); | |
7964 | RTX_FRAME_RELATED_P (last) = 1; | |
7965 | } | |
7966 | while (last != insn); | |
e04c2d6c RE |
7967 | |
7968 | /* If the frame pointer is needed, emit a special barrier that | |
7969 | will prevent the scheduler from moving stores to the frame | |
7970 | before the stack adjustment. */ | |
7971 | if (frame_pointer_needed) | |
7972 | { | |
7973 | rtx unspec = gen_rtx_UNSPEC (SImode, | |
7974 | gen_rtvec (2, stack_pointer_rtx, | |
b15bca31 RE |
7975 | hard_frame_pointer_rtx), |
7976 | UNSPEC_PRLG_STK); | |
e04c2d6c | 7977 | |
6d3d9133 | 7978 | insn = emit_insn (gen_rtx_CLOBBER (VOIDmode, |
e04c2d6c RE |
7979 | gen_rtx_MEM (BLKmode, unspec))); |
7980 | } | |
e2c671ba RE |
7981 | } |
7982 | ||
7983 | /* If we are profiling, make sure no instructions are scheduled before | |
f5a1b0d2 NC |
7984 | the call to mcount. Similarly if the user has requested no |
7985 | scheduling in the prolog. */ | |
7986 | if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO) | |
e2c671ba | 7987 | emit_insn (gen_blockage ()); |
6f7ebcbb NC |
7988 | |
7989 | /* If the link register is being kept alive, with the return address in it, | |
7990 | then make sure that it does not get reused by the ce2 pass. */ | |
7991 | if ((live_regs_mask & (1 << LR_REGNUM)) == 0) | |
7992 | { | |
7993 | emit_insn (gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, LR_REGNUM))); | |
7994 | cfun->machine->lr_save_eliminated = 1; | |
7995 | } | |
e2c671ba | 7996 | } |
cce8749e | 7997 | \f |
9997d19d RE |
7998 | /* If CODE is 'd', then the X is a condition operand and the instruction |
7999 | should only be executed if the condition is true. | |
ddd5a7c1 | 8000 | if CODE is 'D', then the X is a condition operand and the instruction |
9997d19d RE |
8001 | should only be executed if the condition is false: however, if the mode |
8002 | of the comparison is CCFPEmode, then always execute the instruction -- we | |
8003 | do this because in these circumstances !GE does not necessarily imply LT; | |
8004 | in these cases the instruction pattern will take care to make sure that | |
8005 | an instruction containing %d will follow, thereby undoing the effects of | |
ddd5a7c1 | 8006 | doing this instruction unconditionally. |
9997d19d RE |
8007 | If CODE is 'N' then X is a floating point operand that must be negated |
8008 | before output. | |
8009 | If CODE is 'B' then output a bitwise inverted value of X (a const int). | |
8010 | If X is a REG and CODE is `M', output a ldm/stm style multi-reg. */ | |
8011 | ||
8012 | void | |
8013 | arm_print_operand (stream, x, code) | |
62b10bbc | 8014 | FILE * stream; |
9997d19d RE |
8015 | rtx x; |
8016 | int code; | |
8017 | { | |
8018 | switch (code) | |
8019 | { | |
8020 | case '@': | |
f3139301 | 8021 | fputs (ASM_COMMENT_START, stream); |
9997d19d RE |
8022 | return; |
8023 | ||
d5b7b3ae RE |
8024 | case '_': |
8025 | fputs (user_label_prefix, stream); | |
8026 | return; | |
8027 | ||
9997d19d | 8028 | case '|': |
f3139301 | 8029 | fputs (REGISTER_PREFIX, stream); |
9997d19d RE |
8030 | return; |
8031 | ||
8032 | case '?': | |
8033 | if (arm_ccfsm_state == 3 || arm_ccfsm_state == 4) | |
cca0a211 RE |
8034 | { |
8035 | if (TARGET_THUMB || current_insn_predicate != NULL) | |
8036 | abort (); | |
8037 | ||
8038 | fputs (arm_condition_codes[arm_current_cc], stream); | |
8039 | } | |
8040 | else if (current_insn_predicate) | |
8041 | { | |
8042 | enum arm_cond_code code; | |
8043 | ||
8044 | if (TARGET_THUMB) | |
8045 | abort (); | |
8046 | ||
8047 | code = get_arm_condition_code (current_insn_predicate); | |
8048 | fputs (arm_condition_codes[code], stream); | |
8049 | } | |
9997d19d RE |
8050 | return; |
8051 | ||
8052 | case 'N': | |
8053 | { | |
8054 | REAL_VALUE_TYPE r; | |
8055 | REAL_VALUE_FROM_CONST_DOUBLE (r, x); | |
8056 | r = REAL_VALUE_NEGATE (r); | |
8057 | fprintf (stream, "%s", fp_const_from_val (&r)); | |
8058 | } | |
8059 | return; | |
8060 | ||
8061 | case 'B': | |
8062 | if (GET_CODE (x) == CONST_INT) | |
4bc74ece NC |
8063 | { |
8064 | HOST_WIDE_INT val; | |
5895f793 | 8065 | val = ARM_SIGN_EXTEND (~INTVAL (x)); |
36ba9cb8 | 8066 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val); |
4bc74ece | 8067 | } |
9997d19d RE |
8068 | else |
8069 | { | |
8070 | putc ('~', stream); | |
8071 | output_addr_const (stream, x); | |
8072 | } | |
8073 | return; | |
8074 | ||
8075 | case 'i': | |
8076 | fprintf (stream, "%s", arithmetic_instr (x, 1)); | |
8077 | return; | |
8078 | ||
8079 | case 'I': | |
8080 | fprintf (stream, "%s", arithmetic_instr (x, 0)); | |
8081 | return; | |
8082 | ||
8083 | case 'S': | |
8084 | { | |
8085 | HOST_WIDE_INT val; | |
5895f793 | 8086 | const char * shift = shift_op (x, &val); |
9997d19d | 8087 | |
e2c671ba RE |
8088 | if (shift) |
8089 | { | |
5895f793 | 8090 | fprintf (stream, ", %s ", shift_op (x, &val)); |
e2c671ba RE |
8091 | if (val == -1) |
8092 | arm_print_operand (stream, XEXP (x, 1), 0); | |
8093 | else | |
4bc74ece NC |
8094 | { |
8095 | fputc ('#', stream); | |
36ba9cb8 | 8096 | fprintf (stream, HOST_WIDE_INT_PRINT_DEC, val); |
4bc74ece | 8097 | } |
e2c671ba | 8098 | } |
9997d19d RE |
8099 | } |
8100 | return; | |
8101 | ||
d5b7b3ae RE |
8102 | /* An explanation of the 'Q', 'R' and 'H' register operands: |
8103 | ||
8104 | In a pair of registers containing a DI or DF value the 'Q' | |
8105 | operand returns the register number of the register containing | |
8106 | the least signficant part of the value. The 'R' operand returns | |
8107 | the register number of the register containing the most | |
8108 | significant part of the value. | |
8109 | ||
8110 | The 'H' operand returns the higher of the two register numbers. | |
8111 | On a run where WORDS_BIG_ENDIAN is true the 'H' operand is the | |
8112 | same as the 'Q' operand, since the most signficant part of the | |
8113 | value is held in the lower number register. The reverse is true | |
8114 | on systems where WORDS_BIG_ENDIAN is false. | |
8115 | ||
8116 | The purpose of these operands is to distinguish between cases | |
8117 | where the endian-ness of the values is important (for example | |
8118 | when they are added together), and cases where the endian-ness | |
8119 | is irrelevant, but the order of register operations is important. | |
8120 | For example when loading a value from memory into a register | |
8121 | pair, the endian-ness does not matter. Provided that the value | |
8122 | from the lower memory address is put into the lower numbered | |
8123 | register, and the value from the higher address is put into the | |
8124 | higher numbered register, the load will work regardless of whether | |
8125 | the value being loaded is big-wordian or little-wordian. The | |
8126 | order of the two register loads can matter however, if the address | |
8127 | of the memory location is actually held in one of the registers | |
8128 | being overwritten by the load. */ | |
c1c2bc04 | 8129 | case 'Q': |
d5b7b3ae | 8130 | if (REGNO (x) > LAST_ARM_REGNUM) |
c1c2bc04 | 8131 | abort (); |
d5b7b3ae | 8132 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 1 : 0)); |
c1c2bc04 RE |
8133 | return; |
8134 | ||
9997d19d | 8135 | case 'R': |
d5b7b3ae | 8136 | if (REGNO (x) > LAST_ARM_REGNUM) |
9997d19d | 8137 | abort (); |
d5b7b3ae RE |
8138 | asm_fprintf (stream, "%r", REGNO (x) + (WORDS_BIG_ENDIAN ? 0 : 1)); |
8139 | return; | |
8140 | ||
8141 | case 'H': | |
8142 | if (REGNO (x) > LAST_ARM_REGNUM) | |
8143 | abort (); | |
8144 | asm_fprintf (stream, "%r", REGNO (x) + 1); | |
9997d19d RE |
8145 | return; |
8146 | ||
8147 | case 'm': | |
d5b7b3ae RE |
8148 | asm_fprintf (stream, "%r", |
8149 | GET_CODE (XEXP (x, 0)) == REG | |
8150 | ? REGNO (XEXP (x, 0)) : REGNO (XEXP (XEXP (x, 0), 0))); | |
9997d19d RE |
8151 | return; |
8152 | ||
8153 | case 'M': | |
dd18ae56 | 8154 | asm_fprintf (stream, "{%r-%r}", |
d5b7b3ae RE |
8155 | REGNO (x), |
8156 | REGNO (x) + NUM_REGS (GET_MODE (x)) - 1); | |
9997d19d RE |
8157 | return; |
8158 | ||
8159 | case 'd': | |
5895f793 | 8160 | if (!x) |
d5b7b3ae RE |
8161 | return; |
8162 | ||
8163 | if (TARGET_ARM) | |
9997d19d RE |
8164 | fputs (arm_condition_codes[get_arm_condition_code (x)], |
8165 | stream); | |
d5b7b3ae RE |
8166 | else |
8167 | fputs (thumb_condition_code (x, 0), stream); | |
9997d19d RE |
8168 | return; |
8169 | ||
8170 | case 'D': | |
5895f793 | 8171 | if (!x) |
d5b7b3ae RE |
8172 | return; |
8173 | ||
8174 | if (TARGET_ARM) | |
8175 | fputs (arm_condition_codes[ARM_INVERSE_CONDITION_CODE | |
8176 | (get_arm_condition_code (x))], | |
9997d19d | 8177 | stream); |
d5b7b3ae RE |
8178 | else |
8179 | fputs (thumb_condition_code (x, 1), stream); | |
9997d19d RE |
8180 | return; |
8181 | ||
8182 | default: | |
8183 | if (x == 0) | |
8184 | abort (); | |
8185 | ||
8186 | if (GET_CODE (x) == REG) | |
d5b7b3ae | 8187 | asm_fprintf (stream, "%r", REGNO (x)); |
9997d19d RE |
8188 | else if (GET_CODE (x) == MEM) |
8189 | { | |
8190 | output_memory_reference_mode = GET_MODE (x); | |
8191 | output_address (XEXP (x, 0)); | |
8192 | } | |
8193 | else if (GET_CODE (x) == CONST_DOUBLE) | |
8194 | fprintf (stream, "#%s", fp_immediate_constant (x)); | |
8195 | else if (GET_CODE (x) == NEG) | |
6354dc9b | 8196 | abort (); /* This should never happen now. */ |
9997d19d RE |
8197 | else |
8198 | { | |
8199 | fputc ('#', stream); | |
8200 | output_addr_const (stream, x); | |
8201 | } | |
8202 | } | |
8203 | } | |
cce8749e CH |
8204 | \f |
8205 | /* A finite state machine takes care of noticing whether or not instructions | |
8206 | can be conditionally executed, and thus decrease execution time and code | |
8207 | size by deleting branch instructions. The fsm is controlled by | |
8208 | final_prescan_insn, and controls the actions of ASM_OUTPUT_OPCODE. */ | |
8209 | ||
8210 | /* The state of the fsm controlling condition codes are: | |
8211 | 0: normal, do nothing special | |
8212 | 1: make ASM_OUTPUT_OPCODE not output this instruction | |
8213 | 2: make ASM_OUTPUT_OPCODE not output this instruction | |
8214 | 3: make instructions conditional | |
8215 | 4: make instructions conditional | |
8216 | ||
8217 | State transitions (state->state by whom under condition): | |
8218 | 0 -> 1 final_prescan_insn if the `target' is a label | |
8219 | 0 -> 2 final_prescan_insn if the `target' is an unconditional branch | |
8220 | 1 -> 3 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
8221 | 2 -> 4 ASM_OUTPUT_OPCODE after not having output the conditional branch | |
8222 | 3 -> 0 ASM_OUTPUT_INTERNAL_LABEL if the `target' label is reached | |
8223 | (the target label has CODE_LABEL_NUMBER equal to arm_target_label). | |
8224 | 4 -> 0 final_prescan_insn if the `target' unconditional branch is reached | |
8225 | (the target insn is arm_target_insn). | |
8226 | ||
ff9940b0 RE |
8227 | If the jump clobbers the conditions then we use states 2 and 4. |
8228 | ||
8229 | A similar thing can be done with conditional return insns. | |
8230 | ||
cce8749e CH |
8231 | XXX In case the `target' is an unconditional branch, this conditionalising |
8232 | of the instructions always reduces code size, but not always execution | |
8233 | time. But then, I want to reduce the code size to somewhere near what | |
8234 | /bin/cc produces. */ | |
8235 | ||
cce8749e CH |
8236 | /* Returns the index of the ARM condition code string in |
8237 | `arm_condition_codes'. COMPARISON should be an rtx like | |
8238 | `(eq (...) (...))'. */ | |
8239 | ||
84ed5e79 | 8240 | static enum arm_cond_code |
cce8749e CH |
8241 | get_arm_condition_code (comparison) |
8242 | rtx comparison; | |
8243 | { | |
5165176d | 8244 | enum machine_mode mode = GET_MODE (XEXP (comparison, 0)); |
84ed5e79 RE |
8245 | register int code; |
8246 | register enum rtx_code comp_code = GET_CODE (comparison); | |
5165176d RE |
8247 | |
8248 | if (GET_MODE_CLASS (mode) != MODE_CC) | |
84ed5e79 | 8249 | mode = SELECT_CC_MODE (comp_code, XEXP (comparison, 0), |
5165176d RE |
8250 | XEXP (comparison, 1)); |
8251 | ||
8252 | switch (mode) | |
cce8749e | 8253 | { |
84ed5e79 RE |
8254 | case CC_DNEmode: code = ARM_NE; goto dominance; |
8255 | case CC_DEQmode: code = ARM_EQ; goto dominance; | |
8256 | case CC_DGEmode: code = ARM_GE; goto dominance; | |
8257 | case CC_DGTmode: code = ARM_GT; goto dominance; | |
8258 | case CC_DLEmode: code = ARM_LE; goto dominance; | |
8259 | case CC_DLTmode: code = ARM_LT; goto dominance; | |
8260 | case CC_DGEUmode: code = ARM_CS; goto dominance; | |
8261 | case CC_DGTUmode: code = ARM_HI; goto dominance; | |
8262 | case CC_DLEUmode: code = ARM_LS; goto dominance; | |
8263 | case CC_DLTUmode: code = ARM_CC; | |
8264 | ||
8265 | dominance: | |
8266 | if (comp_code != EQ && comp_code != NE) | |
8267 | abort (); | |
8268 | ||
8269 | if (comp_code == EQ) | |
8270 | return ARM_INVERSE_CONDITION_CODE (code); | |
8271 | return code; | |
8272 | ||
5165176d | 8273 | case CC_NOOVmode: |
84ed5e79 | 8274 | switch (comp_code) |
5165176d | 8275 | { |
84ed5e79 RE |
8276 | case NE: return ARM_NE; |
8277 | case EQ: return ARM_EQ; | |
8278 | case GE: return ARM_PL; | |
8279 | case LT: return ARM_MI; | |
5165176d RE |
8280 | default: abort (); |
8281 | } | |
8282 | ||
8283 | case CC_Zmode: | |
84ed5e79 | 8284 | switch (comp_code) |
5165176d | 8285 | { |
84ed5e79 RE |
8286 | case NE: return ARM_NE; |
8287 | case EQ: return ARM_EQ; | |
5165176d RE |
8288 | default: abort (); |
8289 | } | |
8290 | ||
8291 | case CCFPEmode: | |
e45b72c4 RE |
8292 | case CCFPmode: |
8293 | /* These encodings assume that AC=1 in the FPA system control | |
8294 | byte. This allows us to handle all cases except UNEQ and | |
8295 | LTGT. */ | |
84ed5e79 RE |
8296 | switch (comp_code) |
8297 | { | |
8298 | case GE: return ARM_GE; | |
8299 | case GT: return ARM_GT; | |
8300 | case LE: return ARM_LS; | |
8301 | case LT: return ARM_MI; | |
e45b72c4 RE |
8302 | case NE: return ARM_NE; |
8303 | case EQ: return ARM_EQ; | |
8304 | case ORDERED: return ARM_VC; | |
8305 | case UNORDERED: return ARM_VS; | |
8306 | case UNLT: return ARM_LT; | |
8307 | case UNLE: return ARM_LE; | |
8308 | case UNGT: return ARM_HI; | |
8309 | case UNGE: return ARM_PL; | |
8310 | /* UNEQ and LTGT do not have a representation. */ | |
8311 | case UNEQ: /* Fall through. */ | |
8312 | case LTGT: /* Fall through. */ | |
84ed5e79 RE |
8313 | default: abort (); |
8314 | } | |
8315 | ||
8316 | case CC_SWPmode: | |
8317 | switch (comp_code) | |
8318 | { | |
8319 | case NE: return ARM_NE; | |
8320 | case EQ: return ARM_EQ; | |
8321 | case GE: return ARM_LE; | |
8322 | case GT: return ARM_LT; | |
8323 | case LE: return ARM_GE; | |
8324 | case LT: return ARM_GT; | |
8325 | case GEU: return ARM_LS; | |
8326 | case GTU: return ARM_CC; | |
8327 | case LEU: return ARM_CS; | |
8328 | case LTU: return ARM_HI; | |
8329 | default: abort (); | |
8330 | } | |
8331 | ||
bd9c7e23 RE |
8332 | case CC_Cmode: |
8333 | switch (comp_code) | |
8334 | { | |
8335 | case LTU: return ARM_CS; | |
8336 | case GEU: return ARM_CC; | |
8337 | default: abort (); | |
8338 | } | |
8339 | ||
5165176d | 8340 | case CCmode: |
84ed5e79 | 8341 | switch (comp_code) |
5165176d | 8342 | { |
84ed5e79 RE |
8343 | case NE: return ARM_NE; |
8344 | case EQ: return ARM_EQ; | |
8345 | case GE: return ARM_GE; | |
8346 | case GT: return ARM_GT; | |
8347 | case LE: return ARM_LE; | |
8348 | case LT: return ARM_LT; | |
8349 | case GEU: return ARM_CS; | |
8350 | case GTU: return ARM_HI; | |
8351 | case LEU: return ARM_LS; | |
8352 | case LTU: return ARM_CC; | |
5165176d RE |
8353 | default: abort (); |
8354 | } | |
8355 | ||
cce8749e CH |
8356 | default: abort (); |
8357 | } | |
84ed5e79 RE |
8358 | |
8359 | abort (); | |
f3bb6135 | 8360 | } |
cce8749e CH |
8361 | |
8362 | ||
8363 | void | |
74bbc178 | 8364 | arm_final_prescan_insn (insn) |
cce8749e | 8365 | rtx insn; |
cce8749e CH |
8366 | { |
8367 | /* BODY will hold the body of INSN. */ | |
8368 | register rtx body = PATTERN (insn); | |
8369 | ||
8370 | /* This will be 1 if trying to repeat the trick, and things need to be | |
8371 | reversed if it appears to fail. */ | |
8372 | int reverse = 0; | |
8373 | ||
ff9940b0 RE |
8374 | /* JUMP_CLOBBERS will be one implies that the conditions if a branch is |
8375 | taken are clobbered, even if the rtl suggests otherwise. It also | |
8376 | means that we have to grub around within the jump expression to find | |
8377 | out what the conditions are when the jump isn't taken. */ | |
8378 | int jump_clobbers = 0; | |
8379 | ||
6354dc9b | 8380 | /* If we start with a return insn, we only succeed if we find another one. */ |
ff9940b0 RE |
8381 | int seeking_return = 0; |
8382 | ||
cce8749e CH |
8383 | /* START_INSN will hold the insn from where we start looking. This is the |
8384 | first insn after the following code_label if REVERSE is true. */ | |
8385 | rtx start_insn = insn; | |
8386 | ||
8387 | /* If in state 4, check if the target branch is reached, in order to | |
8388 | change back to state 0. */ | |
8389 | if (arm_ccfsm_state == 4) | |
8390 | { | |
8391 | if (insn == arm_target_insn) | |
f5a1b0d2 NC |
8392 | { |
8393 | arm_target_insn = NULL; | |
8394 | arm_ccfsm_state = 0; | |
8395 | } | |
cce8749e CH |
8396 | return; |
8397 | } | |
8398 | ||
8399 | /* If in state 3, it is possible to repeat the trick, if this insn is an | |
8400 | unconditional branch to a label, and immediately following this branch | |
8401 | is the previous target label which is only used once, and the label this | |
8402 | branch jumps to is not too far off. */ | |
8403 | if (arm_ccfsm_state == 3) | |
8404 | { | |
8405 | if (simplejump_p (insn)) | |
8406 | { | |
8407 | start_insn = next_nonnote_insn (start_insn); | |
8408 | if (GET_CODE (start_insn) == BARRIER) | |
8409 | { | |
8410 | /* XXX Isn't this always a barrier? */ | |
8411 | start_insn = next_nonnote_insn (start_insn); | |
8412 | } | |
8413 | if (GET_CODE (start_insn) == CODE_LABEL | |
8414 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
8415 | && LABEL_NUSES (start_insn) == 1) | |
8416 | reverse = TRUE; | |
8417 | else | |
8418 | return; | |
8419 | } | |
ff9940b0 RE |
8420 | else if (GET_CODE (body) == RETURN) |
8421 | { | |
8422 | start_insn = next_nonnote_insn (start_insn); | |
8423 | if (GET_CODE (start_insn) == BARRIER) | |
8424 | start_insn = next_nonnote_insn (start_insn); | |
8425 | if (GET_CODE (start_insn) == CODE_LABEL | |
8426 | && CODE_LABEL_NUMBER (start_insn) == arm_target_label | |
8427 | && LABEL_NUSES (start_insn) == 1) | |
8428 | { | |
8429 | reverse = TRUE; | |
8430 | seeking_return = 1; | |
8431 | } | |
8432 | else | |
8433 | return; | |
8434 | } | |
cce8749e CH |
8435 | else |
8436 | return; | |
8437 | } | |
8438 | ||
8439 | if (arm_ccfsm_state != 0 && !reverse) | |
8440 | abort (); | |
8441 | if (GET_CODE (insn) != JUMP_INSN) | |
8442 | return; | |
8443 | ||
ddd5a7c1 | 8444 | /* This jump might be paralleled with a clobber of the condition codes |
ff9940b0 RE |
8445 | the jump should always come first */ |
8446 | if (GET_CODE (body) == PARALLEL && XVECLEN (body, 0) > 0) | |
8447 | body = XVECEXP (body, 0, 0); | |
8448 | ||
8449 | #if 0 | |
8450 | /* If this is a conditional return then we don't want to know */ | |
8451 | if (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC | |
8452 | && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE | |
8453 | && (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN | |
8454 | || GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN)) | |
8455 | return; | |
8456 | #endif | |
8457 | ||
cce8749e CH |
8458 | if (reverse |
8459 | || (GET_CODE (body) == SET && GET_CODE (SET_DEST (body)) == PC | |
8460 | && GET_CODE (SET_SRC (body)) == IF_THEN_ELSE)) | |
8461 | { | |
bd9c7e23 RE |
8462 | int insns_skipped; |
8463 | int fail = FALSE, succeed = FALSE; | |
cce8749e CH |
8464 | /* Flag which part of the IF_THEN_ELSE is the LABEL_REF. */ |
8465 | int then_not_else = TRUE; | |
ff9940b0 | 8466 | rtx this_insn = start_insn, label = 0; |
cce8749e | 8467 | |
e45b72c4 RE |
8468 | /* If the jump cannot be done with one instruction, we cannot |
8469 | conditionally execute the instruction in the inverse case. */ | |
ff9940b0 | 8470 | if (get_attr_conds (insn) == CONDS_JUMP_CLOB) |
5bbe2d40 | 8471 | { |
5bbe2d40 RE |
8472 | jump_clobbers = 1; |
8473 | return; | |
8474 | } | |
ff9940b0 | 8475 | |
cce8749e CH |
8476 | /* Register the insn jumped to. */ |
8477 | if (reverse) | |
ff9940b0 RE |
8478 | { |
8479 | if (!seeking_return) | |
8480 | label = XEXP (SET_SRC (body), 0); | |
8481 | } | |
cce8749e CH |
8482 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == LABEL_REF) |
8483 | label = XEXP (XEXP (SET_SRC (body), 1), 0); | |
8484 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == LABEL_REF) | |
8485 | { | |
8486 | label = XEXP (XEXP (SET_SRC (body), 2), 0); | |
8487 | then_not_else = FALSE; | |
8488 | } | |
ff9940b0 RE |
8489 | else if (GET_CODE (XEXP (SET_SRC (body), 1)) == RETURN) |
8490 | seeking_return = 1; | |
8491 | else if (GET_CODE (XEXP (SET_SRC (body), 2)) == RETURN) | |
8492 | { | |
8493 | seeking_return = 1; | |
8494 | then_not_else = FALSE; | |
8495 | } | |
cce8749e CH |
8496 | else |
8497 | abort (); | |
8498 | ||
8499 | /* See how many insns this branch skips, and what kind of insns. If all | |
8500 | insns are okay, and the label or unconditional branch to the same | |
8501 | label is not too far away, succeed. */ | |
8502 | for (insns_skipped = 0; | |
b36ba79f | 8503 | !fail && !succeed && insns_skipped++ < max_insns_skipped;) |
cce8749e CH |
8504 | { |
8505 | rtx scanbody; | |
8506 | ||
8507 | this_insn = next_nonnote_insn (this_insn); | |
8508 | if (!this_insn) | |
8509 | break; | |
8510 | ||
cce8749e CH |
8511 | switch (GET_CODE (this_insn)) |
8512 | { | |
8513 | case CODE_LABEL: | |
8514 | /* Succeed if it is the target label, otherwise fail since | |
8515 | control falls in from somewhere else. */ | |
8516 | if (this_insn == label) | |
8517 | { | |
ff9940b0 RE |
8518 | if (jump_clobbers) |
8519 | { | |
8520 | arm_ccfsm_state = 2; | |
8521 | this_insn = next_nonnote_insn (this_insn); | |
8522 | } | |
8523 | else | |
8524 | arm_ccfsm_state = 1; | |
cce8749e CH |
8525 | succeed = TRUE; |
8526 | } | |
8527 | else | |
8528 | fail = TRUE; | |
8529 | break; | |
8530 | ||
ff9940b0 | 8531 | case BARRIER: |
cce8749e | 8532 | /* Succeed if the following insn is the target label. |
ff9940b0 RE |
8533 | Otherwise fail. |
8534 | If return insns are used then the last insn in a function | |
6354dc9b | 8535 | will be a barrier. */ |
cce8749e | 8536 | this_insn = next_nonnote_insn (this_insn); |
ff9940b0 | 8537 | if (this_insn && this_insn == label) |
cce8749e | 8538 | { |
ff9940b0 RE |
8539 | if (jump_clobbers) |
8540 | { | |
8541 | arm_ccfsm_state = 2; | |
8542 | this_insn = next_nonnote_insn (this_insn); | |
8543 | } | |
8544 | else | |
8545 | arm_ccfsm_state = 1; | |
cce8749e CH |
8546 | succeed = TRUE; |
8547 | } | |
8548 | else | |
8549 | fail = TRUE; | |
8550 | break; | |
8551 | ||
ff9940b0 | 8552 | case CALL_INSN: |
2b835d68 | 8553 | /* If using 32-bit addresses the cc is not preserved over |
914a3b8c | 8554 | calls. */ |
2b835d68 | 8555 | if (TARGET_APCS_32) |
bd9c7e23 RE |
8556 | { |
8557 | /* Succeed if the following insn is the target label, | |
8558 | or if the following two insns are a barrier and | |
8559 | the target label. */ | |
8560 | this_insn = next_nonnote_insn (this_insn); | |
8561 | if (this_insn && GET_CODE (this_insn) == BARRIER) | |
8562 | this_insn = next_nonnote_insn (this_insn); | |
8563 | ||
8564 | if (this_insn && this_insn == label | |
b36ba79f | 8565 | && insns_skipped < max_insns_skipped) |
bd9c7e23 RE |
8566 | { |
8567 | if (jump_clobbers) | |
8568 | { | |
8569 | arm_ccfsm_state = 2; | |
8570 | this_insn = next_nonnote_insn (this_insn); | |
8571 | } | |
8572 | else | |
8573 | arm_ccfsm_state = 1; | |
8574 | succeed = TRUE; | |
8575 | } | |
8576 | else | |
8577 | fail = TRUE; | |
8578 | } | |
ff9940b0 | 8579 | break; |
2b835d68 | 8580 | |
cce8749e CH |
8581 | case JUMP_INSN: |
8582 | /* If this is an unconditional branch to the same label, succeed. | |
8583 | If it is to another label, do nothing. If it is conditional, | |
8584 | fail. */ | |
914a3b8c | 8585 | /* XXX Probably, the tests for SET and the PC are unnecessary. */ |
cce8749e | 8586 | |
ed4c4348 | 8587 | scanbody = PATTERN (this_insn); |
ff9940b0 RE |
8588 | if (GET_CODE (scanbody) == SET |
8589 | && GET_CODE (SET_DEST (scanbody)) == PC) | |
cce8749e CH |
8590 | { |
8591 | if (GET_CODE (SET_SRC (scanbody)) == LABEL_REF | |
8592 | && XEXP (SET_SRC (scanbody), 0) == label && !reverse) | |
8593 | { | |
8594 | arm_ccfsm_state = 2; | |
8595 | succeed = TRUE; | |
8596 | } | |
8597 | else if (GET_CODE (SET_SRC (scanbody)) == IF_THEN_ELSE) | |
8598 | fail = TRUE; | |
8599 | } | |
b36ba79f RE |
8600 | /* Fail if a conditional return is undesirable (eg on a |
8601 | StrongARM), but still allow this if optimizing for size. */ | |
8602 | else if (GET_CODE (scanbody) == RETURN | |
5895f793 RE |
8603 | && !use_return_insn (TRUE) |
8604 | && !optimize_size) | |
b36ba79f | 8605 | fail = TRUE; |
ff9940b0 RE |
8606 | else if (GET_CODE (scanbody) == RETURN |
8607 | && seeking_return) | |
8608 | { | |
8609 | arm_ccfsm_state = 2; | |
8610 | succeed = TRUE; | |
8611 | } | |
8612 | else if (GET_CODE (scanbody) == PARALLEL) | |
8613 | { | |
8614 | switch (get_attr_conds (this_insn)) | |
8615 | { | |
8616 | case CONDS_NOCOND: | |
8617 | break; | |
8618 | default: | |
8619 | fail = TRUE; | |
8620 | break; | |
8621 | } | |
8622 | } | |
4e67550b RE |
8623 | else |
8624 | fail = TRUE; /* Unrecognized jump (eg epilogue). */ | |
8625 | ||
cce8749e CH |
8626 | break; |
8627 | ||
8628 | case INSN: | |
ff9940b0 RE |
8629 | /* Instructions using or affecting the condition codes make it |
8630 | fail. */ | |
ed4c4348 | 8631 | scanbody = PATTERN (this_insn); |
5895f793 RE |
8632 | if (!(GET_CODE (scanbody) == SET |
8633 | || GET_CODE (scanbody) == PARALLEL) | |
74641843 | 8634 | || get_attr_conds (this_insn) != CONDS_NOCOND) |
cce8749e CH |
8635 | fail = TRUE; |
8636 | break; | |
8637 | ||
8638 | default: | |
8639 | break; | |
8640 | } | |
8641 | } | |
8642 | if (succeed) | |
8643 | { | |
ff9940b0 | 8644 | if ((!seeking_return) && (arm_ccfsm_state == 1 || reverse)) |
cce8749e | 8645 | arm_target_label = CODE_LABEL_NUMBER (label); |
ff9940b0 RE |
8646 | else if (seeking_return || arm_ccfsm_state == 2) |
8647 | { | |
8648 | while (this_insn && GET_CODE (PATTERN (this_insn)) == USE) | |
8649 | { | |
8650 | this_insn = next_nonnote_insn (this_insn); | |
8651 | if (this_insn && (GET_CODE (this_insn) == BARRIER | |
8652 | || GET_CODE (this_insn) == CODE_LABEL)) | |
8653 | abort (); | |
8654 | } | |
8655 | if (!this_insn) | |
8656 | { | |
8657 | /* Oh, dear! we ran off the end.. give up */ | |
8658 | recog (PATTERN (insn), insn, NULL_PTR); | |
8659 | arm_ccfsm_state = 0; | |
abaa26e5 | 8660 | arm_target_insn = NULL; |
ff9940b0 RE |
8661 | return; |
8662 | } | |
8663 | arm_target_insn = this_insn; | |
8664 | } | |
cce8749e CH |
8665 | else |
8666 | abort (); | |
ff9940b0 RE |
8667 | if (jump_clobbers) |
8668 | { | |
8669 | if (reverse) | |
8670 | abort (); | |
8671 | arm_current_cc = | |
8672 | get_arm_condition_code (XEXP (XEXP (XEXP (SET_SRC (body), | |
8673 | 0), 0), 1)); | |
8674 | if (GET_CODE (XEXP (XEXP (SET_SRC (body), 0), 0)) == AND) | |
8675 | arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); | |
8676 | if (GET_CODE (XEXP (SET_SRC (body), 0)) == NE) | |
8677 | arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); | |
8678 | } | |
8679 | else | |
8680 | { | |
8681 | /* If REVERSE is true, ARM_CURRENT_CC needs to be inverted from | |
8682 | what it was. */ | |
8683 | if (!reverse) | |
8684 | arm_current_cc = get_arm_condition_code (XEXP (SET_SRC (body), | |
8685 | 0)); | |
8686 | } | |
cce8749e | 8687 | |
cce8749e CH |
8688 | if (reverse || then_not_else) |
8689 | arm_current_cc = ARM_INVERSE_CONDITION_CODE (arm_current_cc); | |
8690 | } | |
d5b7b3ae | 8691 | |
1ccbefce | 8692 | /* Restore recog_data (getting the attributes of other insns can |
ff9940b0 | 8693 | destroy this array, but final.c assumes that it remains intact |
ddd5a7c1 | 8694 | across this call; since the insn has been recognized already we |
b020fd92 | 8695 | call recog direct). */ |
ff9940b0 | 8696 | recog (PATTERN (insn), insn, NULL_PTR); |
cce8749e | 8697 | } |
f3bb6135 | 8698 | } |
cce8749e | 8699 | |
d5b7b3ae RE |
8700 | int |
8701 | arm_regno_class (regno) | |
8702 | int regno; | |
8703 | { | |
8704 | if (TARGET_THUMB) | |
8705 | { | |
8706 | if (regno == STACK_POINTER_REGNUM) | |
8707 | return STACK_REG; | |
8708 | if (regno == CC_REGNUM) | |
8709 | return CC_REG; | |
8710 | if (regno < 8) | |
8711 | return LO_REGS; | |
8712 | return HI_REGS; | |
8713 | } | |
8714 | ||
8715 | if ( regno <= LAST_ARM_REGNUM | |
8716 | || regno == FRAME_POINTER_REGNUM | |
8717 | || regno == ARG_POINTER_REGNUM) | |
8718 | return GENERAL_REGS; | |
8719 | ||
8720 | if (regno == CC_REGNUM) | |
8721 | return NO_REGS; | |
8722 | ||
8723 | return FPU_REGS; | |
8724 | } | |
8725 | ||
8726 | /* Handle a special case when computing the offset | |
8727 | of an argument from the frame pointer. */ | |
8728 | int | |
8729 | arm_debugger_arg_offset (value, addr) | |
8730 | int value; | |
8731 | rtx addr; | |
8732 | { | |
8733 | rtx insn; | |
8734 | ||
8735 | /* We are only interested if dbxout_parms() failed to compute the offset. */ | |
8736 | if (value != 0) | |
8737 | return 0; | |
8738 | ||
8739 | /* We can only cope with the case where the address is held in a register. */ | |
8740 | if (GET_CODE (addr) != REG) | |
8741 | return 0; | |
8742 | ||
8743 | /* If we are using the frame pointer to point at the argument, then | |
8744 | an offset of 0 is correct. */ | |
cd2b33d0 | 8745 | if (REGNO (addr) == (unsigned) HARD_FRAME_POINTER_REGNUM) |
d5b7b3ae RE |
8746 | return 0; |
8747 | ||
8748 | /* If we are using the stack pointer to point at the | |
8749 | argument, then an offset of 0 is correct. */ | |
5895f793 | 8750 | if ((TARGET_THUMB || !frame_pointer_needed) |
d5b7b3ae RE |
8751 | && REGNO (addr) == SP_REGNUM) |
8752 | return 0; | |
8753 | ||
8754 | /* Oh dear. The argument is pointed to by a register rather | |
8755 | than being held in a register, or being stored at a known | |
8756 | offset from the frame pointer. Since GDB only understands | |
8757 | those two kinds of argument we must translate the address | |
8758 | held in the register into an offset from the frame pointer. | |
8759 | We do this by searching through the insns for the function | |
8760 | looking to see where this register gets its value. If the | |
8761 | register is initialised from the frame pointer plus an offset | |
8762 | then we are in luck and we can continue, otherwise we give up. | |
8763 | ||
8764 | This code is exercised by producing debugging information | |
8765 | for a function with arguments like this: | |
8766 | ||
8767 | double func (double a, double b, int c, double d) {return d;} | |
8768 | ||
8769 | Without this code the stab for parameter 'd' will be set to | |
8770 | an offset of 0 from the frame pointer, rather than 8. */ | |
8771 | ||
8772 | /* The if() statement says: | |
8773 | ||
8774 | If the insn is a normal instruction | |
8775 | and if the insn is setting the value in a register | |
8776 | and if the register being set is the register holding the address of the argument | |
8777 | and if the address is computing by an addition | |
8778 | that involves adding to a register | |
8779 | which is the frame pointer | |
8780 | a constant integer | |
8781 | ||
8782 | then... */ | |
8783 | ||
8784 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
8785 | { | |
8786 | if ( GET_CODE (insn) == INSN | |
8787 | && GET_CODE (PATTERN (insn)) == SET | |
8788 | && REGNO (XEXP (PATTERN (insn), 0)) == REGNO (addr) | |
8789 | && GET_CODE (XEXP (PATTERN (insn), 1)) == PLUS | |
8790 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 0)) == REG | |
cd2b33d0 | 8791 | && REGNO (XEXP (XEXP (PATTERN (insn), 1), 0)) == (unsigned) HARD_FRAME_POINTER_REGNUM |
d5b7b3ae RE |
8792 | && GET_CODE (XEXP (XEXP (PATTERN (insn), 1), 1)) == CONST_INT |
8793 | ) | |
8794 | { | |
8795 | value = INTVAL (XEXP (XEXP (PATTERN (insn), 1), 1)); | |
8796 | ||
8797 | break; | |
8798 | } | |
8799 | } | |
8800 | ||
8801 | if (value == 0) | |
8802 | { | |
8803 | debug_rtx (addr); | |
8804 | warning ("Unable to compute real location of stacked parameter"); | |
8805 | value = 8; /* XXX magic hack */ | |
8806 | } | |
8807 | ||
8808 | return value; | |
8809 | } | |
8810 | ||
d19fb8e3 NC |
8811 | #define def_builtin(NAME, TYPE, CODE) \ |
8812 | builtin_function ((NAME), (TYPE), (CODE), BUILT_IN_MD, NULL_PTR) | |
8813 | ||
8814 | void | |
8815 | arm_init_builtins () | |
8816 | { | |
cbd5937a | 8817 | tree endlink = void_list_node; |
d19fb8e3 NC |
8818 | tree int_endlink = tree_cons (NULL_TREE, integer_type_node, endlink); |
8819 | tree pchar_type_node = build_pointer_type (char_type_node); | |
8820 | ||
8821 | tree int_ftype_int, void_ftype_pchar; | |
8822 | ||
8823 | /* void func (void *) */ | |
8824 | void_ftype_pchar | |
8825 | = build_function_type (void_type_node, | |
8826 | tree_cons (NULL_TREE, pchar_type_node, endlink)); | |
8827 | ||
8828 | /* int func (int) */ | |
8829 | int_ftype_int | |
8830 | = build_function_type (integer_type_node, int_endlink); | |
8831 | ||
8832 | /* Initialize arm V5 builtins. */ | |
8833 | if (arm_arch5) | |
eab4abeb | 8834 | def_builtin ("__builtin_clz", int_ftype_int, ARM_BUILTIN_CLZ); |
b15bca31 RE |
8835 | |
8836 | /* Initialize arm V5E builtins. */ | |
8837 | if (arm_arch5e) | |
eab4abeb NC |
8838 | def_builtin ("__builtin_prefetch", void_ftype_pchar, |
8839 | ARM_BUILTIN_PREFETCH); | |
d19fb8e3 NC |
8840 | } |
8841 | ||
8842 | /* Expand an expression EXP that calls a built-in function, | |
8843 | with result going to TARGET if that's convenient | |
8844 | (and in mode MODE if that's convenient). | |
8845 | SUBTARGET may be used as the target for computing one of EXP's operands. | |
8846 | IGNORE is nonzero if the value is to be ignored. */ | |
8847 | ||
8848 | rtx | |
8849 | arm_expand_builtin (exp, target, subtarget, mode, ignore) | |
8850 | tree exp; | |
8851 | rtx target; | |
8852 | rtx subtarget ATTRIBUTE_UNUSED; | |
8853 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
8854 | int ignore ATTRIBUTE_UNUSED; | |
8855 | { | |
8856 | enum insn_code icode; | |
8857 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
8858 | tree arglist = TREE_OPERAND (exp, 1); | |
8859 | tree arg0; | |
8860 | rtx op0, pat; | |
8861 | enum machine_mode tmode, mode0; | |
8862 | int fcode = DECL_FUNCTION_CODE (fndecl); | |
8863 | ||
8864 | switch (fcode) | |
8865 | { | |
8866 | default: | |
8867 | break; | |
8868 | ||
8869 | case ARM_BUILTIN_CLZ: | |
8870 | icode = CODE_FOR_clz; | |
8871 | arg0 = TREE_VALUE (arglist); | |
8872 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
8873 | tmode = insn_data[icode].operand[0].mode; | |
8874 | mode0 = insn_data[icode].operand[1].mode; | |
8875 | ||
8876 | if (! (*insn_data[icode].operand[1].predicate) (op0, mode0)) | |
8877 | op0 = copy_to_mode_reg (mode0, op0); | |
8878 | if (target == 0 | |
8879 | || GET_MODE (target) != tmode | |
8880 | || ! (*insn_data[icode].operand[0].predicate) (target, tmode)) | |
8881 | target = gen_reg_rtx (tmode); | |
8882 | pat = GEN_FCN (icode) (target, op0); | |
8883 | if (! pat) | |
8884 | return 0; | |
8885 | emit_insn (pat); | |
8886 | return target; | |
8887 | ||
8888 | case ARM_BUILTIN_PREFETCH: | |
8889 | icode = CODE_FOR_prefetch; | |
8890 | arg0 = TREE_VALUE (arglist); | |
8891 | op0 = expand_expr (arg0, NULL_RTX, VOIDmode, 0); | |
8892 | ||
8893 | op0 = gen_rtx_MEM (SImode, copy_to_mode_reg (Pmode, op0)); | |
8894 | ||
8895 | pat = GEN_FCN (icode) (op0); | |
8896 | if (! pat) | |
8897 | return 0; | |
8898 | emit_insn (pat); | |
8899 | return target; | |
8900 | } | |
8901 | ||
8902 | /* @@@ Should really do something sensible here. */ | |
8903 | return NULL_RTX; | |
8904 | } | |
d5b7b3ae RE |
8905 | \f |
8906 | /* Recursively search through all of the blocks in a function | |
8907 | checking to see if any of the variables created in that | |
8908 | function match the RTX called 'orig'. If they do then | |
8909 | replace them with the RTX called 'new'. */ | |
8910 | ||
8911 | static void | |
8912 | replace_symbols_in_block (block, orig, new) | |
8913 | tree block; | |
8914 | rtx orig; | |
8915 | rtx new; | |
8916 | { | |
8917 | for (; block; block = BLOCK_CHAIN (block)) | |
8918 | { | |
8919 | tree sym; | |
8920 | ||
5895f793 | 8921 | if (!TREE_USED (block)) |
d5b7b3ae RE |
8922 | continue; |
8923 | ||
8924 | for (sym = BLOCK_VARS (block); sym; sym = TREE_CHAIN (sym)) | |
8925 | { | |
8926 | if ( (DECL_NAME (sym) == 0 && TREE_CODE (sym) != TYPE_DECL) | |
8927 | || DECL_IGNORED_P (sym) | |
8928 | || TREE_CODE (sym) != VAR_DECL | |
8929 | || DECL_EXTERNAL (sym) | |
5895f793 | 8930 | || !rtx_equal_p (DECL_RTL (sym), orig) |
d5b7b3ae RE |
8931 | ) |
8932 | continue; | |
8933 | ||
8934 | DECL_RTL (sym) = new; | |
8935 | } | |
8936 | ||
8937 | replace_symbols_in_block (BLOCK_SUBBLOCKS (block), orig, new); | |
8938 | } | |
8939 | } | |
8940 | ||
8941 | /* Return the number (counting from 0) of the least significant set | |
8942 | bit in MASK. */ | |
8943 | #ifdef __GNUC__ | |
8944 | inline | |
8945 | #endif | |
8946 | static int | |
8947 | number_of_first_bit_set (mask) | |
8948 | int mask; | |
8949 | { | |
8950 | int bit; | |
8951 | ||
8952 | for (bit = 0; | |
8953 | (mask & (1 << bit)) == 0; | |
5895f793 | 8954 | ++bit) |
d5b7b3ae RE |
8955 | continue; |
8956 | ||
8957 | return bit; | |
8958 | } | |
8959 | ||
8960 | /* Generate code to return from a thumb function. | |
8961 | If 'reg_containing_return_addr' is -1, then the return address is | |
8962 | actually on the stack, at the stack pointer. */ | |
8963 | static void | |
8964 | thumb_exit (f, reg_containing_return_addr, eh_ofs) | |
8965 | FILE * f; | |
8966 | int reg_containing_return_addr; | |
8967 | rtx eh_ofs; | |
8968 | { | |
8969 | unsigned regs_available_for_popping; | |
8970 | unsigned regs_to_pop; | |
8971 | int pops_needed; | |
8972 | unsigned available; | |
8973 | unsigned required; | |
8974 | int mode; | |
8975 | int size; | |
8976 | int restore_a4 = FALSE; | |
8977 | ||
8978 | /* Compute the registers we need to pop. */ | |
8979 | regs_to_pop = 0; | |
8980 | pops_needed = 0; | |
8981 | ||
8982 | /* There is an assumption here, that if eh_ofs is not NULL, the | |
8983 | normal return address will have been pushed. */ | |
8984 | if (reg_containing_return_addr == -1 || eh_ofs) | |
8985 | { | |
8986 | /* When we are generating a return for __builtin_eh_return, | |
8987 | reg_containing_return_addr must specify the return regno. */ | |
8988 | if (eh_ofs && reg_containing_return_addr == -1) | |
8989 | abort (); | |
8990 | ||
8991 | regs_to_pop |= 1 << LR_REGNUM; | |
5895f793 | 8992 | ++pops_needed; |
d5b7b3ae RE |
8993 | } |
8994 | ||
8995 | if (TARGET_BACKTRACE) | |
8996 | { | |
8997 | /* Restore the (ARM) frame pointer and stack pointer. */ | |
8998 | regs_to_pop |= (1 << ARM_HARD_FRAME_POINTER_REGNUM) | (1 << SP_REGNUM); | |
8999 | pops_needed += 2; | |
9000 | } | |
9001 | ||
9002 | /* If there is nothing to pop then just emit the BX instruction and | |
9003 | return. */ | |
9004 | if (pops_needed == 0) | |
9005 | { | |
9006 | if (eh_ofs) | |
9007 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, REGNO (eh_ofs)); | |
9008 | ||
9009 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
9010 | return; | |
9011 | } | |
9012 | /* Otherwise if we are not supporting interworking and we have not created | |
9013 | a backtrace structure and the function was not entered in ARM mode then | |
9014 | just pop the return address straight into the PC. */ | |
5895f793 RE |
9015 | else if (!TARGET_INTERWORK |
9016 | && !TARGET_BACKTRACE | |
9017 | && !is_called_in_ARM_mode (current_function_decl)) | |
d5b7b3ae RE |
9018 | { |
9019 | if (eh_ofs) | |
9020 | { | |
9021 | asm_fprintf (f, "\tadd\t%r, #4\n", SP_REGNUM); | |
9022 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, REGNO (eh_ofs)); | |
9023 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
9024 | } | |
9025 | else | |
9026 | asm_fprintf (f, "\tpop\t{%r}\n", PC_REGNUM); | |
9027 | ||
9028 | return; | |
9029 | } | |
9030 | ||
9031 | /* Find out how many of the (return) argument registers we can corrupt. */ | |
9032 | regs_available_for_popping = 0; | |
9033 | ||
9034 | /* If returning via __builtin_eh_return, the bottom three registers | |
9035 | all contain information needed for the return. */ | |
9036 | if (eh_ofs) | |
9037 | size = 12; | |
9038 | else | |
9039 | { | |
9040 | #ifdef RTX_CODE | |
9041 | /* If we can deduce the registers used from the function's | |
9042 | return value. This is more reliable that examining | |
9043 | regs_ever_live[] because that will be set if the register is | |
9044 | ever used in the function, not just if the register is used | |
9045 | to hold a return value. */ | |
9046 | ||
9047 | if (current_function_return_rtx != 0) | |
9048 | mode = GET_MODE (current_function_return_rtx); | |
9049 | else | |
9050 | #endif | |
9051 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); | |
9052 | ||
9053 | size = GET_MODE_SIZE (mode); | |
9054 | ||
9055 | if (size == 0) | |
9056 | { | |
9057 | /* In a void function we can use any argument register. | |
9058 | In a function that returns a structure on the stack | |
9059 | we can use the second and third argument registers. */ | |
9060 | if (mode == VOIDmode) | |
9061 | regs_available_for_popping = | |
9062 | (1 << ARG_REGISTER (1)) | |
9063 | | (1 << ARG_REGISTER (2)) | |
9064 | | (1 << ARG_REGISTER (3)); | |
9065 | else | |
9066 | regs_available_for_popping = | |
9067 | (1 << ARG_REGISTER (2)) | |
9068 | | (1 << ARG_REGISTER (3)); | |
9069 | } | |
9070 | else if (size <= 4) | |
9071 | regs_available_for_popping = | |
9072 | (1 << ARG_REGISTER (2)) | |
9073 | | (1 << ARG_REGISTER (3)); | |
9074 | else if (size <= 8) | |
9075 | regs_available_for_popping = | |
9076 | (1 << ARG_REGISTER (3)); | |
9077 | } | |
9078 | ||
9079 | /* Match registers to be popped with registers into which we pop them. */ | |
9080 | for (available = regs_available_for_popping, | |
9081 | required = regs_to_pop; | |
9082 | required != 0 && available != 0; | |
9083 | available &= ~(available & - available), | |
9084 | required &= ~(required & - required)) | |
9085 | -- pops_needed; | |
9086 | ||
9087 | /* If we have any popping registers left over, remove them. */ | |
9088 | if (available > 0) | |
5895f793 | 9089 | regs_available_for_popping &= ~available; |
d5b7b3ae RE |
9090 | |
9091 | /* Otherwise if we need another popping register we can use | |
9092 | the fourth argument register. */ | |
9093 | else if (pops_needed) | |
9094 | { | |
9095 | /* If we have not found any free argument registers and | |
9096 | reg a4 contains the return address, we must move it. */ | |
9097 | if (regs_available_for_popping == 0 | |
9098 | && reg_containing_return_addr == LAST_ARG_REGNUM) | |
9099 | { | |
9100 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
9101 | reg_containing_return_addr = LR_REGNUM; | |
9102 | } | |
9103 | else if (size > 12) | |
9104 | { | |
9105 | /* Register a4 is being used to hold part of the return value, | |
9106 | but we have dire need of a free, low register. */ | |
9107 | restore_a4 = TRUE; | |
9108 | ||
9109 | asm_fprintf (f, "\tmov\t%r, %r\n",IP_REGNUM, LAST_ARG_REGNUM); | |
9110 | } | |
9111 | ||
9112 | if (reg_containing_return_addr != LAST_ARG_REGNUM) | |
9113 | { | |
9114 | /* The fourth argument register is available. */ | |
9115 | regs_available_for_popping |= 1 << LAST_ARG_REGNUM; | |
9116 | ||
5895f793 | 9117 | --pops_needed; |
d5b7b3ae RE |
9118 | } |
9119 | } | |
9120 | ||
9121 | /* Pop as many registers as we can. */ | |
9122 | thumb_pushpop (f, regs_available_for_popping, FALSE); | |
9123 | ||
9124 | /* Process the registers we popped. */ | |
9125 | if (reg_containing_return_addr == -1) | |
9126 | { | |
9127 | /* The return address was popped into the lowest numbered register. */ | |
5895f793 | 9128 | regs_to_pop &= ~(1 << LR_REGNUM); |
d5b7b3ae RE |
9129 | |
9130 | reg_containing_return_addr = | |
9131 | number_of_first_bit_set (regs_available_for_popping); | |
9132 | ||
9133 | /* Remove this register for the mask of available registers, so that | |
9134 | the return address will not be corrupted by futher pops. */ | |
5895f793 | 9135 | regs_available_for_popping &= ~(1 << reg_containing_return_addr); |
d5b7b3ae RE |
9136 | } |
9137 | ||
9138 | /* If we popped other registers then handle them here. */ | |
9139 | if (regs_available_for_popping) | |
9140 | { | |
9141 | int frame_pointer; | |
9142 | ||
9143 | /* Work out which register currently contains the frame pointer. */ | |
9144 | frame_pointer = number_of_first_bit_set (regs_available_for_popping); | |
9145 | ||
9146 | /* Move it into the correct place. */ | |
9147 | asm_fprintf (f, "\tmov\t%r, %r\n", | |
9148 | ARM_HARD_FRAME_POINTER_REGNUM, frame_pointer); | |
9149 | ||
9150 | /* (Temporarily) remove it from the mask of popped registers. */ | |
5895f793 RE |
9151 | regs_available_for_popping &= ~(1 << frame_pointer); |
9152 | regs_to_pop &= ~(1 << ARM_HARD_FRAME_POINTER_REGNUM); | |
d5b7b3ae RE |
9153 | |
9154 | if (regs_available_for_popping) | |
9155 | { | |
9156 | int stack_pointer; | |
9157 | ||
9158 | /* We popped the stack pointer as well, | |
9159 | find the register that contains it. */ | |
9160 | stack_pointer = number_of_first_bit_set (regs_available_for_popping); | |
9161 | ||
9162 | /* Move it into the stack register. */ | |
9163 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, stack_pointer); | |
9164 | ||
9165 | /* At this point we have popped all necessary registers, so | |
9166 | do not worry about restoring regs_available_for_popping | |
9167 | to its correct value: | |
9168 | ||
9169 | assert (pops_needed == 0) | |
9170 | assert (regs_available_for_popping == (1 << frame_pointer)) | |
9171 | assert (regs_to_pop == (1 << STACK_POINTER)) */ | |
9172 | } | |
9173 | else | |
9174 | { | |
9175 | /* Since we have just move the popped value into the frame | |
9176 | pointer, the popping register is available for reuse, and | |
9177 | we know that we still have the stack pointer left to pop. */ | |
9178 | regs_available_for_popping |= (1 << frame_pointer); | |
9179 | } | |
9180 | } | |
9181 | ||
9182 | /* If we still have registers left on the stack, but we no longer have | |
9183 | any registers into which we can pop them, then we must move the return | |
9184 | address into the link register and make available the register that | |
9185 | contained it. */ | |
9186 | if (regs_available_for_popping == 0 && pops_needed > 0) | |
9187 | { | |
9188 | regs_available_for_popping |= 1 << reg_containing_return_addr; | |
9189 | ||
9190 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, | |
9191 | reg_containing_return_addr); | |
9192 | ||
9193 | reg_containing_return_addr = LR_REGNUM; | |
9194 | } | |
9195 | ||
9196 | /* If we have registers left on the stack then pop some more. | |
9197 | We know that at most we will want to pop FP and SP. */ | |
9198 | if (pops_needed > 0) | |
9199 | { | |
9200 | int popped_into; | |
9201 | int move_to; | |
9202 | ||
9203 | thumb_pushpop (f, regs_available_for_popping, FALSE); | |
9204 | ||
9205 | /* We have popped either FP or SP. | |
9206 | Move whichever one it is into the correct register. */ | |
9207 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
9208 | move_to = number_of_first_bit_set (regs_to_pop); | |
9209 | ||
9210 | asm_fprintf (f, "\tmov\t%r, %r\n", move_to, popped_into); | |
9211 | ||
5895f793 | 9212 | regs_to_pop &= ~(1 << move_to); |
d5b7b3ae | 9213 | |
5895f793 | 9214 | --pops_needed; |
d5b7b3ae RE |
9215 | } |
9216 | ||
9217 | /* If we still have not popped everything then we must have only | |
9218 | had one register available to us and we are now popping the SP. */ | |
9219 | if (pops_needed > 0) | |
9220 | { | |
9221 | int popped_into; | |
9222 | ||
9223 | thumb_pushpop (f, regs_available_for_popping, FALSE); | |
9224 | ||
9225 | popped_into = number_of_first_bit_set (regs_available_for_popping); | |
9226 | ||
9227 | asm_fprintf (f, "\tmov\t%r, %r\n", SP_REGNUM, popped_into); | |
9228 | /* | |
9229 | assert (regs_to_pop == (1 << STACK_POINTER)) | |
9230 | assert (pops_needed == 1) | |
9231 | */ | |
9232 | } | |
9233 | ||
9234 | /* If necessary restore the a4 register. */ | |
9235 | if (restore_a4) | |
9236 | { | |
9237 | if (reg_containing_return_addr != LR_REGNUM) | |
9238 | { | |
9239 | asm_fprintf (f, "\tmov\t%r, %r\n", LR_REGNUM, LAST_ARG_REGNUM); | |
9240 | reg_containing_return_addr = LR_REGNUM; | |
9241 | } | |
9242 | ||
9243 | asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM); | |
9244 | } | |
9245 | ||
9246 | if (eh_ofs) | |
9247 | asm_fprintf (f, "\tadd\t%r, %r\n", SP_REGNUM, REGNO (eh_ofs)); | |
9248 | ||
9249 | /* Return to caller. */ | |
9250 | asm_fprintf (f, "\tbx\t%r\n", reg_containing_return_addr); | |
9251 | } | |
9252 | ||
9253 | /* Emit code to push or pop registers to or from the stack. */ | |
9254 | static void | |
9255 | thumb_pushpop (f, mask, push) | |
9256 | FILE * f; | |
9257 | int mask; | |
9258 | int push; | |
9259 | { | |
9260 | int regno; | |
9261 | int lo_mask = mask & 0xFF; | |
9262 | ||
5895f793 | 9263 | if (lo_mask == 0 && !push && (mask & (1 << 15))) |
d5b7b3ae RE |
9264 | { |
9265 | /* Special case. Do not generate a POP PC statement here, do it in | |
9266 | thumb_exit() */ | |
9267 | thumb_exit (f, -1, NULL_RTX); | |
9268 | return; | |
9269 | } | |
9270 | ||
9271 | fprintf (f, "\t%s\t{", push ? "push" : "pop"); | |
9272 | ||
9273 | /* Look at the low registers first. */ | |
5895f793 | 9274 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++, lo_mask >>= 1) |
d5b7b3ae RE |
9275 | { |
9276 | if (lo_mask & 1) | |
9277 | { | |
9278 | asm_fprintf (f, "%r", regno); | |
9279 | ||
9280 | if ((lo_mask & ~1) != 0) | |
9281 | fprintf (f, ", "); | |
9282 | } | |
9283 | } | |
9284 | ||
9285 | if (push && (mask & (1 << LR_REGNUM))) | |
9286 | { | |
9287 | /* Catch pushing the LR. */ | |
9288 | if (mask & 0xFF) | |
9289 | fprintf (f, ", "); | |
9290 | ||
9291 | asm_fprintf (f, "%r", LR_REGNUM); | |
9292 | } | |
9293 | else if (!push && (mask & (1 << PC_REGNUM))) | |
9294 | { | |
9295 | /* Catch popping the PC. */ | |
9296 | if (TARGET_INTERWORK || TARGET_BACKTRACE) | |
9297 | { | |
9298 | /* The PC is never poped directly, instead | |
9299 | it is popped into r3 and then BX is used. */ | |
9300 | fprintf (f, "}\n"); | |
9301 | ||
9302 | thumb_exit (f, -1, NULL_RTX); | |
9303 | ||
9304 | return; | |
9305 | } | |
9306 | else | |
9307 | { | |
9308 | if (mask & 0xFF) | |
9309 | fprintf (f, ", "); | |
9310 | ||
9311 | asm_fprintf (f, "%r", PC_REGNUM); | |
9312 | } | |
9313 | } | |
9314 | ||
9315 | fprintf (f, "}\n"); | |
9316 | } | |
9317 | \f | |
9318 | void | |
9319 | thumb_final_prescan_insn (insn) | |
9320 | rtx insn; | |
9321 | { | |
d5b7b3ae | 9322 | if (flag_print_asm_name) |
9d98a694 AO |
9323 | asm_fprintf (asm_out_file, "%@ 0x%04x\n", |
9324 | INSN_ADDRESSES (INSN_UID (insn))); | |
d5b7b3ae RE |
9325 | } |
9326 | ||
9327 | int | |
9328 | thumb_shiftable_const (val) | |
9329 | unsigned HOST_WIDE_INT val; | |
9330 | { | |
9331 | unsigned HOST_WIDE_INT mask = 0xff; | |
9332 | int i; | |
9333 | ||
9334 | if (val == 0) /* XXX */ | |
9335 | return 0; | |
9336 | ||
9337 | for (i = 0; i < 25; i++) | |
9338 | if ((val & (mask << i)) == val) | |
9339 | return 1; | |
9340 | ||
9341 | return 0; | |
9342 | } | |
9343 | ||
9344 | /* Returns non-zero if the current function contains, | |
9345 | or might contain a far jump. */ | |
9346 | int | |
9347 | thumb_far_jump_used_p (int in_prologue) | |
9348 | { | |
9349 | rtx insn; | |
9350 | ||
9351 | /* This test is only important for leaf functions. */ | |
5895f793 | 9352 | /* assert (!leaf_function_p ()); */ |
d5b7b3ae RE |
9353 | |
9354 | /* If we have already decided that far jumps may be used, | |
9355 | do not bother checking again, and always return true even if | |
9356 | it turns out that they are not being used. Once we have made | |
9357 | the decision that far jumps are present (and that hence the link | |
9358 | register will be pushed onto the stack) we cannot go back on it. */ | |
9359 | if (cfun->machine->far_jump_used) | |
9360 | return 1; | |
9361 | ||
9362 | /* If this function is not being called from the prologue/epilogue | |
9363 | generation code then it must be being called from the | |
9364 | INITIAL_ELIMINATION_OFFSET macro. */ | |
5895f793 | 9365 | if (!in_prologue) |
d5b7b3ae RE |
9366 | { |
9367 | /* In this case we know that we are being asked about the elimination | |
9368 | of the arg pointer register. If that register is not being used, | |
9369 | then there are no arguments on the stack, and we do not have to | |
9370 | worry that a far jump might force the prologue to push the link | |
9371 | register, changing the stack offsets. In this case we can just | |
9372 | return false, since the presence of far jumps in the function will | |
9373 | not affect stack offsets. | |
9374 | ||
9375 | If the arg pointer is live (or if it was live, but has now been | |
9376 | eliminated and so set to dead) then we do have to test to see if | |
9377 | the function might contain a far jump. This test can lead to some | |
9378 | false negatives, since before reload is completed, then length of | |
9379 | branch instructions is not known, so gcc defaults to returning their | |
9380 | longest length, which in turn sets the far jump attribute to true. | |
9381 | ||
9382 | A false negative will not result in bad code being generated, but it | |
9383 | will result in a needless push and pop of the link register. We | |
9384 | hope that this does not occur too often. */ | |
9385 | if (regs_ever_live [ARG_POINTER_REGNUM]) | |
9386 | cfun->machine->arg_pointer_live = 1; | |
5895f793 | 9387 | else if (!cfun->machine->arg_pointer_live) |
d5b7b3ae RE |
9388 | return 0; |
9389 | } | |
9390 | ||
9391 | /* Check to see if the function contains a branch | |
9392 | insn with the far jump attribute set. */ | |
9393 | for (insn = get_insns (); insn; insn = NEXT_INSN (insn)) | |
9394 | { | |
9395 | if (GET_CODE (insn) == JUMP_INSN | |
9396 | /* Ignore tablejump patterns. */ | |
9397 | && GET_CODE (PATTERN (insn)) != ADDR_VEC | |
9398 | && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC | |
9399 | && get_attr_far_jump (insn) == FAR_JUMP_YES | |
9400 | ) | |
9401 | { | |
9402 | /* Record the fact that we have decied that | |
9403 | the function does use far jumps. */ | |
9404 | cfun->machine->far_jump_used = 1; | |
9405 | return 1; | |
9406 | } | |
9407 | } | |
9408 | ||
9409 | return 0; | |
9410 | } | |
9411 | ||
9412 | /* Return non-zero if FUNC must be entered in ARM mode. */ | |
9413 | int | |
9414 | is_called_in_ARM_mode (func) | |
9415 | tree func; | |
9416 | { | |
9417 | if (TREE_CODE (func) != FUNCTION_DECL) | |
9418 | abort (); | |
9419 | ||
9420 | /* Ignore the problem about functions whoes address is taken. */ | |
9421 | if (TARGET_CALLEE_INTERWORKING && TREE_PUBLIC (func)) | |
9422 | return TRUE; | |
9423 | ||
9424 | #ifdef ARM_PE | |
9425 | return lookup_attribute ("interfacearm", DECL_MACHINE_ATTRIBUTES (func)) != NULL_TREE; | |
9426 | #else | |
9427 | return FALSE; | |
9428 | #endif | |
9429 | } | |
9430 | ||
9431 | /* The bits which aren't usefully expanded as rtl. */ | |
400500c4 | 9432 | |
cd2b33d0 | 9433 | const char * |
d5b7b3ae RE |
9434 | thumb_unexpanded_epilogue () |
9435 | { | |
9436 | int regno; | |
9437 | int live_regs_mask = 0; | |
9438 | int high_regs_pushed = 0; | |
9439 | int leaf_function = leaf_function_p (); | |
9440 | int had_to_push_lr; | |
9441 | rtx eh_ofs = cfun->machine->eh_epilogue_sp_ofs; | |
9442 | ||
9443 | if (return_used_this_function) | |
9444 | return ""; | |
9445 | ||
9446 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
5895f793 RE |
9447 | if (regs_ever_live[regno] && !call_used_regs[regno] |
9448 | && !(TARGET_SINGLE_PIC_BASE && (regno == arm_pic_register))) | |
d5b7b3ae RE |
9449 | live_regs_mask |= 1 << regno; |
9450 | ||
9451 | for (regno = 8; regno < 13; regno++) | |
9452 | { | |
5895f793 RE |
9453 | if (regs_ever_live[regno] && !call_used_regs[regno] |
9454 | && !(TARGET_SINGLE_PIC_BASE && (regno == arm_pic_register))) | |
9455 | high_regs_pushed++; | |
d5b7b3ae RE |
9456 | } |
9457 | ||
9458 | /* The prolog may have pushed some high registers to use as | |
9459 | work registers. eg the testuite file: | |
9460 | gcc/testsuite/gcc/gcc.c-torture/execute/complex-2.c | |
9461 | compiles to produce: | |
9462 | push {r4, r5, r6, r7, lr} | |
9463 | mov r7, r9 | |
9464 | mov r6, r8 | |
9465 | push {r6, r7} | |
9466 | as part of the prolog. We have to undo that pushing here. */ | |
9467 | ||
9468 | if (high_regs_pushed) | |
9469 | { | |
9470 | int mask = live_regs_mask; | |
9471 | int next_hi_reg; | |
9472 | int size; | |
9473 | int mode; | |
9474 | ||
9475 | #ifdef RTX_CODE | |
9476 | /* If we can deduce the registers used from the function's return value. | |
9477 | This is more reliable that examining regs_ever_live[] because that | |
9478 | will be set if the register is ever used in the function, not just if | |
9479 | the register is used to hold a return value. */ | |
9480 | ||
9481 | if (current_function_return_rtx != 0) | |
9482 | mode = GET_MODE (current_function_return_rtx); | |
9483 | else | |
9484 | #endif | |
9485 | mode = DECL_MODE (DECL_RESULT (current_function_decl)); | |
9486 | ||
9487 | size = GET_MODE_SIZE (mode); | |
9488 | ||
9489 | /* Unless we are returning a type of size > 12 register r3 is | |
9490 | available. */ | |
9491 | if (size < 13) | |
9492 | mask |= 1 << 3; | |
9493 | ||
9494 | if (mask == 0) | |
9495 | /* Oh dear! We have no low registers into which we can pop | |
9496 | high registers! */ | |
400500c4 RK |
9497 | internal_error |
9498 | ("no low registers available for popping high registers"); | |
d5b7b3ae RE |
9499 | |
9500 | for (next_hi_reg = 8; next_hi_reg < 13; next_hi_reg++) | |
5895f793 RE |
9501 | if (regs_ever_live[next_hi_reg] && !call_used_regs[next_hi_reg] |
9502 | && !(TARGET_SINGLE_PIC_BASE && (next_hi_reg == arm_pic_register))) | |
d5b7b3ae RE |
9503 | break; |
9504 | ||
9505 | while (high_regs_pushed) | |
9506 | { | |
9507 | /* Find lo register(s) into which the high register(s) can | |
9508 | be popped. */ | |
9509 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
9510 | { | |
9511 | if (mask & (1 << regno)) | |
9512 | high_regs_pushed--; | |
9513 | if (high_regs_pushed == 0) | |
9514 | break; | |
9515 | } | |
9516 | ||
9517 | mask &= (2 << regno) - 1; /* A noop if regno == 8 */ | |
9518 | ||
9519 | /* Pop the values into the low register(s). */ | |
9520 | thumb_pushpop (asm_out_file, mask, 0); | |
9521 | ||
9522 | /* Move the value(s) into the high registers. */ | |
9523 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) | |
9524 | { | |
9525 | if (mask & (1 << regno)) | |
9526 | { | |
9527 | asm_fprintf (asm_out_file, "\tmov\t%r, %r\n", next_hi_reg, | |
9528 | regno); | |
9529 | ||
9530 | for (next_hi_reg++; next_hi_reg < 13; next_hi_reg++) | |
5895f793 RE |
9531 | if (regs_ever_live[next_hi_reg] |
9532 | && !call_used_regs[next_hi_reg] | |
9533 | && !(TARGET_SINGLE_PIC_BASE | |
9534 | && (next_hi_reg == arm_pic_register))) | |
d5b7b3ae RE |
9535 | break; |
9536 | } | |
9537 | } | |
9538 | } | |
9539 | } | |
9540 | ||
5895f793 | 9541 | had_to_push_lr = (live_regs_mask || !leaf_function |
d5b7b3ae RE |
9542 | || thumb_far_jump_used_p (1)); |
9543 | ||
9544 | if (TARGET_BACKTRACE | |
9545 | && ((live_regs_mask & 0xFF) == 0) | |
9546 | && regs_ever_live [LAST_ARG_REGNUM] != 0) | |
9547 | { | |
9548 | /* The stack backtrace structure creation code had to | |
9549 | push R7 in order to get a work register, so we pop | |
9550 | it now. */ | |
9551 | live_regs_mask |= (1 << LAST_LO_REGNUM); | |
9552 | } | |
9553 | ||
9554 | if (current_function_pretend_args_size == 0 || TARGET_BACKTRACE) | |
9555 | { | |
9556 | if (had_to_push_lr | |
5895f793 RE |
9557 | && !is_called_in_ARM_mode (current_function_decl) |
9558 | && !eh_ofs) | |
d5b7b3ae RE |
9559 | live_regs_mask |= 1 << PC_REGNUM; |
9560 | ||
9561 | /* Either no argument registers were pushed or a backtrace | |
9562 | structure was created which includes an adjusted stack | |
9563 | pointer, so just pop everything. */ | |
9564 | if (live_regs_mask) | |
9565 | thumb_pushpop (asm_out_file, live_regs_mask, FALSE); | |
9566 | ||
9567 | if (eh_ofs) | |
9568 | thumb_exit (asm_out_file, 2, eh_ofs); | |
9569 | /* We have either just popped the return address into the | |
9570 | PC or it is was kept in LR for the entire function or | |
9571 | it is still on the stack because we do not want to | |
9572 | return by doing a pop {pc}. */ | |
9573 | else if ((live_regs_mask & (1 << PC_REGNUM)) == 0) | |
9574 | thumb_exit (asm_out_file, | |
9575 | (had_to_push_lr | |
9576 | && is_called_in_ARM_mode (current_function_decl)) ? | |
9577 | -1 : LR_REGNUM, NULL_RTX); | |
9578 | } | |
9579 | else | |
9580 | { | |
9581 | /* Pop everything but the return address. */ | |
5895f793 | 9582 | live_regs_mask &= ~(1 << PC_REGNUM); |
d5b7b3ae RE |
9583 | |
9584 | if (live_regs_mask) | |
9585 | thumb_pushpop (asm_out_file, live_regs_mask, FALSE); | |
9586 | ||
9587 | if (had_to_push_lr) | |
9588 | /* Get the return address into a temporary register. */ | |
9589 | thumb_pushpop (asm_out_file, 1 << LAST_ARG_REGNUM, 0); | |
9590 | ||
9591 | /* Remove the argument registers that were pushed onto the stack. */ | |
9592 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, #%d\n", | |
9593 | SP_REGNUM, SP_REGNUM, | |
9594 | current_function_pretend_args_size); | |
9595 | ||
9596 | if (eh_ofs) | |
9597 | thumb_exit (asm_out_file, 2, eh_ofs); | |
9598 | else | |
9599 | thumb_exit (asm_out_file, | |
9600 | had_to_push_lr ? LAST_ARG_REGNUM : LR_REGNUM, NULL_RTX); | |
9601 | } | |
9602 | ||
9603 | return ""; | |
9604 | } | |
9605 | ||
9606 | /* Functions to save and restore machine-specific function data. */ | |
9607 | ||
9608 | static void | |
9609 | arm_mark_machine_status (p) | |
9610 | struct function * p; | |
9611 | { | |
6d3d9133 | 9612 | machine_function *machine = p->machine; |
d5b7b3ae | 9613 | |
f7a80099 NC |
9614 | if (machine) |
9615 | { | |
9616 | ggc_mark_rtx (machine->ra_rtx); | |
9617 | ggc_mark_rtx (machine->eh_epilogue_sp_ofs); | |
9618 | } | |
d5b7b3ae RE |
9619 | } |
9620 | ||
9621 | static void | |
9622 | arm_init_machine_status (p) | |
9623 | struct function * p; | |
9624 | { | |
9625 | p->machine = | |
6d3d9133 NC |
9626 | (machine_function *) xcalloc (1, sizeof (machine_function)); |
9627 | ||
9628 | #if ARM_FT_UNKNOWWN != 0 | |
9629 | ((machine_function *) p->machine)->func_type = ARM_FT_UNKNOWN; | |
9630 | #endif | |
d5b7b3ae RE |
9631 | } |
9632 | ||
f7a80099 NC |
9633 | static void |
9634 | arm_free_machine_status (p) | |
9635 | struct function * p; | |
9636 | { | |
9637 | if (p->machine) | |
9638 | { | |
9639 | free (p->machine); | |
9640 | p->machine = NULL; | |
9641 | } | |
9642 | } | |
9643 | ||
d5b7b3ae RE |
9644 | /* Return an RTX indicating where the return address to the |
9645 | calling function can be found. */ | |
9646 | rtx | |
9647 | arm_return_addr (count, frame) | |
9648 | int count; | |
9649 | rtx frame ATTRIBUTE_UNUSED; | |
9650 | { | |
9651 | rtx reg; | |
9652 | ||
9653 | if (count != 0) | |
9654 | return NULL_RTX; | |
9655 | ||
9656 | reg = cfun->machine->ra_rtx; | |
9657 | ||
9658 | if (reg == NULL) | |
9659 | { | |
9660 | rtx init; | |
9661 | ||
9662 | /* No rtx yet. Invent one, and initialize it for r14 (lr) in | |
9663 | the prologue. */ | |
9664 | reg = gen_reg_rtx (Pmode); | |
9665 | cfun->machine->ra_rtx = reg; | |
9666 | ||
5895f793 | 9667 | if (!TARGET_APCS_32) |
d5b7b3ae RE |
9668 | init = gen_rtx_AND (Pmode, gen_rtx_REG (Pmode, LR_REGNUM), |
9669 | GEN_INT (RETURN_ADDR_MASK26)); | |
9670 | else | |
9671 | init = gen_rtx_REG (Pmode, LR_REGNUM); | |
9672 | ||
9673 | init = gen_rtx_SET (VOIDmode, reg, init); | |
9674 | ||
9675 | /* Emit the insn to the prologue with the other argument copies. */ | |
9676 | push_topmost_sequence (); | |
9677 | emit_insn_after (init, get_insns ()); | |
9678 | pop_topmost_sequence (); | |
9679 | } | |
9680 | ||
9681 | return reg; | |
9682 | } | |
9683 | ||
9684 | /* Do anything needed before RTL is emitted for each function. */ | |
9685 | void | |
9686 | arm_init_expanders () | |
9687 | { | |
9688 | /* Arrange to initialize and mark the machine per-function status. */ | |
9689 | init_machine_status = arm_init_machine_status; | |
9690 | mark_machine_status = arm_mark_machine_status; | |
f7a80099 | 9691 | free_machine_status = arm_free_machine_status; |
d5b7b3ae RE |
9692 | } |
9693 | ||
9694 | /* Generate the rest of a function's prologue. */ | |
9695 | void | |
9696 | thumb_expand_prologue () | |
9697 | { | |
9698 | HOST_WIDE_INT amount = (get_frame_size () | |
9699 | + current_function_outgoing_args_size); | |
6d3d9133 NC |
9700 | unsigned long func_type; |
9701 | ||
9702 | func_type = arm_current_func_type (); | |
d5b7b3ae RE |
9703 | |
9704 | /* Naked functions don't have prologues. */ | |
6d3d9133 | 9705 | if (IS_NAKED (func_type)) |
d5b7b3ae RE |
9706 | return; |
9707 | ||
6d3d9133 NC |
9708 | if (IS_INTERRUPT (func_type)) |
9709 | { | |
9710 | error ("Interrupt Service Routines cannot be coded in Thumb mode."); | |
9711 | return; | |
9712 | } | |
9713 | ||
d5b7b3ae RE |
9714 | if (frame_pointer_needed) |
9715 | emit_insn (gen_movsi (hard_frame_pointer_rtx, stack_pointer_rtx)); | |
9716 | ||
9717 | if (amount) | |
9718 | { | |
9719 | amount = ROUND_UP (amount); | |
9720 | ||
9721 | if (amount < 512) | |
9722 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
5895f793 | 9723 | GEN_INT (-amount))); |
d5b7b3ae RE |
9724 | else |
9725 | { | |
9726 | int regno; | |
9727 | rtx reg; | |
9728 | ||
9729 | /* The stack decrement is too big for an immediate value in a single | |
9730 | insn. In theory we could issue multiple subtracts, but after | |
9731 | three of them it becomes more space efficient to place the full | |
9732 | value in the constant pool and load into a register. (Also the | |
9733 | ARM debugger really likes to see only one stack decrement per | |
9734 | function). So instead we look for a scratch register into which | |
9735 | we can load the decrement, and then we subtract this from the | |
9736 | stack pointer. Unfortunately on the thumb the only available | |
9737 | scratch registers are the argument registers, and we cannot use | |
9738 | these as they may hold arguments to the function. Instead we | |
9739 | attempt to locate a call preserved register which is used by this | |
9740 | function. If we can find one, then we know that it will have | |
9741 | been pushed at the start of the prologue and so we can corrupt | |
9742 | it now. */ | |
9743 | for (regno = LAST_ARG_REGNUM + 1; regno <= LAST_LO_REGNUM; regno++) | |
9744 | if (regs_ever_live[regno] | |
5895f793 RE |
9745 | && !call_used_regs[regno] /* Paranoia */ |
9746 | && !(TARGET_SINGLE_PIC_BASE && (regno == arm_pic_register)) | |
9747 | && !(frame_pointer_needed | |
9748 | && (regno == THUMB_HARD_FRAME_POINTER_REGNUM))) | |
d5b7b3ae RE |
9749 | break; |
9750 | ||
9751 | if (regno > LAST_LO_REGNUM) /* Very unlikely */ | |
9752 | { | |
9753 | rtx spare = gen_rtx (REG, SImode, IP_REGNUM); | |
9754 | ||
9755 | /* Choose an arbitary, non-argument low register. */ | |
9756 | reg = gen_rtx (REG, SImode, LAST_LO_REGNUM); | |
9757 | ||
9758 | /* Save it by copying it into a high, scratch register. */ | |
9759 | emit_insn (gen_movsi (spare, reg)); | |
9760 | ||
9761 | /* Decrement the stack. */ | |
5895f793 | 9762 | emit_insn (gen_movsi (reg, GEN_INT (-amount))); |
d5b7b3ae RE |
9763 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
9764 | reg)); | |
9765 | ||
9766 | /* Restore the low register's original value. */ | |
9767 | emit_insn (gen_movsi (reg, spare)); | |
9768 | ||
9769 | /* Emit a USE of the restored scratch register, so that flow | |
9770 | analysis will not consider the restore redundant. The | |
9771 | register won't be used again in this function and isn't | |
9772 | restored by the epilogue. */ | |
9773 | emit_insn (gen_rtx_USE (VOIDmode, reg)); | |
9774 | } | |
9775 | else | |
9776 | { | |
9777 | reg = gen_rtx (REG, SImode, regno); | |
9778 | ||
5895f793 | 9779 | emit_insn (gen_movsi (reg, GEN_INT (-amount))); |
d5b7b3ae RE |
9780 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, |
9781 | reg)); | |
9782 | } | |
9783 | } | |
9784 | } | |
9785 | ||
9786 | if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO) | |
9787 | emit_insn (gen_blockage ()); | |
9788 | } | |
9789 | ||
9790 | void | |
9791 | thumb_expand_epilogue () | |
9792 | { | |
9793 | HOST_WIDE_INT amount = (get_frame_size () | |
9794 | + current_function_outgoing_args_size); | |
6d3d9133 NC |
9795 | |
9796 | /* Naked functions don't have prologues. */ | |
9797 | if (IS_NAKED (arm_current_func_type ())) | |
d5b7b3ae RE |
9798 | return; |
9799 | ||
9800 | if (frame_pointer_needed) | |
9801 | emit_insn (gen_movsi (stack_pointer_rtx, hard_frame_pointer_rtx)); | |
9802 | else if (amount) | |
9803 | { | |
9804 | amount = ROUND_UP (amount); | |
9805 | ||
9806 | if (amount < 512) | |
9807 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, | |
9808 | GEN_INT (amount))); | |
9809 | else | |
9810 | { | |
9811 | /* r3 is always free in the epilogue. */ | |
9812 | rtx reg = gen_rtx (REG, SImode, LAST_ARG_REGNUM); | |
9813 | ||
9814 | emit_insn (gen_movsi (reg, GEN_INT (amount))); | |
9815 | emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx, reg)); | |
9816 | } | |
9817 | } | |
9818 | ||
9819 | /* Emit a USE (stack_pointer_rtx), so that | |
9820 | the stack adjustment will not be deleted. */ | |
9821 | emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx)); | |
9822 | ||
9823 | if (profile_flag || profile_block_flag || TARGET_NO_SCHED_PRO) | |
9824 | emit_insn (gen_blockage ()); | |
9825 | } | |
9826 | ||
9827 | void | |
9828 | output_thumb_prologue (f) | |
9829 | FILE * f; | |
9830 | { | |
9831 | int live_regs_mask = 0; | |
9832 | int high_regs_pushed = 0; | |
d5b7b3ae RE |
9833 | int regno; |
9834 | ||
6d3d9133 | 9835 | if (IS_NAKED (arm_current_func_type ())) |
d5b7b3ae RE |
9836 | return; |
9837 | ||
9838 | if (is_called_in_ARM_mode (current_function_decl)) | |
9839 | { | |
9840 | const char * name; | |
9841 | ||
9842 | if (GET_CODE (DECL_RTL (current_function_decl)) != MEM) | |
9843 | abort (); | |
9844 | if (GET_CODE (XEXP (DECL_RTL (current_function_decl), 0)) != SYMBOL_REF) | |
9845 | abort (); | |
9846 | name = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0); | |
9847 | ||
9848 | /* Generate code sequence to switch us into Thumb mode. */ | |
9849 | /* The .code 32 directive has already been emitted by | |
6d77b53e | 9850 | ASM_DECLARE_FUNCTION_NAME. */ |
d5b7b3ae RE |
9851 | asm_fprintf (f, "\torr\t%r, %r, #1\n", IP_REGNUM, PC_REGNUM); |
9852 | asm_fprintf (f, "\tbx\t%r\n", IP_REGNUM); | |
9853 | ||
9854 | /* Generate a label, so that the debugger will notice the | |
9855 | change in instruction sets. This label is also used by | |
9856 | the assembler to bypass the ARM code when this function | |
9857 | is called from a Thumb encoded function elsewhere in the | |
9858 | same file. Hence the definition of STUB_NAME here must | |
9859 | agree with the definition in gas/config/tc-arm.c */ | |
9860 | ||
9861 | #define STUB_NAME ".real_start_of" | |
9862 | ||
9863 | asm_fprintf (f, "\t.code\t16\n"); | |
9864 | #ifdef ARM_PE | |
9865 | if (arm_dllexport_name_p (name)) | |
e5951263 | 9866 | name = arm_strip_name_encoding (name); |
d5b7b3ae RE |
9867 | #endif |
9868 | asm_fprintf (f, "\t.globl %s%U%s\n", STUB_NAME, name); | |
9869 | asm_fprintf (f, "\t.thumb_func\n"); | |
9870 | asm_fprintf (f, "%s%U%s:\n", STUB_NAME, name); | |
9871 | } | |
9872 | ||
d5b7b3ae RE |
9873 | if (current_function_pretend_args_size) |
9874 | { | |
6d3d9133 | 9875 | if (current_function_anonymous_args) |
d5b7b3ae RE |
9876 | { |
9877 | int num_pushes; | |
9878 | ||
9879 | asm_fprintf (f, "\tpush\t{"); | |
9880 | ||
9881 | num_pushes = NUM_INTS (current_function_pretend_args_size); | |
9882 | ||
9883 | for (regno = LAST_ARG_REGNUM + 1 - num_pushes; | |
9884 | regno <= LAST_ARG_REGNUM; | |
5895f793 | 9885 | regno++) |
d5b7b3ae RE |
9886 | asm_fprintf (f, "%r%s", regno, |
9887 | regno == LAST_ARG_REGNUM ? "" : ", "); | |
9888 | ||
9889 | asm_fprintf (f, "}\n"); | |
9890 | } | |
9891 | else | |
9892 | asm_fprintf (f, "\tsub\t%r, %r, #%d\n", | |
9893 | SP_REGNUM, SP_REGNUM, | |
9894 | current_function_pretend_args_size); | |
9895 | } | |
9896 | ||
5895f793 RE |
9897 | for (regno = 0; regno <= LAST_LO_REGNUM; regno++) |
9898 | if (regs_ever_live[regno] && !call_used_regs[regno] | |
9899 | && !(TARGET_SINGLE_PIC_BASE && (regno == arm_pic_register))) | |
d5b7b3ae RE |
9900 | live_regs_mask |= 1 << regno; |
9901 | ||
5895f793 | 9902 | if (live_regs_mask || !leaf_function_p () || thumb_far_jump_used_p (1)) |
d5b7b3ae RE |
9903 | live_regs_mask |= 1 << LR_REGNUM; |
9904 | ||
9905 | if (TARGET_BACKTRACE) | |
9906 | { | |
9907 | int offset; | |
9908 | int work_register = 0; | |
9909 | int wr; | |
9910 | ||
9911 | /* We have been asked to create a stack backtrace structure. | |
9912 | The code looks like this: | |
9913 | ||
9914 | 0 .align 2 | |
9915 | 0 func: | |
9916 | 0 sub SP, #16 Reserve space for 4 registers. | |
9917 | 2 push {R7} Get a work register. | |
9918 | 4 add R7, SP, #20 Get the stack pointer before the push. | |
9919 | 6 str R7, [SP, #8] Store the stack pointer (before reserving the space). | |
9920 | 8 mov R7, PC Get hold of the start of this code plus 12. | |
9921 | 10 str R7, [SP, #16] Store it. | |
9922 | 12 mov R7, FP Get hold of the current frame pointer. | |
9923 | 14 str R7, [SP, #4] Store it. | |
9924 | 16 mov R7, LR Get hold of the current return address. | |
9925 | 18 str R7, [SP, #12] Store it. | |
9926 | 20 add R7, SP, #16 Point at the start of the backtrace structure. | |
9927 | 22 mov FP, R7 Put this value into the frame pointer. */ | |
9928 | ||
9929 | if ((live_regs_mask & 0xFF) == 0) | |
9930 | { | |
9931 | /* See if the a4 register is free. */ | |
9932 | ||
9933 | if (regs_ever_live [LAST_ARG_REGNUM] == 0) | |
9934 | work_register = LAST_ARG_REGNUM; | |
9935 | else /* We must push a register of our own */ | |
9936 | live_regs_mask |= (1 << LAST_LO_REGNUM); | |
9937 | } | |
9938 | ||
9939 | if (work_register == 0) | |
9940 | { | |
9941 | /* Select a register from the list that will be pushed to | |
9942 | use as our work register. */ | |
9943 | for (work_register = (LAST_LO_REGNUM + 1); work_register--;) | |
9944 | if ((1 << work_register) & live_regs_mask) | |
9945 | break; | |
9946 | } | |
9947 | ||
9948 | asm_fprintf | |
9949 | (f, "\tsub\t%r, %r, #16\t%@ Create stack backtrace structure\n", | |
9950 | SP_REGNUM, SP_REGNUM); | |
9951 | ||
9952 | if (live_regs_mask) | |
9953 | thumb_pushpop (f, live_regs_mask, 1); | |
9954 | ||
9955 | for (offset = 0, wr = 1 << 15; wr != 0; wr >>= 1) | |
9956 | if (wr & live_regs_mask) | |
9957 | offset += 4; | |
9958 | ||
9959 | asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM, | |
9960 | offset + 16 + current_function_pretend_args_size); | |
9961 | ||
9962 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9963 | offset + 4); | |
9964 | ||
9965 | /* Make sure that the instruction fetching the PC is in the right place | |
9966 | to calculate "start of backtrace creation code + 12". */ | |
9967 | if (live_regs_mask) | |
9968 | { | |
9969 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM); | |
9970 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9971 | offset + 12); | |
9972 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, | |
9973 | ARM_HARD_FRAME_POINTER_REGNUM); | |
9974 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9975 | offset); | |
9976 | } | |
9977 | else | |
9978 | { | |
9979 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, | |
9980 | ARM_HARD_FRAME_POINTER_REGNUM); | |
9981 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9982 | offset); | |
9983 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, PC_REGNUM); | |
9984 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9985 | offset + 12); | |
9986 | } | |
9987 | ||
9988 | asm_fprintf (f, "\tmov\t%r, %r\n", work_register, LR_REGNUM); | |
9989 | asm_fprintf (f, "\tstr\t%r, [%r, #%d]\n", work_register, SP_REGNUM, | |
9990 | offset + 8); | |
9991 | asm_fprintf (f, "\tadd\t%r, %r, #%d\n", work_register, SP_REGNUM, | |
9992 | offset + 12); | |
9993 | asm_fprintf (f, "\tmov\t%r, %r\t\t%@ Backtrace structure created\n", | |
9994 | ARM_HARD_FRAME_POINTER_REGNUM, work_register); | |
9995 | } | |
9996 | else if (live_regs_mask) | |
9997 | thumb_pushpop (f, live_regs_mask, 1); | |
9998 | ||
9999 | for (regno = 8; regno < 13; regno++) | |
10000 | { | |
5895f793 RE |
10001 | if (regs_ever_live[regno] && !call_used_regs[regno] |
10002 | && !(TARGET_SINGLE_PIC_BASE && (regno == arm_pic_register))) | |
10003 | high_regs_pushed++; | |
d5b7b3ae RE |
10004 | } |
10005 | ||
10006 | if (high_regs_pushed) | |
10007 | { | |
10008 | int pushable_regs = 0; | |
10009 | int mask = live_regs_mask & 0xff; | |
10010 | int next_hi_reg; | |
10011 | ||
10012 | for (next_hi_reg = 12; next_hi_reg > LAST_LO_REGNUM; next_hi_reg--) | |
10013 | { | |
5895f793 RE |
10014 | if (regs_ever_live[next_hi_reg] && !call_used_regs[next_hi_reg] |
10015 | && !(TARGET_SINGLE_PIC_BASE | |
10016 | && (next_hi_reg == arm_pic_register))) | |
d5b7b3ae RE |
10017 | break; |
10018 | } | |
10019 | ||
10020 | pushable_regs = mask; | |
10021 | ||
10022 | if (pushable_regs == 0) | |
10023 | { | |
10024 | /* Desperation time -- this probably will never happen. */ | |
10025 | if (regs_ever_live[LAST_ARG_REGNUM] | |
5895f793 | 10026 | || !call_used_regs[LAST_ARG_REGNUM]) |
d5b7b3ae RE |
10027 | asm_fprintf (f, "\tmov\t%r, %r\n", IP_REGNUM, LAST_ARG_REGNUM); |
10028 | mask = 1 << LAST_ARG_REGNUM; | |
10029 | } | |
10030 | ||
10031 | while (high_regs_pushed > 0) | |
10032 | { | |
10033 | for (regno = LAST_LO_REGNUM; regno >= 0; regno--) | |
10034 | { | |
10035 | if (mask & (1 << regno)) | |
10036 | { | |
10037 | asm_fprintf (f, "\tmov\t%r, %r\n", regno, next_hi_reg); | |
10038 | ||
5895f793 | 10039 | high_regs_pushed--; |
d5b7b3ae RE |
10040 | |
10041 | if (high_regs_pushed) | |
10042 | for (next_hi_reg--; next_hi_reg > LAST_LO_REGNUM; | |
10043 | next_hi_reg--) | |
10044 | { | |
10045 | if (regs_ever_live[next_hi_reg] | |
5895f793 RE |
10046 | && !call_used_regs[next_hi_reg] |
10047 | && !(TARGET_SINGLE_PIC_BASE | |
10048 | && (next_hi_reg == arm_pic_register))) | |
d5b7b3ae RE |
10049 | break; |
10050 | } | |
10051 | else | |
10052 | { | |
5895f793 | 10053 | mask &= ~((1 << regno) - 1); |
d5b7b3ae RE |
10054 | break; |
10055 | } | |
10056 | } | |
10057 | } | |
10058 | ||
10059 | thumb_pushpop (f, mask, 1); | |
10060 | } | |
10061 | ||
10062 | if (pushable_regs == 0 | |
10063 | && (regs_ever_live[LAST_ARG_REGNUM] | |
5895f793 | 10064 | || !call_used_regs[LAST_ARG_REGNUM])) |
d5b7b3ae RE |
10065 | asm_fprintf (f, "\tmov\t%r, %r\n", LAST_ARG_REGNUM, IP_REGNUM); |
10066 | } | |
10067 | } | |
10068 | ||
10069 | /* Handle the case of a double word load into a low register from | |
10070 | a computed memory address. The computed address may involve a | |
10071 | register which is overwritten by the load. */ | |
10072 | ||
cd2b33d0 | 10073 | const char * |
d5b7b3ae | 10074 | thumb_load_double_from_address (operands) |
400500c4 | 10075 | rtx *operands; |
d5b7b3ae RE |
10076 | { |
10077 | rtx addr; | |
10078 | rtx base; | |
10079 | rtx offset; | |
10080 | rtx arg1; | |
10081 | rtx arg2; | |
10082 | ||
10083 | if (GET_CODE (operands[0]) != REG) | |
400500c4 | 10084 | abort (); |
d5b7b3ae RE |
10085 | |
10086 | if (GET_CODE (operands[1]) != MEM) | |
400500c4 | 10087 | abort (); |
d5b7b3ae RE |
10088 | |
10089 | /* Get the memory address. */ | |
10090 | addr = XEXP (operands[1], 0); | |
10091 | ||
10092 | /* Work out how the memory address is computed. */ | |
10093 | switch (GET_CODE (addr)) | |
10094 | { | |
10095 | case REG: | |
10096 | operands[2] = gen_rtx (MEM, SImode, | |
10097 | plus_constant (XEXP (operands[1], 0), 4)); | |
10098 | ||
10099 | if (REGNO (operands[0]) == REGNO (addr)) | |
10100 | { | |
10101 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10102 | output_asm_insn ("ldr\t%0, %1", operands); | |
10103 | } | |
10104 | else | |
10105 | { | |
10106 | output_asm_insn ("ldr\t%0, %1", operands); | |
10107 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10108 | } | |
10109 | break; | |
10110 | ||
10111 | case CONST: | |
10112 | /* Compute <address> + 4 for the high order load. */ | |
10113 | operands[2] = gen_rtx (MEM, SImode, | |
10114 | plus_constant (XEXP (operands[1], 0), 4)); | |
10115 | ||
10116 | output_asm_insn ("ldr\t%0, %1", operands); | |
10117 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10118 | break; | |
10119 | ||
10120 | case PLUS: | |
10121 | arg1 = XEXP (addr, 0); | |
10122 | arg2 = XEXP (addr, 1); | |
10123 | ||
10124 | if (CONSTANT_P (arg1)) | |
10125 | base = arg2, offset = arg1; | |
10126 | else | |
10127 | base = arg1, offset = arg2; | |
10128 | ||
10129 | if (GET_CODE (base) != REG) | |
400500c4 | 10130 | abort (); |
d5b7b3ae RE |
10131 | |
10132 | /* Catch the case of <address> = <reg> + <reg> */ | |
10133 | if (GET_CODE (offset) == REG) | |
10134 | { | |
10135 | int reg_offset = REGNO (offset); | |
10136 | int reg_base = REGNO (base); | |
10137 | int reg_dest = REGNO (operands[0]); | |
10138 | ||
10139 | /* Add the base and offset registers together into the | |
10140 | higher destination register. */ | |
10141 | asm_fprintf (asm_out_file, "\tadd\t%r, %r, %r", | |
10142 | reg_dest + 1, reg_base, reg_offset); | |
10143 | ||
10144 | /* Load the lower destination register from the address in | |
10145 | the higher destination register. */ | |
10146 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #0]", | |
10147 | reg_dest, reg_dest + 1); | |
10148 | ||
10149 | /* Load the higher destination register from its own address | |
10150 | plus 4. */ | |
10151 | asm_fprintf (asm_out_file, "\tldr\t%r, [%r, #4]", | |
10152 | reg_dest + 1, reg_dest + 1); | |
10153 | } | |
10154 | else | |
10155 | { | |
10156 | /* Compute <address> + 4 for the high order load. */ | |
10157 | operands[2] = gen_rtx (MEM, SImode, | |
10158 | plus_constant (XEXP (operands[1], 0), 4)); | |
10159 | ||
10160 | /* If the computed address is held in the low order register | |
10161 | then load the high order register first, otherwise always | |
10162 | load the low order register first. */ | |
10163 | if (REGNO (operands[0]) == REGNO (base)) | |
10164 | { | |
10165 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10166 | output_asm_insn ("ldr\t%0, %1", operands); | |
10167 | } | |
10168 | else | |
10169 | { | |
10170 | output_asm_insn ("ldr\t%0, %1", operands); | |
10171 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10172 | } | |
10173 | } | |
10174 | break; | |
10175 | ||
10176 | case LABEL_REF: | |
10177 | /* With no registers to worry about we can just load the value | |
10178 | directly. */ | |
10179 | operands[2] = gen_rtx (MEM, SImode, | |
10180 | plus_constant (XEXP (operands[1], 0), 4)); | |
10181 | ||
10182 | output_asm_insn ("ldr\t%H0, %2", operands); | |
10183 | output_asm_insn ("ldr\t%0, %1", operands); | |
10184 | break; | |
10185 | ||
10186 | default: | |
400500c4 | 10187 | abort (); |
d5b7b3ae RE |
10188 | break; |
10189 | } | |
10190 | ||
10191 | return ""; | |
10192 | } | |
10193 | ||
10194 | ||
cd2b33d0 | 10195 | const char * |
d5b7b3ae RE |
10196 | thumb_output_move_mem_multiple (n, operands) |
10197 | int n; | |
10198 | rtx * operands; | |
10199 | { | |
10200 | rtx tmp; | |
10201 | ||
10202 | switch (n) | |
10203 | { | |
10204 | case 2: | |
ca356f3a | 10205 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 10206 | { |
ca356f3a RE |
10207 | tmp = operands[4]; |
10208 | operands[4] = operands[5]; | |
10209 | operands[5] = tmp; | |
d5b7b3ae | 10210 | } |
ca356f3a RE |
10211 | output_asm_insn ("ldmia\t%1!, {%4, %5}", operands); |
10212 | output_asm_insn ("stmia\t%0!, {%4, %5}", operands); | |
d5b7b3ae RE |
10213 | break; |
10214 | ||
10215 | case 3: | |
ca356f3a | 10216 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 10217 | { |
ca356f3a RE |
10218 | tmp = operands[4]; |
10219 | operands[4] = operands[5]; | |
10220 | operands[5] = tmp; | |
d5b7b3ae | 10221 | } |
ca356f3a | 10222 | if (REGNO (operands[5]) > REGNO (operands[6])) |
d5b7b3ae | 10223 | { |
ca356f3a RE |
10224 | tmp = operands[5]; |
10225 | operands[5] = operands[6]; | |
10226 | operands[6] = tmp; | |
d5b7b3ae | 10227 | } |
ca356f3a | 10228 | if (REGNO (operands[4]) > REGNO (operands[5])) |
d5b7b3ae | 10229 | { |
ca356f3a RE |
10230 | tmp = operands[4]; |
10231 | operands[4] = operands[5]; | |
10232 | operands[5] = tmp; | |
d5b7b3ae RE |
10233 | } |
10234 | ||
ca356f3a RE |
10235 | output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands); |
10236 | output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands); | |
d5b7b3ae RE |
10237 | break; |
10238 | ||
10239 | default: | |
10240 | abort (); | |
10241 | } | |
10242 | ||
10243 | return ""; | |
10244 | } | |
10245 | ||
10246 | /* Routines for generating rtl */ | |
10247 | ||
10248 | void | |
10249 | thumb_expand_movstrqi (operands) | |
10250 | rtx * operands; | |
10251 | { | |
10252 | rtx out = copy_to_mode_reg (SImode, XEXP (operands[0], 0)); | |
10253 | rtx in = copy_to_mode_reg (SImode, XEXP (operands[1], 0)); | |
10254 | HOST_WIDE_INT len = INTVAL (operands[2]); | |
10255 | HOST_WIDE_INT offset = 0; | |
10256 | ||
10257 | while (len >= 12) | |
10258 | { | |
ca356f3a | 10259 | emit_insn (gen_movmem12b (out, in, out, in)); |
d5b7b3ae RE |
10260 | len -= 12; |
10261 | } | |
10262 | ||
10263 | if (len >= 8) | |
10264 | { | |
ca356f3a | 10265 | emit_insn (gen_movmem8b (out, in, out, in)); |
d5b7b3ae RE |
10266 | len -= 8; |
10267 | } | |
10268 | ||
10269 | if (len >= 4) | |
10270 | { | |
10271 | rtx reg = gen_reg_rtx (SImode); | |
10272 | emit_insn (gen_movsi (reg, gen_rtx (MEM, SImode, in))); | |
10273 | emit_insn (gen_movsi (gen_rtx (MEM, SImode, out), reg)); | |
10274 | len -= 4; | |
10275 | offset += 4; | |
10276 | } | |
10277 | ||
10278 | if (len >= 2) | |
10279 | { | |
10280 | rtx reg = gen_reg_rtx (HImode); | |
10281 | emit_insn (gen_movhi (reg, gen_rtx (MEM, HImode, | |
10282 | plus_constant (in, offset)))); | |
10283 | emit_insn (gen_movhi (gen_rtx (MEM, HImode, plus_constant (out, offset)), | |
10284 | reg)); | |
10285 | len -= 2; | |
10286 | offset += 2; | |
10287 | } | |
10288 | ||
10289 | if (len) | |
10290 | { | |
10291 | rtx reg = gen_reg_rtx (QImode); | |
10292 | emit_insn (gen_movqi (reg, gen_rtx (MEM, QImode, | |
10293 | plus_constant (in, offset)))); | |
10294 | emit_insn (gen_movqi (gen_rtx (MEM, QImode, plus_constant (out, offset)), | |
10295 | reg)); | |
10296 | } | |
10297 | } | |
10298 | ||
10299 | int | |
10300 | thumb_cmp_operand (op, mode) | |
10301 | rtx op; | |
10302 | enum machine_mode mode; | |
10303 | { | |
10304 | return ((GET_CODE (op) == CONST_INT | |
10305 | && (unsigned HOST_WIDE_INT) (INTVAL (op)) < 256) | |
10306 | || register_operand (op, mode)); | |
10307 | } | |
10308 | ||
cd2b33d0 | 10309 | static const char * |
d5b7b3ae RE |
10310 | thumb_condition_code (x, invert) |
10311 | rtx x; | |
10312 | int invert; | |
10313 | { | |
cd2b33d0 | 10314 | static const char * conds[] = |
d5b7b3ae RE |
10315 | { |
10316 | "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", | |
10317 | "hi", "ls", "ge", "lt", "gt", "le" | |
10318 | }; | |
10319 | int val; | |
10320 | ||
10321 | switch (GET_CODE (x)) | |
10322 | { | |
10323 | case EQ: val = 0; break; | |
10324 | case NE: val = 1; break; | |
10325 | case GEU: val = 2; break; | |
10326 | case LTU: val = 3; break; | |
10327 | case GTU: val = 8; break; | |
10328 | case LEU: val = 9; break; | |
10329 | case GE: val = 10; break; | |
10330 | case LT: val = 11; break; | |
10331 | case GT: val = 12; break; | |
10332 | case LE: val = 13; break; | |
10333 | default: | |
10334 | abort (); | |
10335 | } | |
10336 | ||
10337 | return conds[val ^ invert]; | |
10338 | } | |
10339 | ||
10340 | /* Handle storing a half-word to memory during reload. */ | |
10341 | void | |
10342 | thumb_reload_out_hi (operands) | |
10343 | rtx * operands; | |
10344 | { | |
10345 | emit_insn (gen_thumb_movhi_clobber (operands[0], operands[1], operands[2])); | |
10346 | } | |
10347 | ||
10348 | /* Handle storing a half-word to memory during reload. */ | |
10349 | void | |
10350 | thumb_reload_in_hi (operands) | |
10351 | rtx * operands ATTRIBUTE_UNUSED; | |
10352 | { | |
10353 | abort (); | |
10354 | } | |
10355 | ||
c27ba912 DM |
10356 | /* Return the length of a function name prefix |
10357 | that starts with the character 'c'. */ | |
10358 | static int | |
10359 | arm_get_strip_length (char c) | |
10360 | { | |
10361 | switch (c) | |
10362 | { | |
10363 | ARM_NAME_ENCODING_LENGTHS | |
10364 | default: return 0; | |
10365 | } | |
10366 | } | |
10367 | ||
10368 | /* Return a pointer to a function's name with any | |
10369 | and all prefix encodings stripped from it. */ | |
10370 | const char * | |
10371 | arm_strip_name_encoding (const char * name) | |
10372 | { | |
10373 | int skip; | |
10374 | ||
10375 | while ((skip = arm_get_strip_length (* name))) | |
10376 | name += skip; | |
10377 | ||
10378 | return name; | |
10379 | } | |
10380 | ||
2b835d68 | 10381 | #ifdef AOF_ASSEMBLER |
6354dc9b | 10382 | /* Special functions only needed when producing AOF syntax assembler. */ |
2b835d68 | 10383 | |
32de079a RE |
10384 | rtx aof_pic_label = NULL_RTX; |
10385 | struct pic_chain | |
10386 | { | |
62b10bbc NC |
10387 | struct pic_chain * next; |
10388 | char * symname; | |
32de079a RE |
10389 | }; |
10390 | ||
62b10bbc | 10391 | static struct pic_chain * aof_pic_chain = NULL; |
32de079a RE |
10392 | |
10393 | rtx | |
10394 | aof_pic_entry (x) | |
10395 | rtx x; | |
10396 | { | |
62b10bbc | 10397 | struct pic_chain ** chainp; |
32de079a RE |
10398 | int offset; |
10399 | ||
10400 | if (aof_pic_label == NULL_RTX) | |
10401 | { | |
92a432f4 RE |
10402 | /* We mark this here and not in arm_add_gc_roots() to avoid |
10403 | polluting even more code with ifdefs, and because it never | |
10404 | contains anything useful until we assign to it here. */ | |
5895f793 | 10405 | ggc_add_rtx_root (&aof_pic_label, 1); |
43cffd11 | 10406 | aof_pic_label = gen_rtx_SYMBOL_REF (Pmode, "x$adcons"); |
32de079a RE |
10407 | } |
10408 | ||
10409 | for (offset = 0, chainp = &aof_pic_chain; *chainp; | |
10410 | offset += 4, chainp = &(*chainp)->next) | |
10411 | if ((*chainp)->symname == XSTR (x, 0)) | |
10412 | return plus_constant (aof_pic_label, offset); | |
10413 | ||
10414 | *chainp = (struct pic_chain *) xmalloc (sizeof (struct pic_chain)); | |
10415 | (*chainp)->next = NULL; | |
10416 | (*chainp)->symname = XSTR (x, 0); | |
10417 | return plus_constant (aof_pic_label, offset); | |
10418 | } | |
10419 | ||
10420 | void | |
10421 | aof_dump_pic_table (f) | |
62b10bbc | 10422 | FILE * f; |
32de079a | 10423 | { |
62b10bbc | 10424 | struct pic_chain * chain; |
32de079a RE |
10425 | |
10426 | if (aof_pic_chain == NULL) | |
10427 | return; | |
10428 | ||
dd18ae56 NC |
10429 | asm_fprintf (f, "\tAREA |%r$$adcons|, BASED %r\n", |
10430 | PIC_OFFSET_TABLE_REGNUM, | |
10431 | PIC_OFFSET_TABLE_REGNUM); | |
32de079a RE |
10432 | fputs ("|x$adcons|\n", f); |
10433 | ||
10434 | for (chain = aof_pic_chain; chain; chain = chain->next) | |
10435 | { | |
10436 | fputs ("\tDCD\t", f); | |
10437 | assemble_name (f, chain->symname); | |
10438 | fputs ("\n", f); | |
10439 | } | |
10440 | } | |
10441 | ||
2b835d68 RE |
10442 | int arm_text_section_count = 1; |
10443 | ||
10444 | char * | |
84ed5e79 | 10445 | aof_text_section () |
2b835d68 RE |
10446 | { |
10447 | static char buf[100]; | |
2b835d68 RE |
10448 | sprintf (buf, "\tAREA |C$$code%d|, CODE, READONLY", |
10449 | arm_text_section_count++); | |
10450 | if (flag_pic) | |
10451 | strcat (buf, ", PIC, REENTRANT"); | |
10452 | return buf; | |
10453 | } | |
10454 | ||
10455 | static int arm_data_section_count = 1; | |
10456 | ||
10457 | char * | |
10458 | aof_data_section () | |
10459 | { | |
10460 | static char buf[100]; | |
10461 | sprintf (buf, "\tAREA |C$$data%d|, DATA", arm_data_section_count++); | |
10462 | return buf; | |
10463 | } | |
10464 | ||
10465 | /* The AOF assembler is religiously strict about declarations of | |
10466 | imported and exported symbols, so that it is impossible to declare | |
956d6950 | 10467 | a function as imported near the beginning of the file, and then to |
2b835d68 RE |
10468 | export it later on. It is, however, possible to delay the decision |
10469 | until all the functions in the file have been compiled. To get | |
10470 | around this, we maintain a list of the imports and exports, and | |
10471 | delete from it any that are subsequently defined. At the end of | |
10472 | compilation we spit the remainder of the list out before the END | |
10473 | directive. */ | |
10474 | ||
10475 | struct import | |
10476 | { | |
62b10bbc NC |
10477 | struct import * next; |
10478 | char * name; | |
2b835d68 RE |
10479 | }; |
10480 | ||
62b10bbc | 10481 | static struct import * imports_list = NULL; |
2b835d68 RE |
10482 | |
10483 | void | |
10484 | aof_add_import (name) | |
62b10bbc | 10485 | char * name; |
2b835d68 | 10486 | { |
62b10bbc | 10487 | struct import * new; |
2b835d68 RE |
10488 | |
10489 | for (new = imports_list; new; new = new->next) | |
10490 | if (new->name == name) | |
10491 | return; | |
10492 | ||
10493 | new = (struct import *) xmalloc (sizeof (struct import)); | |
10494 | new->next = imports_list; | |
10495 | imports_list = new; | |
10496 | new->name = name; | |
10497 | } | |
10498 | ||
10499 | void | |
10500 | aof_delete_import (name) | |
62b10bbc | 10501 | char * name; |
2b835d68 | 10502 | { |
62b10bbc | 10503 | struct import ** old; |
2b835d68 RE |
10504 | |
10505 | for (old = &imports_list; *old; old = & (*old)->next) | |
10506 | { | |
10507 | if ((*old)->name == name) | |
10508 | { | |
10509 | *old = (*old)->next; | |
10510 | return; | |
10511 | } | |
10512 | } | |
10513 | } | |
10514 | ||
10515 | int arm_main_function = 0; | |
10516 | ||
10517 | void | |
10518 | aof_dump_imports (f) | |
62b10bbc | 10519 | FILE * f; |
2b835d68 RE |
10520 | { |
10521 | /* The AOF assembler needs this to cause the startup code to be extracted | |
10522 | from the library. Brining in __main causes the whole thing to work | |
10523 | automagically. */ | |
10524 | if (arm_main_function) | |
10525 | { | |
10526 | text_section (); | |
10527 | fputs ("\tIMPORT __main\n", f); | |
10528 | fputs ("\tDCD __main\n", f); | |
10529 | } | |
10530 | ||
10531 | /* Now dump the remaining imports. */ | |
10532 | while (imports_list) | |
10533 | { | |
10534 | fprintf (f, "\tIMPORT\t"); | |
10535 | assemble_name (f, imports_list->name); | |
10536 | fputc ('\n', f); | |
10537 | imports_list = imports_list->next; | |
10538 | } | |
10539 | } | |
10540 | #endif /* AOF_ASSEMBLER */ |