]>
Commit | Line | Data |
---|---|---|
36a05131 BS |
1 | /* Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. |
2 | Contributed by Red Hat, Inc. | |
3 | ||
7ec022b2 | 4 | This file is part of GCC. |
36a05131 | 5 | |
7ec022b2 | 6 | GCC is free software; you can redistribute it and/or modify |
36a05131 BS |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
7ec022b2 | 11 | GCC is distributed in the hope that it will be useful, |
36a05131 BS |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
7ec022b2 | 17 | along with GCC; see the file COPYING. If not, write to |
36a05131 BS |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "config.h" | |
22 | #include "system.h" | |
4977bab6 ZW |
23 | #include "coretypes.h" |
24 | #include "tm.h" | |
36a05131 BS |
25 | #include "rtl.h" |
26 | #include "tree.h" | |
27 | #include "regs.h" | |
28 | #include "hard-reg-set.h" | |
29 | #include "real.h" | |
30 | #include "insn-config.h" | |
31 | #include "conditions.h" | |
32 | #include "insn-flags.h" | |
33 | #include "output.h" | |
34 | #include "insn-attr.h" | |
35 | #include "flags.h" | |
36 | #include "recog.h" | |
37 | #include "reload.h" | |
38 | #include "expr.h" | |
39 | #include "obstack.h" | |
40 | #include "except.h" | |
41 | #include "function.h" | |
42 | #include "optabs.h" | |
43 | #include "toplev.h" | |
44 | #include "basic-block.h" | |
45 | #include "tm_p.h" | |
46 | #include "ggc.h" | |
47 | #include <ctype.h> | |
48 | #include "target.h" | |
49 | #include "target-def.h" | |
50 | ||
51 | #ifndef FRV_INLINE | |
52 | #define FRV_INLINE inline | |
53 | #endif | |
54 | ||
55 | /* Temporary register allocation support structure. */ | |
56 | typedef struct frv_tmp_reg_struct | |
57 | { | |
58 | HARD_REG_SET regs; /* possible registers to allocate */ | |
59 | int next_reg[N_REG_CLASSES]; /* next register to allocate per class */ | |
60 | } | |
61 | frv_tmp_reg_t; | |
62 | ||
63 | /* Register state information for VLIW re-packing phase. These values must fit | |
64 | within an unsigned char. */ | |
65 | #define REGSTATE_DEAD 0x00 /* register is currently dead */ | |
66 | #define REGSTATE_CC_MASK 0x07 /* Mask to isolate CCn for cond exec */ | |
67 | #define REGSTATE_LIVE 0x08 /* register is live */ | |
68 | #define REGSTATE_MODIFIED 0x10 /* reg modified in current VLIW insn */ | |
69 | #define REGSTATE_IF_TRUE 0x20 /* reg modified in cond exec true */ | |
70 | #define REGSTATE_IF_FALSE 0x40 /* reg modified in cond exec false */ | |
71 | #define REGSTATE_UNUSED 0x80 /* bit for hire */ | |
72 | #define REGSTATE_MASK 0xff /* mask for the bits to set */ | |
73 | ||
74 | /* conditional expression used */ | |
75 | #define REGSTATE_IF_EITHER (REGSTATE_IF_TRUE | REGSTATE_IF_FALSE) | |
76 | ||
77 | /* the following is not sure in the reg_state bytes, so can have a larger value | |
78 | than 0xff. */ | |
79 | #define REGSTATE_CONDJUMP 0x100 /* conditional jump done in VLIW insn */ | |
80 | ||
81 | /* Used in frv_frame_accessor_t to indicate the direction of a register-to- | |
82 | memory move. */ | |
83 | enum frv_stack_op | |
84 | { | |
85 | FRV_LOAD, | |
86 | FRV_STORE | |
87 | }; | |
88 | ||
89 | /* Information required by frv_frame_access. */ | |
90 | typedef struct | |
91 | { | |
92 | /* This field is FRV_LOAD if registers are to be loaded from the stack and | |
93 | FRV_STORE if they should be stored onto the stack. FRV_STORE implies | |
94 | the move is being done by the prologue code while FRV_LOAD implies it | |
95 | is being done by the epilogue. */ | |
96 | enum frv_stack_op op; | |
97 | ||
98 | /* The base register to use when accessing the stack. This may be the | |
99 | frame pointer, stack pointer, or a temporary. The choice of register | |
100 | depends on which part of the frame is being accessed and how big the | |
101 | frame is. */ | |
102 | rtx base; | |
103 | ||
104 | /* The offset of BASE from the bottom of the current frame, in bytes. */ | |
105 | int base_offset; | |
106 | } frv_frame_accessor_t; | |
107 | ||
108 | /* Define the information needed to generate branch and scc insns. This is | |
109 | stored from the compare operation. */ | |
110 | rtx frv_compare_op0; | |
111 | rtx frv_compare_op1; | |
112 | ||
113 | /* Conditional execution support gathered together in one structure */ | |
114 | typedef struct | |
115 | { | |
116 | /* Linked list of insns to add if the conditional execution conversion was | |
117 | successful. Each link points to an EXPR_LIST which points to the pattern | |
118 | of the insn to add, and the insn to be inserted before. */ | |
119 | rtx added_insns_list; | |
120 | ||
121 | /* Identify which registers are safe to allocate for if conversions to | |
122 | conditional execution. We keep the last allocated register in the | |
123 | register classes between COND_EXEC statements. This will mean we allocate | |
124 | different registers for each different COND_EXEC group if we can. This | |
125 | might allow the scheduler to intermix two different COND_EXEC sections. */ | |
126 | frv_tmp_reg_t tmp_reg; | |
127 | ||
128 | /* For nested IFs, identify which CC registers are used outside of setting | |
129 | via a compare isnsn, and using via a check insn. This will allow us to | |
130 | know if we can rewrite the register to use a different register that will | |
131 | be paired with the CR register controlling the nested IF-THEN blocks. */ | |
132 | HARD_REG_SET nested_cc_ok_rewrite; | |
133 | ||
134 | /* Temporary registers allocated to hold constants during conditional | |
135 | execution. */ | |
136 | rtx scratch_regs[FIRST_PSEUDO_REGISTER]; | |
137 | ||
138 | /* Current number of temp registers available. */ | |
139 | int cur_scratch_regs; | |
140 | ||
141 | /* Number of nested conditional execution blocks */ | |
142 | int num_nested_cond_exec; | |
143 | ||
144 | /* Map of insns that set up constants in scratch registers. */ | |
145 | bitmap scratch_insns_bitmap; | |
146 | ||
147 | /* Conditional execution test register (CC0..CC7) */ | |
148 | rtx cr_reg; | |
149 | ||
150 | /* Conditional execution compare register that is paired with cr_reg, so that | |
151 | nested compares can be done. The csubcc and caddcc instructions don't | |
152 | have enough bits to specify both a CC register to be set and a CR register | |
153 | to do the test on, so the same bit number is used for both. Needless to | |
154 | say, this is rather inconvient for GCC. */ | |
155 | rtx nested_cc_reg; | |
156 | ||
157 | /* Extra CR registers used for &&, ||. */ | |
158 | rtx extra_int_cr; | |
159 | rtx extra_fp_cr; | |
160 | ||
161 | /* Previous CR used in nested if, to make sure we are dealing with the same | |
162 | nested if as the previous statement. */ | |
163 | rtx last_nested_if_cr; | |
164 | } | |
165 | frv_ifcvt_t; | |
166 | ||
167 | static /* GTY(()) */ frv_ifcvt_t frv_ifcvt; | |
168 | ||
169 | /* Map register number to smallest register class. */ | |
170 | enum reg_class regno_reg_class[FIRST_PSEUDO_REGISTER]; | |
171 | ||
172 | /* Map class letter into register class */ | |
173 | enum reg_class reg_class_from_letter[256]; | |
174 | ||
175 | /* Cached value of frv_stack_info */ | |
176 | static frv_stack_t *frv_stack_cache = (frv_stack_t *)0; | |
177 | ||
178 | /* -mbranch-cost= support */ | |
179 | const char *frv_branch_cost_string; | |
180 | int frv_branch_cost_int = DEFAULT_BRANCH_COST; | |
181 | ||
182 | /* -mcpu= support */ | |
183 | const char *frv_cpu_string; /* -mcpu= option */ | |
184 | frv_cpu_t frv_cpu_type = CPU_TYPE; /* value of -mcpu= */ | |
185 | ||
186 | /* -mcond-exec-insns= support */ | |
187 | const char *frv_condexec_insns_str; /* -mcond-exec-insns= option */ | |
188 | int frv_condexec_insns = DEFAULT_CONDEXEC_INSNS; /* value of -mcond-exec-insns*/ | |
189 | ||
190 | /* -mcond-exec-temps= support */ | |
191 | const char *frv_condexec_temps_str; /* -mcond-exec-temps= option */ | |
192 | int frv_condexec_temps = DEFAULT_CONDEXEC_TEMPS; /* value of -mcond-exec-temps*/ | |
193 | ||
194 | /* -msched-lookahead=n */ | |
195 | const char *frv_sched_lookahead_str; /* -msched-lookahead=n */ | |
196 | int frv_sched_lookahead = 4; /* -msched-lookahead=n */ | |
197 | ||
198 | /* Forward references */ | |
199 | static int frv_default_flags_for_cpu PARAMS ((void)); | |
200 | static int frv_string_begins_with PARAMS ((tree, const char *)); | |
36a05131 BS |
201 | static FRV_INLINE int const_small_data_p PARAMS ((rtx)); |
202 | static FRV_INLINE int plus_small_data_p PARAMS ((rtx, rtx)); | |
203 | static void frv_print_operand_memory_reference_reg | |
204 | PARAMS ((FILE *, rtx)); | |
205 | static void frv_print_operand_memory_reference PARAMS ((FILE *, rtx, int)); | |
206 | static int frv_print_operand_jump_hint PARAMS ((rtx)); | |
207 | static FRV_INLINE int frv_regno_ok_for_base_p PARAMS ((int, int)); | |
208 | static rtx single_set_pattern PARAMS ((rtx)); | |
209 | static int frv_function_contains_far_jump PARAMS ((void)); | |
210 | static rtx frv_alloc_temp_reg PARAMS ((frv_tmp_reg_t *, | |
211 | enum reg_class, | |
212 | enum machine_mode, | |
213 | int, int)); | |
214 | static rtx frv_frame_offset_rtx PARAMS ((int)); | |
215 | static rtx frv_frame_mem PARAMS ((enum machine_mode, | |
216 | rtx, int)); | |
217 | static rtx frv_dwarf_store PARAMS ((rtx, int)); | |
218 | static void frv_frame_insn PARAMS ((rtx, rtx)); | |
219 | static void frv_frame_access PARAMS ((frv_frame_accessor_t*, | |
220 | rtx, int)); | |
221 | static void frv_frame_access_multi PARAMS ((frv_frame_accessor_t*, | |
222 | frv_stack_t *, int)); | |
223 | static void frv_frame_access_standard_regs PARAMS ((enum frv_stack_op, | |
224 | frv_stack_t *)); | |
225 | static struct machine_function *frv_init_machine_status PARAMS ((void)); | |
226 | static int frv_legitimate_memory_operand PARAMS ((rtx, | |
227 | enum machine_mode, | |
228 | int)); | |
229 | static rtx frv_int_to_acc PARAMS ((enum insn_code, | |
230 | int, rtx)); | |
231 | static enum machine_mode frv_matching_accg_mode PARAMS ((enum machine_mode)); | |
232 | static rtx frv_read_argument PARAMS ((tree *)); | |
233 | static int frv_check_constant_argument PARAMS ((enum insn_code, | |
234 | int, rtx)); | |
235 | static rtx frv_legitimize_target PARAMS ((enum insn_code, rtx)); | |
236 | static rtx frv_legitimize_argument PARAMS ((enum insn_code, | |
237 | int, rtx)); | |
238 | static rtx frv_expand_set_builtin PARAMS ((enum insn_code, | |
239 | tree, rtx)); | |
240 | static rtx frv_expand_unop_builtin PARAMS ((enum insn_code, | |
241 | tree, rtx)); | |
242 | static rtx frv_expand_binop_builtin PARAMS ((enum insn_code, | |
243 | tree, rtx)); | |
244 | static rtx frv_expand_cut_builtin PARAMS ((enum insn_code, | |
245 | tree, rtx)); | |
246 | static rtx frv_expand_binopimm_builtin PARAMS ((enum insn_code, | |
247 | tree, rtx)); | |
248 | static rtx frv_expand_voidbinop_builtin PARAMS ((enum insn_code, | |
249 | tree)); | |
250 | static rtx frv_expand_voidtriop_builtin PARAMS ((enum insn_code, | |
251 | tree)); | |
252 | static rtx frv_expand_voidaccop_builtin PARAMS ((enum insn_code, | |
253 | tree)); | |
254 | static rtx frv_expand_mclracc_builtin PARAMS ((tree)); | |
255 | static rtx frv_expand_mrdacc_builtin PARAMS ((enum insn_code, | |
256 | tree)); | |
257 | static rtx frv_expand_mwtacc_builtin PARAMS ((enum insn_code, | |
258 | tree)); | |
259 | static rtx frv_expand_noargs_builtin PARAMS ((enum insn_code)); | |
260 | static rtx frv_emit_comparison PARAMS ((enum rtx_code, rtx, | |
261 | rtx)); | |
262 | static int frv_clear_registers_used PARAMS ((rtx *, void *)); | |
263 | static void frv_ifcvt_add_insn PARAMS ((rtx, rtx, int)); | |
264 | static rtx frv_ifcvt_rewrite_mem PARAMS ((rtx, | |
265 | enum machine_mode, | |
266 | rtx)); | |
267 | static rtx frv_ifcvt_load_value PARAMS ((rtx, rtx)); | |
268 | static void frv_registers_update PARAMS ((rtx, unsigned char [], | |
269 | int [], int *, int)); | |
270 | static int frv_registers_used_p PARAMS ((rtx, unsigned char [], | |
271 | int)); | |
272 | static int frv_registers_set_p PARAMS ((rtx, unsigned char [], | |
273 | int)); | |
28a60850 | 274 | static int frv_issue_rate PARAMS ((void)); |
ffb344c1 | 275 | static int frv_use_dfa_pipeline_interface PARAMS ((void)); |
36a05131 BS |
276 | static void frv_pack_insns PARAMS ((void)); |
277 | static void frv_function_prologue PARAMS ((FILE *, HOST_WIDE_INT)); | |
278 | static void frv_function_epilogue PARAMS ((FILE *, HOST_WIDE_INT)); | |
279 | static bool frv_assemble_integer PARAMS ((rtx, unsigned, int)); | |
14966b94 KG |
280 | static void frv_init_builtins PARAMS ((void)); |
281 | static rtx frv_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int)); | |
c15c90bb | 282 | static void frv_init_libfuncs PARAMS ((void)); |
b3fbfc07 | 283 | static bool frv_in_small_data_p PARAMS ((tree)); |
3961e8fe RH |
284 | static void frv_asm_output_mi_thunk |
285 | PARAMS ((FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree)); | |
3c50106f | 286 | static bool frv_rtx_costs PARAMS ((rtx, int, int, int*)); |
90a63880 RH |
287 | static void frv_asm_out_constructor PARAMS ((rtx, int)); |
288 | static void frv_asm_out_destructor PARAMS ((rtx, int)); | |
36a05131 BS |
289 | \f |
290 | /* Initialize the GCC target structure. */ | |
291 | #undef TARGET_ASM_FUNCTION_PROLOGUE | |
292 | #define TARGET_ASM_FUNCTION_PROLOGUE frv_function_prologue | |
293 | #undef TARGET_ASM_FUNCTION_EPILOGUE | |
294 | #define TARGET_ASM_FUNCTION_EPILOGUE frv_function_epilogue | |
295 | #undef TARGET_ASM_INTEGER | |
296 | #define TARGET_ASM_INTEGER frv_assemble_integer | |
14966b94 KG |
297 | #undef TARGET_INIT_BUILTINS |
298 | #define TARGET_INIT_BUILTINS frv_init_builtins | |
299 | #undef TARGET_EXPAND_BUILTIN | |
300 | #define TARGET_EXPAND_BUILTIN frv_expand_builtin | |
c15c90bb ZW |
301 | #undef TARGET_INIT_LIBFUNCS |
302 | #define TARGET_INIT_LIBFUNCS frv_init_libfuncs | |
b3fbfc07 KG |
303 | #undef TARGET_IN_SMALL_DATA_P |
304 | #define TARGET_IN_SMALL_DATA_P frv_in_small_data_p | |
3c50106f RH |
305 | #undef TARGET_RTX_COSTS |
306 | #define TARGET_RTX_COSTS frv_rtx_costs | |
90a63880 RH |
307 | #undef TARGET_ASM_CONSTRUCTOR |
308 | #define TARGET_ASM_CONSTRUCTOR frv_asm_out_constructor | |
309 | #undef TARGET_ASM_DESTRUCTOR | |
310 | #define TARGET_ASM_DESTRUCTOR frv_asm_out_destructor | |
36a05131 | 311 | |
c590b625 RH |
312 | #undef TARGET_ASM_OUTPUT_MI_THUNK |
313 | #define TARGET_ASM_OUTPUT_MI_THUNK frv_asm_output_mi_thunk | |
3961e8fe RH |
314 | #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK |
315 | #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall | |
c590b625 | 316 | |
28a60850 RS |
317 | #undef TARGET_SCHED_ISSUE_RATE |
318 | #define TARGET_SCHED_ISSUE_RATE frv_issue_rate | |
ffb344c1 RS |
319 | #undef TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE |
320 | #define TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE frv_use_dfa_pipeline_interface | |
321 | ||
36a05131 BS |
322 | struct gcc_target targetm = TARGET_INITIALIZER; |
323 | \f | |
36a05131 BS |
324 | /* Given a CONST, return true if the symbol_ref points to small data. */ |
325 | ||
326 | static FRV_INLINE int | |
327 | const_small_data_p (x) | |
328 | rtx x; | |
329 | { | |
330 | rtx x0, x1; | |
331 | ||
332 | if (GET_CODE (XEXP (x, 0)) != PLUS) | |
333 | return FALSE; | |
334 | ||
335 | x0 = XEXP (XEXP (x, 0), 0); | |
0f6e5d45 | 336 | if (GET_CODE (x0) != SYMBOL_REF || !SYMBOL_REF_SMALL_P (x0)) |
36a05131 BS |
337 | return FALSE; |
338 | ||
339 | x1 = XEXP (XEXP (x, 0), 1); | |
340 | if (GET_CODE (x1) != CONST_INT | |
341 | || !IN_RANGE_P (INTVAL (x1), -2048, 2047)) | |
342 | return FALSE; | |
343 | ||
344 | return TRUE; | |
345 | } | |
346 | ||
347 | /* Given a PLUS, return true if this is a small data reference. */ | |
348 | ||
349 | static FRV_INLINE int | |
350 | plus_small_data_p (op0, op1) | |
351 | rtx op0; | |
352 | rtx op1; | |
353 | { | |
354 | if (GET_MODE (op0) == SImode | |
355 | && GET_CODE (op0) == REG | |
356 | && REGNO (op0) == SDA_BASE_REG) | |
357 | { | |
358 | if (GET_CODE (op1) == SYMBOL_REF) | |
0f6e5d45 | 359 | return SYMBOL_REF_SMALL_P (op1); |
36a05131 BS |
360 | |
361 | if (GET_CODE (op1) == CONST) | |
362 | return const_small_data_p (op1); | |
363 | } | |
364 | ||
365 | return FALSE; | |
366 | } | |
367 | ||
368 | \f | |
369 | static int | |
370 | frv_default_flags_for_cpu () | |
371 | { | |
372 | switch (frv_cpu_type) | |
373 | { | |
374 | case FRV_CPU_GENERIC: | |
375 | return MASK_DEFAULT_FRV; | |
376 | ||
377 | case FRV_CPU_FR500: | |
378 | case FRV_CPU_TOMCAT: | |
379 | return MASK_DEFAULT_FR500; | |
380 | ||
381 | case FRV_CPU_FR400: | |
382 | return MASK_DEFAULT_FR400; | |
383 | ||
384 | case FRV_CPU_FR300: | |
385 | case FRV_CPU_SIMPLE: | |
386 | return MASK_DEFAULT_SIMPLE; | |
387 | } | |
388 | abort (); | |
389 | } | |
390 | ||
391 | /* Sometimes certain combinations of command options do not make | |
392 | sense on a particular target machine. You can define a macro | |
393 | `OVERRIDE_OPTIONS' to take account of this. This macro, if | |
394 | defined, is executed once just after all the command options have | |
395 | been parsed. | |
396 | ||
397 | Don't use this macro to turn on various extra optimizations for | |
398 | `-O'. That is what `OPTIMIZATION_OPTIONS' is for. */ | |
399 | ||
400 | void | |
401 | frv_override_options () | |
402 | { | |
403 | int regno, i; | |
404 | ||
405 | /* Set the cpu type */ | |
406 | if (frv_cpu_string) | |
407 | { | |
408 | if (strcmp (frv_cpu_string, "simple") == 0) | |
409 | frv_cpu_type = FRV_CPU_SIMPLE; | |
410 | ||
411 | else if (strcmp (frv_cpu_string, "tomcat") == 0) | |
412 | frv_cpu_type = FRV_CPU_TOMCAT; | |
413 | ||
414 | else if (strncmp (frv_cpu_string, "fr", sizeof ("fr")-1) != 0) | |
415 | error ("Unknown cpu: -mcpu=%s", frv_cpu_string); | |
416 | ||
417 | else | |
418 | { | |
419 | const char *p = frv_cpu_string + sizeof ("fr") - 1; | |
420 | if (strcmp (p, "500") == 0) | |
421 | frv_cpu_type = FRV_CPU_FR500; | |
422 | ||
423 | else if (strcmp (p, "400") == 0) | |
424 | frv_cpu_type = FRV_CPU_FR400; | |
425 | ||
426 | else if (strcmp (p, "300") == 0) | |
427 | frv_cpu_type = FRV_CPU_FR300; | |
428 | ||
429 | else if (strcmp (p, "v") == 0) | |
430 | frv_cpu_type = FRV_CPU_GENERIC; | |
431 | ||
432 | else | |
433 | error ("Unknown cpu: -mcpu=%s", frv_cpu_string); | |
434 | } | |
435 | } | |
436 | ||
437 | target_flags |= (frv_default_flags_for_cpu () & ~target_flags_explicit); | |
438 | ||
439 | /* -mlibrary-pic sets -fPIC and -G0 and also suppresses warnings from the | |
440 | linker about linking pic and non-pic code. */ | |
441 | if (TARGET_LIBPIC) | |
442 | { | |
443 | if (!flag_pic) /* -fPIC */ | |
444 | flag_pic = 2; | |
445 | ||
446 | if (! g_switch_set) /* -G0 */ | |
447 | { | |
448 | g_switch_set = 1; | |
449 | g_switch_value = 0; | |
450 | } | |
451 | } | |
452 | ||
453 | /* Both -fpic and -gdwarf want to use .previous and the assembler only keeps | |
454 | one level. */ | |
455 | if (write_symbols == DWARF_DEBUG && flag_pic) | |
456 | error ("-fpic and -gdwarf are incompatible (-fpic and -g/-gdwarf-2 are fine)"); | |
457 | ||
458 | /* Change the branch cost value */ | |
459 | if (frv_branch_cost_string) | |
460 | frv_branch_cost_int = atoi (frv_branch_cost_string); | |
461 | ||
462 | /* Change the # of insns to be converted to conditional execution */ | |
463 | if (frv_condexec_insns_str) | |
464 | frv_condexec_insns = atoi (frv_condexec_insns_str); | |
465 | ||
466 | /* Change # of temporary registers used to hold integer constants */ | |
467 | if (frv_condexec_temps_str) | |
468 | frv_condexec_temps = atoi (frv_condexec_temps_str); | |
469 | ||
470 | /* Change scheduling look ahead. */ | |
471 | if (frv_sched_lookahead_str) | |
472 | frv_sched_lookahead = atoi (frv_sched_lookahead_str); | |
473 | ||
474 | /* A C expression whose value is a register class containing hard | |
475 | register REGNO. In general there is more than one such class; | |
476 | choose a class which is "minimal", meaning that no smaller class | |
477 | also contains the register. */ | |
478 | ||
479 | for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++) | |
480 | { | |
481 | enum reg_class class; | |
482 | ||
483 | if (GPR_P (regno)) | |
484 | { | |
485 | int gpr_reg = regno - GPR_FIRST; | |
486 | if ((gpr_reg & 3) == 0) | |
487 | class = QUAD_REGS; | |
488 | ||
489 | else if ((gpr_reg & 1) == 0) | |
490 | class = EVEN_REGS; | |
491 | ||
492 | else | |
493 | class = GPR_REGS; | |
494 | } | |
495 | ||
496 | else if (FPR_P (regno)) | |
497 | { | |
498 | int fpr_reg = regno - GPR_FIRST; | |
499 | if ((fpr_reg & 3) == 0) | |
500 | class = QUAD_FPR_REGS; | |
501 | ||
502 | else if ((fpr_reg & 1) == 0) | |
503 | class = FEVEN_REGS; | |
504 | ||
505 | else | |
506 | class = FPR_REGS; | |
507 | } | |
508 | ||
509 | else if (regno == LR_REGNO) | |
510 | class = LR_REG; | |
511 | ||
512 | else if (regno == LCR_REGNO) | |
513 | class = LCR_REG; | |
514 | ||
515 | else if (ICC_P (regno)) | |
516 | class = ICC_REGS; | |
517 | ||
518 | else if (FCC_P (regno)) | |
519 | class = FCC_REGS; | |
520 | ||
521 | else if (ICR_P (regno)) | |
522 | class = ICR_REGS; | |
523 | ||
524 | else if (FCR_P (regno)) | |
525 | class = FCR_REGS; | |
526 | ||
527 | else if (ACC_P (regno)) | |
528 | { | |
529 | int r = regno - ACC_FIRST; | |
530 | if ((r & 3) == 0) | |
531 | class = QUAD_ACC_REGS; | |
532 | else if ((r & 1) == 0) | |
533 | class = EVEN_ACC_REGS; | |
534 | else | |
535 | class = ACC_REGS; | |
536 | } | |
537 | ||
538 | else if (ACCG_P (regno)) | |
539 | class = ACCG_REGS; | |
540 | ||
541 | else | |
542 | class = NO_REGS; | |
543 | ||
544 | regno_reg_class[regno] = class; | |
545 | } | |
546 | ||
547 | /* Check for small data option */ | |
548 | if (!g_switch_set) | |
549 | g_switch_value = SDATA_DEFAULT_SIZE; | |
550 | ||
551 | /* A C expression which defines the machine-dependent operand | |
552 | constraint letters for register classes. If CHAR is such a | |
553 | letter, the value should be the register class corresponding to | |
554 | it. Otherwise, the value should be `NO_REGS'. The register | |
555 | letter `r', corresponding to class `GENERAL_REGS', will not be | |
556 | passed to this macro; you do not need to handle it. | |
557 | ||
558 | The following letters are unavailable, due to being used as | |
559 | constraints: | |
560 | '0'..'9' | |
561 | '<', '>' | |
562 | 'E', 'F', 'G', 'H' | |
563 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P' | |
564 | 'Q', 'R', 'S', 'T', 'U' | |
565 | 'V', 'X' | |
566 | 'g', 'i', 'm', 'n', 'o', 'p', 'r', 's' */ | |
567 | ||
568 | for (i = 0; i < 256; i++) | |
569 | reg_class_from_letter[i] = NO_REGS; | |
570 | ||
571 | reg_class_from_letter['a'] = ACC_REGS; | |
572 | reg_class_from_letter['b'] = EVEN_ACC_REGS; | |
573 | reg_class_from_letter['c'] = CC_REGS; | |
574 | reg_class_from_letter['d'] = GPR_REGS; | |
575 | reg_class_from_letter['e'] = EVEN_REGS; | |
576 | reg_class_from_letter['f'] = FPR_REGS; | |
577 | reg_class_from_letter['h'] = FEVEN_REGS; | |
578 | reg_class_from_letter['l'] = LR_REG; | |
579 | reg_class_from_letter['q'] = QUAD_REGS; | |
580 | reg_class_from_letter['t'] = ICC_REGS; | |
581 | reg_class_from_letter['u'] = FCC_REGS; | |
582 | reg_class_from_letter['v'] = ICR_REGS; | |
583 | reg_class_from_letter['w'] = FCR_REGS; | |
584 | reg_class_from_letter['x'] = QUAD_FPR_REGS; | |
585 | reg_class_from_letter['y'] = LCR_REG; | |
586 | reg_class_from_letter['z'] = SPR_REGS; | |
587 | reg_class_from_letter['A'] = QUAD_ACC_REGS; | |
588 | reg_class_from_letter['B'] = ACCG_REGS; | |
589 | reg_class_from_letter['C'] = CR_REGS; | |
590 | ||
591 | /* There is no single unaligned SI op for PIC code. Sometimes we | |
592 | need to use ".4byte" and sometimes we need to use ".picptr". | |
593 | See frv_assemble_integer for details. */ | |
594 | if (flag_pic) | |
595 | targetm.asm_out.unaligned_op.si = 0; | |
596 | ||
597 | init_machine_status = frv_init_machine_status; | |
598 | } | |
599 | ||
600 | \f | |
601 | /* Some machines may desire to change what optimizations are performed for | |
602 | various optimization levels. This macro, if defined, is executed once just | |
603 | after the optimization level is determined and before the remainder of the | |
604 | command options have been parsed. Values set in this macro are used as the | |
605 | default values for the other command line options. | |
606 | ||
607 | LEVEL is the optimization level specified; 2 if `-O2' is specified, 1 if | |
608 | `-O' is specified, and 0 if neither is specified. | |
609 | ||
9cd10576 | 610 | SIZE is nonzero if `-Os' is specified, 0 otherwise. |
36a05131 BS |
611 | |
612 | You should not use this macro to change options that are not | |
613 | machine-specific. These should uniformly selected by the same optimization | |
614 | level on all supported machines. Use this macro to enable machbine-specific | |
615 | optimizations. | |
616 | ||
617 | *Do not examine `write_symbols' in this macro!* The debugging options are | |
618 | *not supposed to alter the generated code. */ | |
619 | ||
620 | /* On the FRV, possibly disable VLIW packing which is done by the 2nd | |
621 | scheduling pass at the current time. */ | |
622 | void | |
623 | frv_optimization_options (level, size) | |
624 | int level; | |
625 | int size ATTRIBUTE_UNUSED; | |
626 | { | |
627 | if (level >= 2) | |
628 | { | |
629 | #ifdef DISABLE_SCHED2 | |
630 | flag_schedule_insns_after_reload = 0; | |
631 | #endif | |
632 | #ifdef ENABLE_RCSP | |
633 | flag_rcsp = 1; | |
634 | #endif | |
635 | } | |
636 | } | |
637 | ||
36a05131 BS |
638 | \f |
639 | /* Return true if NAME (a STRING_CST node) begins with PREFIX. */ | |
640 | ||
641 | static int | |
642 | frv_string_begins_with (name, prefix) | |
643 | tree name; | |
644 | const char *prefix; | |
645 | { | |
646 | int prefix_len = strlen (prefix); | |
647 | ||
648 | /* Remember: NAME's length includes the null terminator. */ | |
649 | return (TREE_STRING_LENGTH (name) > prefix_len | |
650 | && strncmp (TREE_STRING_POINTER (name), prefix, prefix_len) == 0); | |
651 | } | |
36a05131 BS |
652 | \f |
653 | /* Zero or more C statements that may conditionally modify two variables | |
654 | `fixed_regs' and `call_used_regs' (both of type `char []') after they have | |
655 | been initialized from the two preceding macros. | |
656 | ||
657 | This is necessary in case the fixed or call-clobbered registers depend on | |
658 | target flags. | |
659 | ||
660 | You need not define this macro if it has no work to do. | |
661 | ||
662 | If the usage of an entire class of registers depends on the target flags, | |
663 | you may indicate this to GCC by using this macro to modify `fixed_regs' and | |
664 | `call_used_regs' to 1 for each of the registers in the classes which should | |
665 | not be used by GCC. Also define the macro `REG_CLASS_FROM_LETTER' to return | |
666 | `NO_REGS' if it is called with a letter for a class that shouldn't be used. | |
667 | ||
668 | (However, if this class is not included in `GENERAL_REGS' and all of the | |
669 | insn patterns whose constraints permit this class are controlled by target | |
670 | switches, then GCC will automatically avoid using these registers when the | |
671 | target switches are opposed to them.) */ | |
672 | ||
673 | void | |
674 | frv_conditional_register_usage () | |
675 | { | |
676 | int i; | |
677 | ||
678 | for (i = GPR_FIRST + NUM_GPRS; i <= GPR_LAST; i++) | |
679 | fixed_regs[i] = call_used_regs[i] = 1; | |
680 | ||
681 | for (i = FPR_FIRST + NUM_FPRS; i <= FPR_LAST; i++) | |
682 | fixed_regs[i] = call_used_regs[i] = 1; | |
683 | ||
684 | for (i = ACC_FIRST + NUM_ACCS; i <= ACC_LAST; i++) | |
685 | fixed_regs[i] = call_used_regs[i] = 1; | |
686 | ||
687 | for (i = ACCG_FIRST + NUM_ACCS; i <= ACCG_LAST; i++) | |
688 | fixed_regs[i] = call_used_regs[i] = 1; | |
689 | ||
690 | /* Reserve the registers used for conditional execution. At present, we need | |
691 | 1 ICC and 1 ICR register. */ | |
692 | fixed_regs[ICC_TEMP] = call_used_regs[ICC_TEMP] = 1; | |
693 | fixed_regs[ICR_TEMP] = call_used_regs[ICR_TEMP] = 1; | |
694 | ||
695 | if (TARGET_FIXED_CC) | |
696 | { | |
697 | fixed_regs[ICC_FIRST] = call_used_regs[ICC_FIRST] = 1; | |
698 | fixed_regs[FCC_FIRST] = call_used_regs[FCC_FIRST] = 1; | |
699 | fixed_regs[ICR_FIRST] = call_used_regs[ICR_FIRST] = 1; | |
700 | fixed_regs[FCR_FIRST] = call_used_regs[FCR_FIRST] = 1; | |
701 | } | |
702 | ||
703 | #if 0 | |
704 | /* If -fpic, SDA_BASE_REG is the PIC register. */ | |
705 | if (g_switch_value == 0 && !flag_pic) | |
706 | fixed_regs[SDA_BASE_REG] = call_used_regs[SDA_BASE_REG] = 0; | |
707 | ||
708 | if (!flag_pic) | |
709 | fixed_regs[PIC_REGNO] = call_used_regs[PIC_REGNO] = 0; | |
710 | #endif | |
711 | } | |
712 | ||
713 | \f | |
714 | /* | |
715 | * Compute the stack frame layout | |
716 | * | |
717 | * Register setup: | |
718 | * +---------------+-----------------------+-----------------------+ | |
719 | * |Register |type |caller-save/callee-save| | |
720 | * +---------------+-----------------------+-----------------------+ | |
721 | * |GR0 |Zero register | - | | |
722 | * |GR1 |Stack pointer(SP) | - | | |
723 | * |GR2 |Frame pointer(FP) | - | | |
724 | * |GR3 |Hidden parameter | caller save | | |
725 | * |GR4-GR7 | - | caller save | | |
726 | * |GR8-GR13 |Argument register | caller save | | |
727 | * |GR14-GR15 | - | caller save | | |
728 | * |GR16-GR31 | - | callee save | | |
729 | * |GR32-GR47 | - | caller save | | |
730 | * |GR48-GR63 | - | callee save | | |
731 | * |FR0-FR15 | - | caller save | | |
732 | * |FR16-FR31 | - | callee save | | |
733 | * |FR32-FR47 | - | caller save | | |
734 | * |FR48-FR63 | - | callee save | | |
735 | * +---------------+-----------------------+-----------------------+ | |
736 | * | |
737 | * Stack frame setup: | |
738 | * Low | |
739 | * SP-> |-----------------------------------| | |
740 | * | Argument area | | |
741 | * |-----------------------------------| | |
742 | * | Register save area | | |
743 | * |-----------------------------------| | |
744 | * | Local variable save area | | |
745 | * FP-> |-----------------------------------| | |
746 | * | Old FP | | |
747 | * |-----------------------------------| | |
748 | * | Hidden parameter save area | | |
749 | * |-----------------------------------| | |
750 | * | Return address(LR) storage area | | |
751 | * |-----------------------------------| | |
752 | * | Padding for alignment | | |
753 | * |-----------------------------------| | |
754 | * | Register argument area | | |
755 | * OLD SP-> |-----------------------------------| | |
756 | * | Parameter area | | |
757 | * |-----------------------------------| | |
758 | * High | |
759 | * | |
760 | * Argument area/Parameter area: | |
761 | * | |
762 | * When a function is called, this area is used for argument transfer. When | |
763 | * the argument is set up by the caller function, this area is referred to as | |
764 | * the argument area. When the argument is referenced by the callee function, | |
765 | * this area is referred to as the parameter area. The area is allocated when | |
766 | * all arguments cannot be placed on the argument register at the time of | |
767 | * argument transfer. | |
768 | * | |
769 | * Register save area: | |
770 | * | |
771 | * This is a register save area that must be guaranteed for the caller | |
772 | * function. This area is not secured when the register save operation is not | |
773 | * needed. | |
774 | * | |
775 | * Local variable save area: | |
776 | * | |
777 | * This is the area for local variables and temporary variables. | |
778 | * | |
779 | * Old FP: | |
780 | * | |
781 | * This area stores the FP value of the caller function. | |
782 | * | |
783 | * Hidden parameter save area: | |
784 | * | |
785 | * This area stores the start address of the return value storage | |
786 | * area for a struct/union return function. | |
787 | * When a struct/union is used as the return value, the caller | |
788 | * function stores the return value storage area start address in | |
789 | * register GR3 and passes it to the caller function. | |
790 | * The callee function interprets the address stored in the GR3 | |
791 | * as the return value storage area start address. | |
792 | * When register GR3 needs to be saved into memory, the callee | |
793 | * function saves it in the hidden parameter save area. This | |
794 | * area is not secured when the save operation is not needed. | |
795 | * | |
796 | * Return address(LR) storage area: | |
797 | * | |
798 | * This area saves the LR. The LR stores the address of a return to the caller | |
799 | * function for the purpose of function calling. | |
800 | * | |
801 | * Argument register area: | |
802 | * | |
803 | * This area saves the argument register. This area is not secured when the | |
804 | * save operation is not needed. | |
805 | * | |
806 | * Argument: | |
807 | * | |
808 | * Arguments, the count of which equals the count of argument registers (6 | |
809 | * words), are positioned in registers GR8 to GR13 and delivered to the callee | |
810 | * function. When a struct/union return function is called, the return value | |
811 | * area address is stored in register GR3. Arguments not placed in the | |
812 | * argument registers will be stored in the stack argument area for transfer | |
813 | * purposes. When an 8-byte type argument is to be delivered using registers, | |
814 | * it is divided into two and placed in two registers for transfer. When | |
815 | * argument registers must be saved to memory, the callee function secures an | |
816 | * argument register save area in the stack. In this case, a continuous | |
817 | * argument register save area must be established in the parameter area. The | |
818 | * argument register save area must be allocated as needed to cover the size of | |
819 | * the argument register to be saved. If the function has a variable count of | |
820 | * arguments, it saves all argument registers in the argument register save | |
821 | * area. | |
822 | * | |
823 | * Argument Extension Format: | |
824 | * | |
825 | * When an argument is to be stored in the stack, its type is converted to an | |
826 | * extended type in accordance with the individual argument type. The argument | |
827 | * is freed by the caller function after the return from the callee function is | |
828 | * made. | |
829 | * | |
830 | * +-----------------------+---------------+------------------------+ | |
831 | * | Argument Type |Extended Type |Stack Storage Size(byte)| | |
832 | * +-----------------------+---------------+------------------------+ | |
833 | * |char |int | 4 | | |
834 | * |signed char |int | 4 | | |
835 | * |unsigned char |int | 4 | | |
836 | * |[signed] short int |int | 4 | | |
837 | * |unsigned short int |int | 4 | | |
838 | * |[signed] int |No extension | 4 | | |
839 | * |unsigned int |No extension | 4 | | |
840 | * |[signed] long int |No extension | 4 | | |
841 | * |unsigned long int |No extension | 4 | | |
842 | * |[signed] long long int |No extension | 8 | | |
843 | * |unsigned long long int |No extension | 8 | | |
844 | * |float |double | 8 | | |
845 | * |double |No extension | 8 | | |
846 | * |long double |No extension | 8 | | |
847 | * |pointer |No extension | 4 | | |
848 | * |struct/union |- | 4 (*1) | | |
849 | * +-----------------------+---------------+------------------------+ | |
850 | * | |
851 | * When a struct/union is to be delivered as an argument, the caller copies it | |
852 | * to the local variable area and delivers the address of that area. | |
853 | * | |
854 | * Return Value: | |
855 | * | |
856 | * +-------------------------------+----------------------+ | |
857 | * |Return Value Type |Return Value Interface| | |
858 | * +-------------------------------+----------------------+ | |
859 | * |void |None | | |
860 | * |[signed|unsigned] char |GR8 | | |
861 | * |[signed|unsigned] short int |GR8 | | |
862 | * |[signed|unsigned] int |GR8 | | |
863 | * |[signed|unsigned] long int |GR8 | | |
864 | * |pointer |GR8 | | |
865 | * |[signed|unsigned] long long int|GR8 & GR9 | | |
866 | * |float |GR8 | | |
867 | * |double |GR8 & GR9 | | |
868 | * |long double |GR8 & GR9 | | |
869 | * |struct/union |(*1) | | |
870 | * +-------------------------------+----------------------+ | |
871 | * | |
872 | * When a struct/union is used as the return value, the caller function stores | |
873 | * the start address of the return value storage area into GR3 and then passes | |
874 | * it to the callee function. The callee function interprets GR3 as the start | |
875 | * address of the return value storage area. When this address needs to be | |
876 | * saved in memory, the callee function secures the hidden parameter save area | |
877 | * and saves the address in that area. | |
878 | */ | |
879 | ||
880 | frv_stack_t * | |
881 | frv_stack_info () | |
882 | { | |
883 | static frv_stack_t info, zero_info; | |
884 | frv_stack_t *info_ptr = &info; | |
885 | tree fndecl = current_function_decl; | |
886 | int varargs_p = 0; | |
887 | tree cur_arg; | |
888 | tree next_arg; | |
889 | int range; | |
890 | int alignment; | |
891 | int offset; | |
892 | ||
893 | /* If we've already calculated the values and reload is complete, just return now */ | |
894 | if (frv_stack_cache) | |
895 | return frv_stack_cache; | |
896 | ||
897 | /* Zero all fields */ | |
898 | info = zero_info; | |
899 | ||
900 | /* Set up the register range information */ | |
901 | info_ptr->regs[STACK_REGS_GPR].name = "gpr"; | |
902 | info_ptr->regs[STACK_REGS_GPR].first = LAST_ARG_REGNUM + 1; | |
903 | info_ptr->regs[STACK_REGS_GPR].last = GPR_LAST; | |
904 | info_ptr->regs[STACK_REGS_GPR].dword_p = TRUE; | |
905 | ||
906 | info_ptr->regs[STACK_REGS_FPR].name = "fpr"; | |
907 | info_ptr->regs[STACK_REGS_FPR].first = FPR_FIRST; | |
908 | info_ptr->regs[STACK_REGS_FPR].last = FPR_LAST; | |
909 | info_ptr->regs[STACK_REGS_FPR].dword_p = TRUE; | |
910 | ||
911 | info_ptr->regs[STACK_REGS_LR].name = "lr"; | |
912 | info_ptr->regs[STACK_REGS_LR].first = LR_REGNO; | |
913 | info_ptr->regs[STACK_REGS_LR].last = LR_REGNO; | |
914 | info_ptr->regs[STACK_REGS_LR].special_p = 1; | |
915 | ||
916 | info_ptr->regs[STACK_REGS_CC].name = "cc"; | |
917 | info_ptr->regs[STACK_REGS_CC].first = CC_FIRST; | |
918 | info_ptr->regs[STACK_REGS_CC].last = CC_LAST; | |
919 | info_ptr->regs[STACK_REGS_CC].field_p = TRUE; | |
920 | ||
921 | info_ptr->regs[STACK_REGS_LCR].name = "lcr"; | |
922 | info_ptr->regs[STACK_REGS_LCR].first = LCR_REGNO; | |
923 | info_ptr->regs[STACK_REGS_LCR].last = LCR_REGNO; | |
924 | ||
925 | info_ptr->regs[STACK_REGS_STDARG].name = "stdarg"; | |
926 | info_ptr->regs[STACK_REGS_STDARG].first = FIRST_ARG_REGNUM; | |
927 | info_ptr->regs[STACK_REGS_STDARG].last = LAST_ARG_REGNUM; | |
928 | info_ptr->regs[STACK_REGS_STDARG].dword_p = 1; | |
929 | info_ptr->regs[STACK_REGS_STDARG].special_p = 1; | |
930 | ||
931 | info_ptr->regs[STACK_REGS_STRUCT].name = "struct"; | |
932 | info_ptr->regs[STACK_REGS_STRUCT].first = STRUCT_VALUE_REGNUM; | |
933 | info_ptr->regs[STACK_REGS_STRUCT].last = STRUCT_VALUE_REGNUM; | |
934 | info_ptr->regs[STACK_REGS_STRUCT].special_p = 1; | |
935 | ||
936 | info_ptr->regs[STACK_REGS_FP].name = "fp"; | |
937 | info_ptr->regs[STACK_REGS_FP].first = FRAME_POINTER_REGNUM; | |
938 | info_ptr->regs[STACK_REGS_FP].last = FRAME_POINTER_REGNUM; | |
939 | info_ptr->regs[STACK_REGS_FP].special_p = 1; | |
940 | ||
941 | /* Determine if this is a stdarg function. If so, allocate space to store | |
942 | the 6 arguments. */ | |
943 | if (cfun->stdarg) | |
944 | varargs_p = 1; | |
945 | ||
946 | else | |
947 | { | |
948 | /* Find the last argument, and see if it is __builtin_va_alist. */ | |
949 | for (cur_arg = DECL_ARGUMENTS (fndecl); cur_arg != (tree)0; cur_arg = next_arg) | |
950 | { | |
951 | next_arg = TREE_CHAIN (cur_arg); | |
952 | if (next_arg == (tree)0) | |
953 | { | |
954 | if (DECL_NAME (cur_arg) | |
955 | && !strcmp (IDENTIFIER_POINTER (DECL_NAME (cur_arg)), "__builtin_va_alist")) | |
956 | varargs_p = 1; | |
957 | ||
958 | break; | |
959 | } | |
960 | } | |
961 | } | |
962 | ||
963 | /* Iterate over all of the register ranges */ | |
964 | for (range = 0; range < STACK_REGS_MAX; range++) | |
965 | { | |
966 | frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]); | |
967 | int first = reg_ptr->first; | |
968 | int last = reg_ptr->last; | |
969 | int size_1word = 0; | |
970 | int size_2words = 0; | |
971 | int regno; | |
972 | ||
973 | /* Calculate which registers need to be saved & save area size */ | |
974 | switch (range) | |
975 | { | |
976 | default: | |
977 | for (regno = first; regno <= last; regno++) | |
978 | { | |
979 | if ((regs_ever_live[regno] && !call_used_regs[regno]) | |
980 | || (current_function_calls_eh_return | |
981 | && (regno >= FIRST_EH_REGNUM && regno <= LAST_EH_REGNUM)) | |
982 | || (flag_pic && cfun->uses_pic_offset_table && regno == PIC_REGNO)) | |
983 | { | |
984 | info_ptr->save_p[regno] = REG_SAVE_1WORD; | |
985 | size_1word += UNITS_PER_WORD; | |
986 | } | |
987 | } | |
988 | break; | |
989 | ||
990 | /* Calculate whether we need to create a frame after everything else | |
991 | has been processed. */ | |
992 | case STACK_REGS_FP: | |
993 | break; | |
994 | ||
995 | case STACK_REGS_LR: | |
996 | if (regs_ever_live[LR_REGNO] | |
997 | || profile_flag | |
998 | || frame_pointer_needed | |
999 | || (flag_pic && cfun->uses_pic_offset_table)) | |
1000 | { | |
1001 | info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD; | |
1002 | size_1word += UNITS_PER_WORD; | |
1003 | } | |
1004 | break; | |
1005 | ||
1006 | case STACK_REGS_STDARG: | |
1007 | if (varargs_p) | |
1008 | { | |
5bdc5878 | 1009 | /* If this is a stdarg function with a non varardic argument split |
36a05131 BS |
1010 | between registers and the stack, adjust the saved registers |
1011 | downward */ | |
1012 | last -= (ADDR_ALIGN (cfun->pretend_args_size, UNITS_PER_WORD) | |
1013 | / UNITS_PER_WORD); | |
1014 | ||
1015 | for (regno = first; regno <= last; regno++) | |
1016 | { | |
1017 | info_ptr->save_p[regno] = REG_SAVE_1WORD; | |
1018 | size_1word += UNITS_PER_WORD; | |
1019 | } | |
1020 | ||
1021 | info_ptr->stdarg_size = size_1word; | |
1022 | } | |
1023 | break; | |
1024 | ||
1025 | case STACK_REGS_STRUCT: | |
1026 | if (cfun->returns_struct) | |
1027 | { | |
1028 | info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD; | |
1029 | size_1word += UNITS_PER_WORD; | |
1030 | } | |
1031 | break; | |
1032 | } | |
1033 | ||
1034 | ||
1035 | if (size_1word) | |
1036 | { | |
1037 | /* If this is a field, it only takes one word */ | |
1038 | if (reg_ptr->field_p) | |
1039 | size_1word = UNITS_PER_WORD; | |
1040 | ||
1041 | /* Determine which register pairs can be saved together */ | |
1042 | else if (reg_ptr->dword_p && TARGET_DWORD) | |
1043 | { | |
1044 | for (regno = first; regno < last; regno += 2) | |
1045 | { | |
1046 | if (info_ptr->save_p[regno] && info_ptr->save_p[regno+1]) | |
1047 | { | |
1048 | size_2words += 2 * UNITS_PER_WORD; | |
1049 | size_1word -= 2 * UNITS_PER_WORD; | |
1050 | info_ptr->save_p[regno] = REG_SAVE_2WORDS; | |
1051 | info_ptr->save_p[regno+1] = REG_SAVE_NO_SAVE; | |
1052 | } | |
1053 | } | |
1054 | } | |
1055 | ||
1056 | reg_ptr->size_1word = size_1word; | |
1057 | reg_ptr->size_2words = size_2words; | |
1058 | ||
1059 | if (! reg_ptr->special_p) | |
1060 | { | |
1061 | info_ptr->regs_size_1word += size_1word; | |
1062 | info_ptr->regs_size_2words += size_2words; | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | ||
1067 | /* Set up the sizes of each each field in the frame body, making the sizes | |
1068 | of each be divisible by the size of a dword if dword operations might | |
1069 | be used, or the size of a word otherwise. */ | |
1070 | alignment = (TARGET_DWORD? 2 * UNITS_PER_WORD : UNITS_PER_WORD); | |
1071 | ||
1072 | info_ptr->parameter_size = ADDR_ALIGN (cfun->outgoing_args_size, alignment); | |
1073 | info_ptr->regs_size = ADDR_ALIGN (info_ptr->regs_size_2words | |
1074 | + info_ptr->regs_size_1word, | |
1075 | alignment); | |
1076 | info_ptr->vars_size = ADDR_ALIGN (get_frame_size (), alignment); | |
1077 | ||
1078 | info_ptr->pretend_size = cfun->pretend_args_size; | |
1079 | ||
1080 | /* Work out the size of the frame, excluding the header. Both the frame | |
1081 | body and register parameter area will be dword-aligned. */ | |
1082 | info_ptr->total_size | |
1083 | = (ADDR_ALIGN (info_ptr->parameter_size | |
1084 | + info_ptr->regs_size | |
1085 | + info_ptr->vars_size, | |
1086 | 2 * UNITS_PER_WORD) | |
1087 | + ADDR_ALIGN (info_ptr->pretend_size | |
1088 | + info_ptr->stdarg_size, | |
1089 | 2 * UNITS_PER_WORD)); | |
1090 | ||
1091 | /* See if we need to create a frame at all, if so add header area. */ | |
1092 | if (info_ptr->total_size > 0 | |
1093 | || info_ptr->regs[STACK_REGS_LR].size_1word > 0 | |
1094 | || info_ptr->regs[STACK_REGS_STRUCT].size_1word > 0) | |
1095 | { | |
1096 | offset = info_ptr->parameter_size; | |
1097 | info_ptr->header_size = 4 * UNITS_PER_WORD; | |
1098 | info_ptr->total_size += 4 * UNITS_PER_WORD; | |
1099 | ||
1100 | /* Calculate the offsets to save normal register pairs */ | |
1101 | for (range = 0; range < STACK_REGS_MAX; range++) | |
1102 | { | |
1103 | frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]); | |
1104 | if (! reg_ptr->special_p) | |
1105 | { | |
1106 | int first = reg_ptr->first; | |
1107 | int last = reg_ptr->last; | |
1108 | int regno; | |
1109 | ||
1110 | for (regno = first; regno <= last; regno++) | |
1111 | if (info_ptr->save_p[regno] == REG_SAVE_2WORDS | |
1112 | && regno != FRAME_POINTER_REGNUM | |
1113 | && (regno < FIRST_ARG_REGNUM | |
1114 | || regno > LAST_ARG_REGNUM)) | |
1115 | { | |
1116 | info_ptr->reg_offset[regno] = offset; | |
1117 | offset += 2 * UNITS_PER_WORD; | |
1118 | } | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | /* Calculate the offsets to save normal single registers */ | |
1123 | for (range = 0; range < STACK_REGS_MAX; range++) | |
1124 | { | |
1125 | frv_stack_regs_t *reg_ptr = &(info_ptr->regs[range]); | |
1126 | if (! reg_ptr->special_p) | |
1127 | { | |
1128 | int first = reg_ptr->first; | |
1129 | int last = reg_ptr->last; | |
1130 | int regno; | |
1131 | ||
1132 | for (regno = first; regno <= last; regno++) | |
1133 | if (info_ptr->save_p[regno] == REG_SAVE_1WORD | |
1134 | && regno != FRAME_POINTER_REGNUM | |
1135 | && (regno < FIRST_ARG_REGNUM | |
1136 | || regno > LAST_ARG_REGNUM)) | |
1137 | { | |
1138 | info_ptr->reg_offset[regno] = offset; | |
1139 | offset += UNITS_PER_WORD; | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | /* Calculate the offset to save the local variables at. */ | |
1145 | offset = ADDR_ALIGN (offset, alignment); | |
1146 | if (info_ptr->vars_size) | |
1147 | { | |
1148 | info_ptr->vars_offset = offset; | |
1149 | offset += info_ptr->vars_size; | |
1150 | } | |
1151 | ||
1152 | /* Align header to a dword-boundary. */ | |
1153 | offset = ADDR_ALIGN (offset, 2 * UNITS_PER_WORD); | |
1154 | ||
1155 | /* Calculate the offsets in the fixed frame. */ | |
1156 | info_ptr->save_p[FRAME_POINTER_REGNUM] = REG_SAVE_1WORD; | |
1157 | info_ptr->reg_offset[FRAME_POINTER_REGNUM] = offset; | |
1158 | info_ptr->regs[STACK_REGS_FP].size_1word = UNITS_PER_WORD; | |
1159 | ||
1160 | info_ptr->save_p[LR_REGNO] = REG_SAVE_1WORD; | |
1161 | info_ptr->reg_offset[LR_REGNO] = offset + 2*UNITS_PER_WORD; | |
1162 | info_ptr->regs[STACK_REGS_LR].size_1word = UNITS_PER_WORD; | |
1163 | ||
1164 | if (cfun->returns_struct) | |
1165 | { | |
1166 | info_ptr->save_p[STRUCT_VALUE_REGNUM] = REG_SAVE_1WORD; | |
1167 | info_ptr->reg_offset[STRUCT_VALUE_REGNUM] = offset + UNITS_PER_WORD; | |
1168 | info_ptr->regs[STACK_REGS_STRUCT].size_1word = UNITS_PER_WORD; | |
1169 | } | |
1170 | ||
1171 | /* Calculate the offsets to store the arguments passed in registers | |
1172 | for stdarg functions. The register pairs are first and the single | |
1173 | register if any is last. The register save area starts on a | |
1174 | dword-boundary. */ | |
1175 | if (info_ptr->stdarg_size) | |
1176 | { | |
1177 | int first = info_ptr->regs[STACK_REGS_STDARG].first; | |
1178 | int last = info_ptr->regs[STACK_REGS_STDARG].last; | |
1179 | int regno; | |
1180 | ||
1181 | /* Skip the header. */ | |
1182 | offset += 4 * UNITS_PER_WORD; | |
1183 | for (regno = first; regno <= last; regno++) | |
1184 | { | |
1185 | if (info_ptr->save_p[regno] == REG_SAVE_2WORDS) | |
1186 | { | |
1187 | info_ptr->reg_offset[regno] = offset; | |
1188 | offset += 2 * UNITS_PER_WORD; | |
1189 | } | |
1190 | else if (info_ptr->save_p[regno] == REG_SAVE_1WORD) | |
1191 | { | |
1192 | info_ptr->reg_offset[regno] = offset; | |
1193 | offset += UNITS_PER_WORD; | |
1194 | } | |
1195 | } | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | if (reload_completed) | |
1200 | frv_stack_cache = info_ptr; | |
1201 | ||
1202 | return info_ptr; | |
1203 | } | |
1204 | ||
1205 | \f | |
1206 | /* Print the information about the frv stack offsets, etc. when debugging. */ | |
1207 | ||
1208 | void | |
1209 | frv_debug_stack (info) | |
1210 | frv_stack_t *info; | |
1211 | { | |
1212 | int range; | |
1213 | ||
1214 | if (!info) | |
1215 | info = frv_stack_info (); | |
1216 | ||
1217 | fprintf (stderr, "\nStack information for function %s:\n", | |
1218 | ((current_function_decl && DECL_NAME (current_function_decl)) | |
1219 | ? IDENTIFIER_POINTER (DECL_NAME (current_function_decl)) | |
1220 | : "<unknown>")); | |
1221 | ||
1222 | fprintf (stderr, "\ttotal_size\t= %6d\n", info->total_size); | |
1223 | fprintf (stderr, "\tvars_size\t= %6d\n", info->vars_size); | |
1224 | fprintf (stderr, "\tparam_size\t= %6d\n", info->parameter_size); | |
1225 | fprintf (stderr, "\tregs_size\t= %6d, 1w = %3d, 2w = %3d\n", | |
1226 | info->regs_size, info->regs_size_1word, info->regs_size_2words); | |
1227 | ||
1228 | fprintf (stderr, "\theader_size\t= %6d\n", info->header_size); | |
1229 | fprintf (stderr, "\tpretend_size\t= %6d\n", info->pretend_size); | |
1230 | fprintf (stderr, "\tvars_offset\t= %6d\n", info->vars_offset); | |
1231 | fprintf (stderr, "\tregs_offset\t= %6d\n", info->regs_offset); | |
1232 | ||
1233 | for (range = 0; range < STACK_REGS_MAX; range++) | |
1234 | { | |
1235 | frv_stack_regs_t *regs = &(info->regs[range]); | |
1236 | if ((regs->size_1word + regs->size_2words) > 0) | |
1237 | { | |
1238 | int first = regs->first; | |
1239 | int last = regs->last; | |
1240 | int regno; | |
1241 | ||
1242 | fprintf (stderr, "\t%s\tsize\t= %6d, 1w = %3d, 2w = %3d, save =", | |
1243 | regs->name, regs->size_1word + regs->size_2words, | |
1244 | regs->size_1word, regs->size_2words); | |
1245 | ||
1246 | for (regno = first; regno <= last; regno++) | |
1247 | { | |
1248 | if (info->save_p[regno] == REG_SAVE_1WORD) | |
1249 | fprintf (stderr, " %s (%d)", reg_names[regno], | |
1250 | info->reg_offset[regno]); | |
1251 | ||
1252 | else if (info->save_p[regno] == REG_SAVE_2WORDS) | |
1253 | fprintf (stderr, " %s-%s (%d)", reg_names[regno], | |
1254 | reg_names[regno+1], info->reg_offset[regno]); | |
1255 | } | |
1256 | ||
1257 | fputc ('\n', stderr); | |
1258 | } | |
1259 | } | |
1260 | ||
1261 | fflush (stderr); | |
1262 | } | |
1263 | ||
1264 | ||
1265 | \f | |
1266 | ||
1267 | /* The following variable value is TRUE if the next output insn should | |
1268 | finish cpu cycle. In order words the insn will have packing bit | |
1269 | (which means absence of asm code suffix `.p' on assembler. */ | |
1270 | ||
1271 | static int frv_insn_packing_flag; | |
1272 | ||
1273 | /* True if the current function contains a far jump. */ | |
1274 | ||
1275 | static int | |
1276 | frv_function_contains_far_jump () | |
1277 | { | |
1278 | rtx insn = get_insns (); | |
1279 | while (insn != NULL | |
1280 | && !(GET_CODE (insn) == JUMP_INSN | |
1281 | /* Ignore tablejump patterns. */ | |
1282 | && GET_CODE (PATTERN (insn)) != ADDR_VEC | |
1283 | && GET_CODE (PATTERN (insn)) != ADDR_DIFF_VEC | |
1284 | && get_attr_far_jump (insn) == FAR_JUMP_YES)) | |
1285 | insn = NEXT_INSN (insn); | |
1286 | return (insn != NULL); | |
1287 | } | |
1288 | ||
1289 | /* For the FRV, this function makes sure that a function with far jumps | |
1290 | will return correctly. It also does the VLIW packing. */ | |
1291 | ||
1292 | static void | |
1293 | frv_function_prologue (file, size) | |
1294 | FILE *file; | |
1295 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; | |
1296 | { | |
1297 | /* If no frame was created, check whether the function uses a call | |
1298 | instruction to implement a far jump. If so, save the link in gr3 and | |
1299 | replace all returns to LR with returns to GR3. GR3 is used because it | |
1300 | is call-clobbered, because is not available to the register allocator, | |
1301 | and because all functions that take a hidden argument pointer will have | |
1302 | a stack frame. */ | |
1303 | if (frv_stack_info ()->total_size == 0 && frv_function_contains_far_jump ()) | |
1304 | { | |
1305 | rtx insn; | |
1306 | ||
1307 | /* Just to check that the above comment is true. */ | |
1308 | if (regs_ever_live[GPR_FIRST + 3]) | |
1309 | abort (); | |
1310 | ||
1311 | /* Generate the instruction that saves the link register. */ | |
1312 | fprintf (file, "\tmovsg lr,gr3\n"); | |
1313 | ||
1314 | /* Replace the LR with GR3 in *return_internal patterns. The insn | |
1315 | will now return using jmpl @(gr3,0) rather than bralr. We cannot | |
1316 | simply emit a different assembly directive because bralr and jmpl | |
1317 | execute in different units. */ | |
1318 | for (insn = get_insns(); insn != NULL; insn = NEXT_INSN (insn)) | |
1319 | if (GET_CODE (insn) == JUMP_INSN) | |
1320 | { | |
1321 | rtx pattern = PATTERN (insn); | |
1322 | if (GET_CODE (pattern) == PARALLEL | |
1323 | && XVECLEN (pattern, 0) >= 2 | |
1324 | && GET_CODE (XVECEXP (pattern, 0, 0)) == RETURN | |
1325 | && GET_CODE (XVECEXP (pattern, 0, 1)) == USE) | |
1326 | { | |
1327 | rtx address = XEXP (XVECEXP (pattern, 0, 1), 0); | |
1328 | if (GET_CODE (address) == REG && REGNO (address) == LR_REGNO) | |
1329 | REGNO (address) = GPR_FIRST + 3; | |
1330 | } | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | frv_pack_insns (); | |
1335 | frv_insn_packing_flag = TRUE; | |
1336 | } | |
1337 | ||
1338 | \f | |
1339 | /* Return the next available temporary register in a given class. */ | |
1340 | ||
1341 | static rtx | |
1342 | frv_alloc_temp_reg (info, class, mode, mark_as_used, no_abort) | |
1343 | frv_tmp_reg_t *info; /* which registers are available */ | |
1344 | enum reg_class class; /* register class desired */ | |
1345 | enum machine_mode mode; /* mode to allocate register with */ | |
1346 | int mark_as_used; /* register not available after allocation */ | |
1347 | int no_abort; /* return NULL instead of aborting */ | |
1348 | { | |
1349 | int regno = info->next_reg[ (int)class ]; | |
1350 | int orig_regno = regno; | |
1351 | HARD_REG_SET *reg_in_class = ®_class_contents[ (int)class ]; | |
1352 | int i, nr; | |
1353 | ||
1354 | for (;;) | |
1355 | { | |
1356 | if (TEST_HARD_REG_BIT (*reg_in_class, regno) | |
1357 | && TEST_HARD_REG_BIT (info->regs, regno)) | |
1358 | break; | |
1359 | ||
1360 | if (++regno >= FIRST_PSEUDO_REGISTER) | |
1361 | regno = 0; | |
1362 | if (regno == orig_regno) | |
1363 | { | |
1364 | if (no_abort) | |
1365 | return NULL_RTX; | |
1366 | else | |
1367 | abort (); | |
1368 | } | |
1369 | } | |
1370 | ||
1371 | nr = HARD_REGNO_NREGS (regno, mode); | |
1372 | info->next_reg[ (int)class ] = regno + nr; | |
1373 | ||
1374 | if (mark_as_used) | |
1375 | for (i = 0; i < nr; i++) | |
1376 | CLEAR_HARD_REG_BIT (info->regs, regno+i); | |
1377 | ||
1378 | return gen_rtx_REG (mode, regno); | |
1379 | } | |
1380 | ||
1381 | \f | |
1382 | /* Return an rtx with the value OFFSET, which will either be a register or a | |
1383 | signed 12-bit integer. It can be used as the second operand in an "add" | |
1384 | instruction, or as the index in a load or store. | |
1385 | ||
1386 | The function returns a constant rtx if OFFSET is small enough, otherwise | |
1387 | it loads the constant into register OFFSET_REGNO and returns that. */ | |
1388 | static rtx | |
1389 | frv_frame_offset_rtx (offset) | |
1390 | int offset; | |
1391 | { | |
1392 | rtx offset_rtx = GEN_INT (offset); | |
1393 | if (IN_RANGE_P (offset, -2048, 2047)) | |
1394 | return offset_rtx; | |
1395 | else | |
1396 | { | |
1397 | rtx reg_rtx = gen_rtx_REG (SImode, OFFSET_REGNO); | |
1398 | if (IN_RANGE_P (offset, -32768, 32767)) | |
1399 | emit_insn (gen_movsi (reg_rtx, offset_rtx)); | |
1400 | else | |
1401 | { | |
1402 | emit_insn (gen_movsi_high (reg_rtx, offset_rtx)); | |
1403 | emit_insn (gen_movsi_lo_sum (reg_rtx, offset_rtx)); | |
1404 | } | |
1405 | return reg_rtx; | |
1406 | } | |
1407 | } | |
1408 | ||
1409 | /* Generate (mem:MODE (plus:Pmode BASE (frv_frame_offset OFFSET)))). The | |
1410 | prologue and epilogue uses such expressions to access the stack. */ | |
1411 | static rtx | |
1412 | frv_frame_mem (mode, base, offset) | |
1413 | enum machine_mode mode; | |
1414 | rtx base; | |
1415 | int offset; | |
1416 | { | |
1417 | return gen_rtx_MEM (mode, gen_rtx_PLUS (Pmode, | |
1418 | base, | |
1419 | frv_frame_offset_rtx (offset))); | |
1420 | } | |
1421 | ||
1422 | /* Generate a frame-related expression: | |
1423 | ||
1424 | (set REG (mem (plus (sp) (const_int OFFSET)))). | |
1425 | ||
1426 | Such expressions are used in FRAME_RELATED_EXPR notes for more complex | |
1427 | instructions. Marking the expressions as frame-related is superfluous if | |
1428 | the note contains just a single set. But if the note contains a PARALLEL | |
1429 | or SEQUENCE that has several sets, each set must be individually marked | |
1430 | as frame-related. */ | |
1431 | static rtx | |
1432 | frv_dwarf_store (reg, offset) | |
1433 | rtx reg; | |
1434 | int offset; | |
1435 | { | |
1436 | rtx set = gen_rtx_SET (VOIDmode, | |
1437 | gen_rtx_MEM (GET_MODE (reg), | |
1438 | plus_constant (stack_pointer_rtx, | |
1439 | offset)), | |
1440 | reg); | |
1441 | RTX_FRAME_RELATED_P (set) = 1; | |
1442 | return set; | |
1443 | } | |
1444 | ||
1445 | /* Emit a frame-related instruction whose pattern is PATTERN. The | |
1446 | instruction is the last in a sequence that cumulatively performs the | |
1447 | operation described by DWARF_PATTERN. The instruction is marked as | |
1448 | frame-related and has a REG_FRAME_RELATED_EXPR note containing | |
1449 | DWARF_PATTERN. */ | |
1450 | static void | |
1451 | frv_frame_insn (pattern, dwarf_pattern) | |
1452 | rtx pattern; | |
1453 | rtx dwarf_pattern; | |
1454 | { | |
1455 | rtx insn = emit_insn (pattern); | |
1456 | RTX_FRAME_RELATED_P (insn) = 1; | |
1457 | REG_NOTES (insn) = alloc_EXPR_LIST (REG_FRAME_RELATED_EXPR, | |
1458 | dwarf_pattern, | |
1459 | REG_NOTES (insn)); | |
1460 | } | |
1461 | ||
1462 | /* Emit instructions that transfer REG to or from the memory location (sp + | |
1463 | STACK_OFFSET). The register is stored in memory if ACCESSOR->OP is | |
1464 | FRV_STORE and loaded if it is FRV_LOAD. Only the prologue uses this | |
1465 | function to store registers and only the epilogue uses it to load them. | |
1466 | ||
1467 | The caller sets up ACCESSOR so that BASE is equal to (sp + BASE_OFFSET). | |
1468 | The generated instruction will use BASE as its base register. BASE may | |
1469 | simply be the stack pointer, but if several accesses are being made to a | |
1470 | region far away from the stack pointer, it may be more efficient to set | |
1471 | up a temporary instead. | |
b16c1435 | 1472 | |
36a05131 BS |
1473 | Store instructions will be frame-related and will be annotated with the |
1474 | overall effect of the store. Load instructions will be followed by a | |
1475 | (use) to prevent later optimizations from zapping them. | |
1476 | ||
1477 | The function takes care of the moves to and from SPRs, using TEMP_REGNO | |
1478 | as a temporary in such cases. */ | |
1479 | static void | |
1480 | frv_frame_access (accessor, reg, stack_offset) | |
1481 | frv_frame_accessor_t *accessor; | |
1482 | rtx reg; | |
1483 | int stack_offset; | |
1484 | { | |
1485 | enum machine_mode mode = GET_MODE (reg); | |
1486 | rtx mem = frv_frame_mem (mode, | |
1487 | accessor->base, | |
1488 | stack_offset - accessor->base_offset); | |
1489 | ||
1490 | if (accessor->op == FRV_LOAD) | |
1491 | { | |
1492 | if (SPR_P (REGNO (reg))) | |
1493 | { | |
1494 | rtx temp = gen_rtx_REG (mode, TEMP_REGNO); | |
1495 | emit_insn (gen_rtx_SET (VOIDmode, temp, mem)); | |
1496 | emit_insn (gen_rtx_SET (VOIDmode, reg, temp)); | |
1497 | } | |
1498 | else | |
1499 | emit_insn (gen_rtx_SET (VOIDmode, reg, mem)); | |
1500 | emit_insn (gen_rtx_USE (VOIDmode, reg)); | |
1501 | } | |
1502 | else | |
1503 | { | |
1504 | if (SPR_P (REGNO (reg))) | |
1505 | { | |
1506 | rtx temp = gen_rtx_REG (mode, TEMP_REGNO); | |
1507 | emit_insn (gen_rtx_SET (VOIDmode, temp, reg)); | |
1508 | frv_frame_insn (gen_rtx_SET (Pmode, mem, temp), | |
1509 | frv_dwarf_store (reg, stack_offset)); | |
1510 | } | |
1511 | else if (GET_MODE (reg) == DImode) | |
1512 | { | |
1513 | /* For DImode saves, the dwarf2 version needs to be a SEQUENCE | |
1514 | with a separate save for each register. */ | |
1515 | rtx reg1 = gen_rtx_REG (SImode, REGNO (reg)); | |
1516 | rtx reg2 = gen_rtx_REG (SImode, REGNO (reg) + 1); | |
1517 | rtx set1 = frv_dwarf_store (reg1, stack_offset); | |
1518 | rtx set2 = frv_dwarf_store (reg2, stack_offset + 4); | |
1519 | frv_frame_insn (gen_rtx_SET (Pmode, mem, reg), | |
1520 | gen_rtx_PARALLEL (VOIDmode, | |
1521 | gen_rtvec (2, set1, set2))); | |
1522 | } | |
1523 | else | |
1524 | frv_frame_insn (gen_rtx_SET (Pmode, mem, reg), | |
1525 | frv_dwarf_store (reg, stack_offset)); | |
1526 | } | |
1527 | } | |
1528 | ||
1529 | /* A function that uses frv_frame_access to transfer a group of registers to | |
1530 | or from the stack. ACCESSOR is passed directly to frv_frame_access, INFO | |
1531 | is the stack information generated by frv_stack_info, and REG_SET is the | |
1532 | number of the register set to transfer. */ | |
1533 | static void | |
1534 | frv_frame_access_multi (accessor, info, reg_set) | |
1535 | frv_frame_accessor_t *accessor; | |
1536 | frv_stack_t *info; | |
1537 | int reg_set; | |
1538 | { | |
1539 | frv_stack_regs_t *regs_info; | |
1540 | int regno; | |
1541 | ||
1542 | regs_info = &info->regs[reg_set]; | |
1543 | for (regno = regs_info->first; regno <= regs_info->last; regno++) | |
1544 | if (info->save_p[regno]) | |
1545 | frv_frame_access (accessor, | |
1546 | info->save_p[regno] == REG_SAVE_2WORDS | |
1547 | ? gen_rtx_REG (DImode, regno) | |
1548 | : gen_rtx_REG (SImode, regno), | |
1549 | info->reg_offset[regno]); | |
1550 | } | |
1551 | ||
1552 | /* Save or restore callee-saved registers that are kept outside the frame | |
1553 | header. The function saves the registers if OP is FRV_STORE and restores | |
1554 | them if OP is FRV_LOAD. INFO is the stack information generated by | |
1555 | frv_stack_info. */ | |
1556 | static void | |
1557 | frv_frame_access_standard_regs (op, info) | |
1558 | enum frv_stack_op op; | |
1559 | frv_stack_t *info; | |
1560 | { | |
1561 | frv_frame_accessor_t accessor; | |
1562 | ||
1563 | accessor.op = op; | |
1564 | accessor.base = stack_pointer_rtx; | |
1565 | accessor.base_offset = 0; | |
1566 | frv_frame_access_multi (&accessor, info, STACK_REGS_GPR); | |
1567 | frv_frame_access_multi (&accessor, info, STACK_REGS_FPR); | |
1568 | frv_frame_access_multi (&accessor, info, STACK_REGS_LCR); | |
b16c1435 | 1569 | } |
36a05131 BS |
1570 | |
1571 | ||
1572 | /* Called after register allocation to add any instructions needed for the | |
1573 | prologue. Using a prologue insn is favored compared to putting all of the | |
1574 | instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler | |
1575 | to intermix instructions with the saves of the caller saved registers. In | |
1576 | some cases, it might be necessary to emit a barrier instruction as the last | |
1577 | insn to prevent such scheduling. | |
1578 | ||
1579 | Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1 | |
1580 | so that the debug info generation code can handle them properly. */ | |
1581 | void | |
1582 | frv_expand_prologue () | |
1583 | { | |
1584 | frv_stack_t *info = frv_stack_info (); | |
1585 | rtx sp = stack_pointer_rtx; | |
1586 | rtx fp = frame_pointer_rtx; | |
1587 | frv_frame_accessor_t accessor; | |
1588 | ||
1589 | if (TARGET_DEBUG_STACK) | |
1590 | frv_debug_stack (info); | |
1591 | ||
1592 | if (info->total_size == 0) | |
1593 | return; | |
1594 | ||
1595 | /* We're interested in three areas of the frame here: | |
1596 | ||
1597 | A: the register save area | |
1598 | B: the old FP | |
1599 | C: the header after B | |
1600 | ||
1601 | If the frame pointer isn't used, we'll have to set up A, B and C | |
1602 | using the stack pointer. If the frame pointer is used, we'll access | |
1603 | them as follows: | |
1604 | ||
1605 | A: set up using sp | |
1606 | B: set up using sp or a temporary (see below) | |
1607 | C: set up using fp | |
1608 | ||
1609 | We set up B using the stack pointer if the frame is small enough. | |
1610 | Otherwise, it's more efficient to copy the old stack pointer into a | |
1611 | temporary and use that. | |
1612 | ||
1613 | Note that it's important to make sure the prologue and epilogue use the | |
1614 | same registers to access A and C, since doing otherwise will confuse | |
1615 | the aliasing code. */ | |
1616 | ||
1617 | /* Set up ACCESSOR for accessing region B above. If the frame pointer | |
1618 | isn't used, the same method will serve for C. */ | |
1619 | accessor.op = FRV_STORE; | |
1620 | if (frame_pointer_needed && info->total_size > 2048) | |
1621 | { | |
1622 | rtx insn; | |
1623 | ||
1624 | accessor.base = gen_rtx_REG (Pmode, OLD_SP_REGNO); | |
1625 | accessor.base_offset = info->total_size; | |
1626 | insn = emit_insn (gen_movsi (accessor.base, sp)); | |
1627 | } | |
1628 | else | |
1629 | { | |
1630 | accessor.base = stack_pointer_rtx; | |
1631 | accessor.base_offset = 0; | |
1632 | } | |
1633 | ||
1634 | /* Allocate the stack space. */ | |
1635 | { | |
1636 | rtx asm_offset = frv_frame_offset_rtx (-info->total_size); | |
1637 | rtx dwarf_offset = GEN_INT (-info->total_size); | |
1638 | ||
1639 | frv_frame_insn (gen_stack_adjust (sp, sp, asm_offset), | |
1640 | gen_rtx_SET (Pmode, | |
1641 | sp, | |
1642 | gen_rtx_PLUS (Pmode, sp, dwarf_offset))); | |
1643 | } | |
1644 | ||
1645 | /* If the frame pointer is needed, store the old one at (sp + FP_OFFSET) | |
1646 | and point the new one to that location. */ | |
1647 | if (frame_pointer_needed) | |
1648 | { | |
1649 | int fp_offset = info->reg_offset[FRAME_POINTER_REGNUM]; | |
1650 | ||
1651 | /* ASM_SRC and DWARF_SRC both point to the frame header. ASM_SRC is | |
1652 | based on ACCESSOR.BASE but DWARF_SRC is always based on the stack | |
1653 | pointer. */ | |
1654 | rtx asm_src = plus_constant (accessor.base, | |
1655 | fp_offset - accessor.base_offset); | |
1656 | rtx dwarf_src = plus_constant (sp, fp_offset); | |
1657 | ||
1658 | /* Store the old frame pointer at (sp + FP_OFFSET). */ | |
1659 | frv_frame_access (&accessor, fp, fp_offset); | |
1660 | ||
1661 | /* Set up the new frame pointer. */ | |
1662 | frv_frame_insn (gen_rtx_SET (VOIDmode, fp, asm_src), | |
1663 | gen_rtx_SET (VOIDmode, fp, dwarf_src)); | |
1664 | ||
1665 | /* Access region C from the frame pointer. */ | |
1666 | accessor.base = fp; | |
1667 | accessor.base_offset = fp_offset; | |
1668 | } | |
1669 | ||
1670 | /* Set up region C. */ | |
1671 | frv_frame_access_multi (&accessor, info, STACK_REGS_STRUCT); | |
1672 | frv_frame_access_multi (&accessor, info, STACK_REGS_LR); | |
1673 | frv_frame_access_multi (&accessor, info, STACK_REGS_STDARG); | |
1674 | ||
1675 | /* Set up region A. */ | |
1676 | frv_frame_access_standard_regs (FRV_STORE, info); | |
1677 | ||
1678 | /* If this is a varargs/stdarg function, issue a blockage to prevent the | |
1679 | scheduler from moving loads before the stores saving the registers. */ | |
1680 | if (info->stdarg_size > 0) | |
1681 | emit_insn (gen_blockage ()); | |
1682 | ||
1683 | /* Set up pic register/small data register for this function. */ | |
1684 | if (flag_pic && cfun->uses_pic_offset_table) | |
1685 | emit_insn (gen_pic_prologue (gen_rtx_REG (Pmode, PIC_REGNO), | |
1686 | gen_rtx_REG (Pmode, LR_REGNO), | |
1687 | gen_rtx_REG (SImode, OFFSET_REGNO))); | |
1688 | } | |
1689 | ||
1690 | \f | |
1691 | /* Under frv, all of the work is done via frv_expand_epilogue, but | |
1692 | this function provides a convient place to do cleanup. */ | |
1693 | ||
1694 | static void | |
1695 | frv_function_epilogue (file, size) | |
1696 | FILE *file ATTRIBUTE_UNUSED; | |
1697 | HOST_WIDE_INT size ATTRIBUTE_UNUSED; | |
1698 | { | |
1699 | frv_stack_cache = (frv_stack_t *)0; | |
1700 | ||
1701 | /* zap last used registers for conditional execution. */ | |
fad205ff | 1702 | memset (&frv_ifcvt.tmp_reg, 0, sizeof (frv_ifcvt.tmp_reg)); |
36a05131 BS |
1703 | |
1704 | /* release the bitmap of created insns. */ | |
1705 | BITMAP_XFREE (frv_ifcvt.scratch_insns_bitmap); | |
1706 | } | |
1707 | ||
1708 | \f | |
1709 | /* Called after register allocation to add any instructions needed for the | |
43aa4e05 | 1710 | epilogue. Using an epilogue insn is favored compared to putting all of the |
36a05131 BS |
1711 | instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler |
1712 | to intermix instructions with the saves of the caller saved registers. In | |
1713 | some cases, it might be necessary to emit a barrier instruction as the last | |
1714 | insn to prevent such scheduling. | |
1715 | ||
1716 | If SIBCALL_P is true, the final branch back to the calling function is | |
1717 | omitted, and is used for sibling call (aka tail call) sites. For sibcalls, | |
1718 | we must not clobber any arguments used for parameter passing or any stack | |
1719 | slots for arguments passed to the current function. */ | |
1720 | ||
1721 | void | |
1722 | frv_expand_epilogue (sibcall_p) | |
1723 | int sibcall_p; | |
1724 | { | |
1725 | frv_stack_t *info = frv_stack_info (); | |
1726 | rtx fp = frame_pointer_rtx; | |
1727 | rtx sp = stack_pointer_rtx; | |
1728 | rtx return_addr; | |
1729 | int fp_offset; | |
1730 | ||
1731 | fp_offset = info->reg_offset[FRAME_POINTER_REGNUM]; | |
1732 | ||
1733 | /* Restore the stack pointer to its original value if alloca or the like | |
1734 | is used. */ | |
1735 | if (! current_function_sp_is_unchanging) | |
1736 | emit_insn (gen_addsi3 (sp, fp, frv_frame_offset_rtx (-fp_offset))); | |
1737 | ||
1738 | /* Restore the callee-saved registers that were used in this function. */ | |
1739 | frv_frame_access_standard_regs (FRV_LOAD, info); | |
1740 | ||
1741 | /* Set RETURN_ADDR to the address we should return to. Set it to NULL if | |
1742 | no return instruction should be emitted. */ | |
1743 | if (sibcall_p) | |
1744 | return_addr = 0; | |
1745 | else if (info->save_p[LR_REGNO]) | |
1746 | { | |
1747 | int lr_offset; | |
1748 | rtx mem; | |
1749 | ||
1750 | /* Use the same method to access the link register's slot as we did in | |
1751 | the prologue. In other words, use the frame pointer if available, | |
1752 | otherwise use the stack pointer. | |
1753 | ||
1754 | LR_OFFSET is the offset of the link register's slot from the start | |
1755 | of the frame and MEM is a memory rtx for it. */ | |
1756 | lr_offset = info->reg_offset[LR_REGNO]; | |
1757 | if (frame_pointer_needed) | |
1758 | mem = frv_frame_mem (Pmode, fp, lr_offset - fp_offset); | |
1759 | else | |
1760 | mem = frv_frame_mem (Pmode, sp, lr_offset); | |
1761 | ||
1762 | /* Load the old link register into a GPR. */ | |
1763 | return_addr = gen_rtx_REG (Pmode, TEMP_REGNO); | |
1764 | emit_insn (gen_rtx_SET (VOIDmode, return_addr, mem)); | |
1765 | } | |
1766 | else | |
1767 | return_addr = gen_rtx_REG (Pmode, LR_REGNO); | |
1768 | ||
1769 | /* Restore the old frame pointer. Emit a USE afterwards to make sure | |
1770 | the load is preserved. */ | |
1771 | if (frame_pointer_needed) | |
1772 | { | |
1773 | emit_insn (gen_rtx_SET (VOIDmode, fp, gen_rtx_MEM (Pmode, fp))); | |
1774 | emit_insn (gen_rtx_USE (VOIDmode, fp)); | |
1775 | } | |
1776 | ||
1777 | /* Deallocate the stack frame. */ | |
1778 | if (info->total_size != 0) | |
1779 | { | |
1780 | rtx offset = frv_frame_offset_rtx (info->total_size); | |
1781 | emit_insn (gen_stack_adjust (sp, sp, offset)); | |
1782 | } | |
1783 | ||
1784 | /* If this function uses eh_return, add the final stack adjustment now. */ | |
1785 | if (current_function_calls_eh_return) | |
1786 | emit_insn (gen_stack_adjust (sp, sp, EH_RETURN_STACKADJ_RTX)); | |
1787 | ||
1788 | if (return_addr) | |
1789 | emit_jump_insn (gen_epilogue_return (return_addr)); | |
1790 | } | |
1791 | ||
1792 | \f | |
1793 | /* A C compound statement that outputs the assembler code for a thunk function, | |
1794 | used to implement C++ virtual function calls with multiple inheritance. The | |
1795 | thunk acts as a wrapper around a virtual function, adjusting the implicit | |
1796 | object parameter before handing control off to the real function. | |
1797 | ||
1798 | First, emit code to add the integer DELTA to the location that contains the | |
1799 | incoming first argument. Assume that this argument contains a pointer, and | |
1800 | is the one used to pass the `this' pointer in C++. This is the incoming | |
1801 | argument *before* the function prologue, e.g. `%o0' on a sparc. The | |
1802 | addition must preserve the values of all other incoming arguments. | |
1803 | ||
1804 | After the addition, emit code to jump to FUNCTION, which is a | |
1805 | `FUNCTION_DECL'. This is a direct pure jump, not a call, and does not touch | |
1806 | the return address. Hence returning from FUNCTION will return to whoever | |
1807 | called the current `thunk'. | |
1808 | ||
1809 | The effect must be as if FUNCTION had been called directly with the adjusted | |
1810 | first argument. This macro is responsible for emitting all of the code for | |
1811 | a thunk function; `FUNCTION_PROLOGUE' and `FUNCTION_EPILOGUE' are not | |
1812 | invoked. | |
1813 | ||
1814 | The THUNK_FNDECL is redundant. (DELTA and FUNCTION have already been | |
1815 | extracted from it.) It might possibly be useful on some targets, but | |
1816 | probably not. | |
1817 | ||
1818 | If you do not define this macro, the target-independent code in the C++ | |
1819 | frontend will generate a less efficient heavyweight thunk that calls | |
1820 | FUNCTION instead of jumping to it. The generic approach does not support | |
1821 | varargs. */ | |
1822 | ||
c590b625 | 1823 | static void |
3961e8fe | 1824 | frv_asm_output_mi_thunk (file, thunk_fndecl, delta, vcall_offset, function) |
36a05131 BS |
1825 | FILE *file; |
1826 | tree thunk_fndecl ATTRIBUTE_UNUSED; | |
eb0424da | 1827 | HOST_WIDE_INT delta; |
3961e8fe | 1828 | HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED; |
36a05131 BS |
1829 | tree function; |
1830 | { | |
1831 | const char *name_func = XSTR (XEXP (DECL_RTL (function), 0), 0); | |
1832 | const char *name_arg0 = reg_names[FIRST_ARG_REGNUM]; | |
1833 | const char *name_jmp = reg_names[JUMP_REGNO]; | |
1834 | const char *parallel = ((PACKING_FLAG_USED_P ()) ? ".p" : ""); | |
1835 | ||
1836 | /* Do the add using an addi if possible */ | |
1837 | if (IN_RANGE_P (delta, -2048, 2047)) | |
eb0424da | 1838 | fprintf (file, "\taddi %s,#%d,%s\n", name_arg0, (int) delta, name_arg0); |
36a05131 BS |
1839 | else |
1840 | { | |
4a0a75dd KG |
1841 | const char *const name_add = reg_names[TEMP_REGNO]; |
1842 | fprintf (file, "\tsethi%s #hi(" HOST_WIDE_INT_PRINT_DEC "),%s\n", | |
1843 | parallel, delta, name_add); | |
1844 | fprintf (file, "\tsetlo #lo(" HOST_WIDE_INT_PRINT_DEC "),%s\n", | |
1845 | delta, name_add); | |
36a05131 BS |
1846 | fprintf (file, "\tadd %s,%s,%s\n", name_add, name_arg0, name_arg0); |
1847 | } | |
1848 | ||
1849 | if (!flag_pic) | |
1850 | { | |
1851 | fprintf (file, "\tsethi%s #hi(", parallel); | |
1852 | assemble_name (file, name_func); | |
1853 | fprintf (file, "),%s\n", name_jmp); | |
1854 | ||
1855 | fprintf (file, "\tsetlo #lo("); | |
1856 | assemble_name (file, name_func); | |
1857 | fprintf (file, "),%s\n", name_jmp); | |
1858 | } | |
1859 | else | |
1860 | { | |
1861 | /* Use JUMP_REGNO as a temporary PIC register. */ | |
1862 | const char *name_lr = reg_names[LR_REGNO]; | |
1863 | const char *name_gppic = name_jmp; | |
1864 | const char *name_tmp = reg_names[TEMP_REGNO]; | |
1865 | ||
1866 | fprintf (file, "\tmovsg %s,%s\n", name_lr, name_tmp); | |
1867 | fprintf (file, "\tcall 1f\n"); | |
1868 | fprintf (file, "1:\tmovsg %s,%s\n", name_lr, name_gppic); | |
1869 | fprintf (file, "\tmovgs %s,%s\n", name_tmp, name_lr); | |
1870 | fprintf (file, "\tsethi%s #gprelhi(1b),%s\n", parallel, name_tmp); | |
1871 | fprintf (file, "\tsetlo #gprello(1b),%s\n", name_tmp); | |
1872 | fprintf (file, "\tsub %s,%s,%s\n", name_gppic, name_tmp, name_gppic); | |
1873 | ||
1874 | fprintf (file, "\tsethi%s #gprelhi(", parallel); | |
1875 | assemble_name (file, name_func); | |
1876 | fprintf (file, "),%s\n", name_tmp); | |
1877 | ||
1878 | fprintf (file, "\tsetlo #gprello("); | |
1879 | assemble_name (file, name_func); | |
1880 | fprintf (file, "),%s\n", name_tmp); | |
1881 | ||
1882 | fprintf (file, "\tadd %s,%s,%s\n", name_gppic, name_tmp, name_jmp); | |
1883 | } | |
1884 | ||
1885 | /* Jump to the function address */ | |
1886 | fprintf (file, "\tjmpl @(%s,%s)\n", name_jmp, reg_names[GPR_FIRST+0]); | |
1887 | } | |
1888 | ||
1889 | \f | |
1890 | /* A C expression which is nonzero if a function must have and use a frame | |
1891 | pointer. This expression is evaluated in the reload pass. If its value is | |
1892 | nonzero the function will have a frame pointer. | |
1893 | ||
1894 | The expression can in principle examine the current function and decide | |
1895 | according to the facts, but on most machines the constant 0 or the constant | |
1896 | 1 suffices. Use 0 when the machine allows code to be generated with no | |
1897 | frame pointer, and doing so saves some time or space. Use 1 when there is | |
1898 | no possible advantage to avoiding a frame pointer. | |
1899 | ||
1900 | In certain cases, the compiler does not know how to produce valid code | |
1901 | without a frame pointer. The compiler recognizes those cases and | |
1902 | automatically gives the function a frame pointer regardless of what | |
1903 | `FRAME_POINTER_REQUIRED' says. You don't need to worry about them. | |
1904 | ||
1905 | In a function that does not require a frame pointer, the frame pointer | |
1906 | register can be allocated for ordinary usage, unless you mark it as a fixed | |
1907 | register. See `FIXED_REGISTERS' for more information. */ | |
1908 | ||
1909 | /* On frv, create a frame whenever we need to create stack */ | |
1910 | ||
1911 | int | |
1912 | frv_frame_pointer_required () | |
1913 | { | |
1914 | if (! current_function_is_leaf) | |
1915 | return TRUE; | |
1916 | ||
1917 | if (get_frame_size () != 0) | |
1918 | return TRUE; | |
1919 | ||
1920 | if (cfun->stdarg) | |
1921 | return TRUE; | |
1922 | ||
1923 | if (!current_function_sp_is_unchanging) | |
1924 | return TRUE; | |
1925 | ||
1926 | if (flag_pic && cfun->uses_pic_offset_table) | |
1927 | return TRUE; | |
1928 | ||
1929 | if (profile_flag) | |
1930 | return TRUE; | |
1931 | ||
1932 | if (cfun->machine->frame_needed) | |
1933 | return TRUE; | |
1934 | ||
1935 | return FALSE; | |
1936 | } | |
1937 | ||
1938 | \f | |
1939 | /* This macro is similar to `INITIAL_FRAME_POINTER_OFFSET'. It specifies the | |
1940 | initial difference between the specified pair of registers. This macro must | |
1941 | be defined if `ELIMINABLE_REGS' is defined. */ | |
1942 | ||
1943 | /* See frv_stack_info for more details on the frv stack frame. */ | |
1944 | ||
1945 | int | |
1946 | frv_initial_elimination_offset (from, to) | |
1947 | int from; | |
1948 | int to; | |
1949 | { | |
1950 | frv_stack_t *info = frv_stack_info (); | |
1951 | int ret = 0; | |
1952 | ||
1953 | if (to == STACK_POINTER_REGNUM && from == ARG_POINTER_REGNUM) | |
1954 | ret = info->total_size - info->pretend_size; | |
1955 | ||
1956 | else if (to == STACK_POINTER_REGNUM && from == FRAME_POINTER_REGNUM) | |
1957 | ret = - info->reg_offset[FRAME_POINTER_REGNUM]; | |
1958 | ||
1959 | else if (to == FRAME_POINTER_REGNUM && from == ARG_POINTER_REGNUM) | |
1960 | ret = (info->total_size | |
1961 | - info->reg_offset[FRAME_POINTER_REGNUM] | |
1962 | - info->pretend_size); | |
1963 | ||
1964 | else | |
1965 | abort (); | |
1966 | ||
1967 | if (TARGET_DEBUG_STACK) | |
1968 | fprintf (stderr, "Eliminate %s to %s by adding %d\n", | |
1969 | reg_names [from], reg_names[to], ret); | |
1970 | ||
1971 | return ret; | |
1972 | } | |
1973 | ||
1974 | \f | |
1975 | /* This macro offers an alternative to using `__builtin_saveregs' and defining | |
1976 | the macro `EXPAND_BUILTIN_SAVEREGS'. Use it to store the anonymous register | |
1977 | arguments into the stack so that all the arguments appear to have been | |
1978 | passed consecutively on the stack. Once this is done, you can use the | |
1979 | standard implementation of varargs that works for machines that pass all | |
1980 | their arguments on the stack. | |
1981 | ||
1982 | The argument ARGS_SO_FAR is the `CUMULATIVE_ARGS' data structure, containing | |
1983 | the values that obtain after processing of the named arguments. The | |
1984 | arguments MODE and TYPE describe the last named argument--its machine mode | |
1985 | and its data type as a tree node. | |
1986 | ||
1987 | The macro implementation should do two things: first, push onto the stack | |
1988 | all the argument registers *not* used for the named arguments, and second, | |
1989 | store the size of the data thus pushed into the `int'-valued variable whose | |
1990 | name is supplied as the argument PRETEND_ARGS_SIZE. The value that you | |
1991 | store here will serve as additional offset for setting up the stack frame. | |
1992 | ||
1993 | Because you must generate code to push the anonymous arguments at compile | |
1994 | time without knowing their data types, `SETUP_INCOMING_VARARGS' is only | |
1995 | useful on machines that have just a single category of argument register and | |
1996 | use it uniformly for all data types. | |
1997 | ||
1998 | If the argument SECOND_TIME is nonzero, it means that the arguments of the | |
1999 | function are being analyzed for the second time. This happens for an inline | |
2000 | function, which is not actually compiled until the end of the source file. | |
2001 | The macro `SETUP_INCOMING_VARARGS' should not generate any instructions in | |
2002 | this case. */ | |
2003 | ||
2004 | void | |
2005 | frv_setup_incoming_varargs (cum, mode, type, pretend_size, second_time) | |
2006 | CUMULATIVE_ARGS *cum; | |
2007 | enum machine_mode mode; | |
2008 | tree type ATTRIBUTE_UNUSED; | |
2009 | int *pretend_size; | |
2010 | int second_time; | |
2011 | { | |
2012 | if (TARGET_DEBUG_ARG) | |
2013 | fprintf (stderr, | |
2014 | "setup_vararg: words = %2d, mode = %4s, pretend_size = %d, second_time = %d\n", | |
2015 | *cum, GET_MODE_NAME (mode), *pretend_size, second_time); | |
2016 | } | |
2017 | ||
2018 | \f | |
2019 | /* If defined, is a C expression that produces the machine-specific code for a | |
2020 | call to `__builtin_saveregs'. This code will be moved to the very beginning | |
2021 | of the function, before any parameter access are made. The return value of | |
2022 | this function should be an RTX that contains the value to use as the return | |
2023 | of `__builtin_saveregs'. | |
2024 | ||
2025 | If this macro is not defined, the compiler will output an ordinary call to | |
2026 | the library function `__builtin_saveregs'. */ | |
2027 | ||
2028 | rtx | |
2029 | frv_expand_builtin_saveregs () | |
2030 | { | |
2031 | int offset = UNITS_PER_WORD * FRV_NUM_ARG_REGS; | |
2032 | ||
2033 | if (TARGET_DEBUG_ARG) | |
2034 | fprintf (stderr, "expand_builtin_saveregs: offset from ap = %d\n", | |
2035 | offset); | |
2036 | ||
2037 | return gen_rtx (PLUS, Pmode, virtual_incoming_args_rtx, GEN_INT (- offset)); | |
2038 | } | |
2039 | ||
2040 | \f | |
2041 | /* Expand __builtin_va_start to do the va_start macro. */ | |
2042 | ||
2043 | void | |
2044 | frv_expand_builtin_va_start (valist, nextarg) | |
2045 | tree valist; | |
2046 | rtx nextarg; | |
2047 | { | |
2048 | tree t; | |
2049 | int num = cfun->args_info - FIRST_ARG_REGNUM - FRV_NUM_ARG_REGS; | |
2050 | ||
2051 | nextarg = gen_rtx_PLUS (Pmode, virtual_incoming_args_rtx, | |
2052 | GEN_INT (UNITS_PER_WORD * num)); | |
2053 | ||
2054 | if (TARGET_DEBUG_ARG) | |
2055 | { | |
2056 | fprintf (stderr, "va_start: args_info = %d, num = %d\n", | |
2057 | cfun->args_info, num); | |
2058 | ||
2059 | debug_rtx (nextarg); | |
2060 | } | |
2061 | ||
2062 | t = build (MODIFY_EXPR, TREE_TYPE (valist), valist, | |
2063 | make_tree (ptr_type_node, nextarg)); | |
2064 | TREE_SIDE_EFFECTS (t) = 1; | |
2065 | ||
2066 | expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL); | |
2067 | } | |
2068 | ||
2069 | \f | |
2070 | /* Expand __builtin_va_arg to do the va_arg macro. */ | |
2071 | ||
2072 | rtx | |
2073 | frv_expand_builtin_va_arg(valist, type) | |
2074 | tree valist; | |
2075 | tree type; | |
2076 | { | |
2077 | rtx addr; | |
2078 | rtx mem; | |
2079 | rtx reg; | |
2080 | ||
2081 | if (TARGET_DEBUG_ARG) | |
2082 | { | |
2083 | fprintf (stderr, "va_arg:\n"); | |
2084 | debug_tree (type); | |
2085 | } | |
2086 | ||
2087 | if (! AGGREGATE_TYPE_P (type)) | |
2088 | return std_expand_builtin_va_arg (valist, type); | |
2089 | ||
2090 | addr = std_expand_builtin_va_arg (valist, ptr_type_node); | |
2091 | mem = gen_rtx_MEM (Pmode, addr); | |
2092 | reg = gen_reg_rtx (Pmode); | |
2093 | ||
2094 | set_mem_alias_set (mem, get_varargs_alias_set ()); | |
2095 | emit_move_insn (reg, mem); | |
2096 | ||
2097 | return reg; | |
2098 | } | |
2099 | ||
2100 | \f | |
2101 | /* Expand a block move operation, and return 1 if successful. Return 0 | |
2102 | if we should let the compiler generate normal code. | |
2103 | ||
2104 | operands[0] is the destination | |
2105 | operands[1] is the source | |
2106 | operands[2] is the length | |
2107 | operands[3] is the alignment */ | |
2108 | ||
2109 | /* Maximum number of loads to do before doing the stores */ | |
2110 | #ifndef MAX_MOVE_REG | |
2111 | #define MAX_MOVE_REG 4 | |
2112 | #endif | |
2113 | ||
2114 | /* Maximum number of total loads to do. */ | |
2115 | #ifndef TOTAL_MOVE_REG | |
2116 | #define TOTAL_MOVE_REG 8 | |
2117 | #endif | |
2118 | ||
2119 | int | |
2120 | frv_expand_block_move (operands) | |
2121 | rtx operands[]; | |
2122 | { | |
2123 | rtx orig_dest = operands[0]; | |
2124 | rtx orig_src = operands[1]; | |
2125 | rtx bytes_rtx = operands[2]; | |
2126 | rtx align_rtx = operands[3]; | |
2127 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); | |
2128 | int align; | |
2129 | int bytes; | |
2130 | int offset; | |
2131 | int num_reg; | |
2132 | int i; | |
2133 | rtx src_reg; | |
2134 | rtx dest_reg; | |
2135 | rtx src_addr; | |
2136 | rtx dest_addr; | |
2137 | rtx src_mem; | |
2138 | rtx dest_mem; | |
2139 | rtx tmp_reg; | |
2140 | rtx stores[MAX_MOVE_REG]; | |
2141 | int move_bytes; | |
2142 | enum machine_mode mode; | |
2143 | ||
2144 | /* If this is not a fixed size move, just call memcpy */ | |
2145 | if (! constp) | |
2146 | return FALSE; | |
2147 | ||
2148 | /* If this is not a fixed size alignment, abort */ | |
2149 | if (GET_CODE (align_rtx) != CONST_INT) | |
2150 | abort (); | |
2151 | ||
2152 | align = INTVAL (align_rtx); | |
2153 | ||
2154 | /* Anything to move? */ | |
2155 | bytes = INTVAL (bytes_rtx); | |
2156 | if (bytes <= 0) | |
2157 | return TRUE; | |
2158 | ||
2159 | /* Don't support real large moves. */ | |
2160 | if (bytes > TOTAL_MOVE_REG*align) | |
2161 | return FALSE; | |
2162 | ||
2163 | /* Move the address into scratch registers. */ | |
2164 | dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0)); | |
2165 | src_reg = copy_addr_to_reg (XEXP (orig_src, 0)); | |
2166 | ||
2167 | num_reg = offset = 0; | |
2168 | for ( ; bytes > 0; (bytes -= move_bytes), (offset += move_bytes)) | |
2169 | { | |
2170 | /* Calculate the correct offset for src/dest */ | |
2171 | if (offset == 0) | |
2172 | { | |
2173 | src_addr = src_reg; | |
2174 | dest_addr = dest_reg; | |
2175 | } | |
2176 | else | |
2177 | { | |
2178 | src_addr = plus_constant (src_reg, offset); | |
2179 | dest_addr = plus_constant (dest_reg, offset); | |
2180 | } | |
2181 | ||
2182 | /* Generate the appropriate load and store, saving the stores | |
2183 | for later. */ | |
2184 | if (bytes >= 4 && align >= 4) | |
2185 | mode = SImode; | |
2186 | else if (bytes >= 2 && align >= 2) | |
2187 | mode = HImode; | |
2188 | else | |
2189 | mode = QImode; | |
2190 | ||
2191 | move_bytes = GET_MODE_SIZE (mode); | |
2192 | tmp_reg = gen_reg_rtx (mode); | |
2193 | src_mem = change_address (orig_src, mode, src_addr); | |
2194 | dest_mem = change_address (orig_dest, mode, dest_addr); | |
2195 | emit_insn (gen_rtx_SET (VOIDmode, tmp_reg, src_mem)); | |
2196 | stores[num_reg++] = gen_rtx_SET (VOIDmode, dest_mem, tmp_reg); | |
2197 | ||
2198 | if (num_reg >= MAX_MOVE_REG) | |
2199 | { | |
2200 | for (i = 0; i < num_reg; i++) | |
2201 | emit_insn (stores[i]); | |
2202 | num_reg = 0; | |
2203 | } | |
2204 | } | |
2205 | ||
2206 | for (i = 0; i < num_reg; i++) | |
2207 | emit_insn (stores[i]); | |
2208 | ||
2209 | return TRUE; | |
2210 | } | |
2211 | ||
2212 | \f | |
2213 | /* Expand a block clear operation, and return 1 if successful. Return 0 | |
2214 | if we should let the compiler generate normal code. | |
2215 | ||
2216 | operands[0] is the destination | |
2217 | operands[1] is the length | |
2218 | operands[2] is the alignment */ | |
2219 | ||
2220 | int | |
2221 | frv_expand_block_clear (operands) | |
2222 | rtx operands[]; | |
2223 | { | |
2224 | rtx orig_dest = operands[0]; | |
2225 | rtx bytes_rtx = operands[1]; | |
2226 | rtx align_rtx = operands[2]; | |
2227 | int constp = (GET_CODE (bytes_rtx) == CONST_INT); | |
2228 | int align; | |
2229 | int bytes; | |
2230 | int offset; | |
2231 | int num_reg; | |
2232 | rtx dest_reg; | |
2233 | rtx dest_addr; | |
2234 | rtx dest_mem; | |
2235 | int clear_bytes; | |
2236 | enum machine_mode mode; | |
2237 | ||
2238 | /* If this is not a fixed size move, just call memcpy */ | |
2239 | if (! constp) | |
2240 | return FALSE; | |
2241 | ||
2242 | /* If this is not a fixed size alignment, abort */ | |
2243 | if (GET_CODE (align_rtx) != CONST_INT) | |
2244 | abort (); | |
2245 | ||
2246 | align = INTVAL (align_rtx); | |
2247 | ||
2248 | /* Anything to move? */ | |
2249 | bytes = INTVAL (bytes_rtx); | |
2250 | if (bytes <= 0) | |
2251 | return TRUE; | |
2252 | ||
2253 | /* Don't support real large clears. */ | |
2254 | if (bytes > TOTAL_MOVE_REG*align) | |
2255 | return FALSE; | |
2256 | ||
2257 | /* Move the address into a scratch register. */ | |
2258 | dest_reg = copy_addr_to_reg (XEXP (orig_dest, 0)); | |
2259 | ||
2260 | num_reg = offset = 0; | |
2261 | for ( ; bytes > 0; (bytes -= clear_bytes), (offset += clear_bytes)) | |
2262 | { | |
2263 | /* Calculate the correct offset for src/dest */ | |
2264 | dest_addr = ((offset == 0) | |
2265 | ? dest_reg | |
2266 | : plus_constant (dest_reg, offset)); | |
2267 | ||
2268 | /* Generate the appropriate store of gr0 */ | |
2269 | if (bytes >= 4 && align >= 4) | |
2270 | mode = SImode; | |
2271 | else if (bytes >= 2 && align >= 2) | |
2272 | mode = HImode; | |
2273 | else | |
2274 | mode = QImode; | |
2275 | ||
2276 | clear_bytes = GET_MODE_SIZE (mode); | |
2277 | dest_mem = change_address (orig_dest, mode, dest_addr); | |
2278 | emit_insn (gen_rtx_SET (VOIDmode, dest_mem, const0_rtx)); | |
2279 | } | |
2280 | ||
2281 | return TRUE; | |
2282 | } | |
2283 | ||
2284 | \f | |
2285 | /* The following variable is used to output modifiers of assembler | |
2286 | code of the current output insn.. */ | |
2287 | ||
2288 | static rtx *frv_insn_operands; | |
2289 | ||
2290 | /* The following function is used to add assembler insn code suffix .p | |
2291 | if it is necessary. */ | |
2292 | ||
2293 | const char * | |
2294 | frv_asm_output_opcode (f, ptr) | |
2295 | FILE *f; | |
2296 | const char *ptr; | |
2297 | { | |
2298 | int c; | |
2299 | ||
2300 | if (! PACKING_FLAG_USED_P()) | |
2301 | return ptr; | |
2302 | ||
2303 | for (; *ptr && *ptr != ' ' && *ptr != '\t';) | |
2304 | { | |
2305 | c = *ptr++; | |
2306 | if (c == '%' && ((*ptr >= 'a' && *ptr <= 'z') | |
2307 | || (*ptr >= 'A' && *ptr <= 'Z'))) | |
2308 | { | |
2309 | int letter = *ptr++; | |
2310 | ||
2311 | c = atoi (ptr); | |
2312 | frv_print_operand (f, frv_insn_operands [c], letter); | |
2313 | while ((c = *ptr) >= '0' && c <= '9') | |
2314 | ptr++; | |
2315 | } | |
2316 | else | |
2317 | fputc (c, f); | |
2318 | } | |
2319 | ||
2320 | if (!frv_insn_packing_flag) | |
2321 | fprintf (f, ".p"); | |
2322 | ||
2323 | return ptr; | |
2324 | } | |
2325 | ||
2326 | /* The following function sets up the packing bit for the current | |
2327 | output insn. Remember that the function is not called for asm | |
2328 | insns. */ | |
2329 | ||
2330 | void | |
2331 | frv_final_prescan_insn (insn, opvec, noperands) | |
2332 | rtx insn; | |
2333 | rtx *opvec; | |
2334 | int noperands ATTRIBUTE_UNUSED; | |
2335 | { | |
2336 | if (! PACKING_FLAG_USED_P()) | |
2337 | return; | |
2338 | ||
735e8085 | 2339 | if (!INSN_P (insn)) |
36a05131 BS |
2340 | return; |
2341 | ||
2342 | frv_insn_operands = opvec; | |
2343 | ||
2344 | /* Look for the next printable instruction. frv_pack_insns () has set | |
2345 | things up so that any printable instruction will have TImode if it | |
2346 | starts a new packet and VOIDmode if it should be packed with the | |
2347 | previous instruction. | |
2348 | ||
2349 | Printable instructions will be asm_operands or match one of the .md | |
2350 | patterns. Since asm instructions cannot be packed -- and will | |
0b4be7de KH |
2351 | therefore have TImode -- this loop terminates on any recognizable |
2352 | instruction, and on any unrecognizable instruction with TImode. */ | |
36a05131 BS |
2353 | for (insn = NEXT_INSN (insn); insn; insn = NEXT_INSN (insn)) |
2354 | { | |
2355 | if (NOTE_P (insn)) | |
2356 | continue; | |
2357 | else if (!INSN_P (insn)) | |
2358 | break; | |
2359 | else if (GET_MODE (insn) == TImode || INSN_CODE (insn) != -1) | |
2360 | break; | |
2361 | } | |
2362 | ||
2363 | /* Set frv_insn_packing_flag to FALSE if the next instruction should | |
2364 | be packed with this one. Set it to TRUE otherwise. If the next | |
2365 | instruction is an asm insntruction, this statement will set the | |
2366 | flag to TRUE, and that value will still hold when the asm operands | |
2367 | themselves are printed. */ | |
2368 | frv_insn_packing_flag = ! (insn && INSN_P (insn) | |
2369 | && GET_MODE (insn) != TImode); | |
2370 | } | |
2371 | ||
2372 | ||
2373 | \f | |
2374 | /* A C expression whose value is RTL representing the address in a stack frame | |
2375 | where the pointer to the caller's frame is stored. Assume that FRAMEADDR is | |
2376 | an RTL expression for the address of the stack frame itself. | |
2377 | ||
2378 | If you don't define this macro, the default is to return the value of | |
2379 | FRAMEADDR--that is, the stack frame address is also the address of the stack | |
2380 | word that points to the previous frame. */ | |
2381 | ||
2382 | /* The default is correct, but we need to make sure the frame gets created. */ | |
2383 | rtx | |
2384 | frv_dynamic_chain_address (frame) | |
2385 | rtx frame; | |
2386 | { | |
2387 | cfun->machine->frame_needed = 1; | |
2388 | return frame; | |
2389 | } | |
2390 | ||
2391 | ||
2392 | /* A C expression whose value is RTL representing the value of the return | |
2393 | address for the frame COUNT steps up from the current frame, after the | |
2394 | prologue. FRAMEADDR is the frame pointer of the COUNT frame, or the frame | |
2395 | pointer of the COUNT - 1 frame if `RETURN_ADDR_IN_PREVIOUS_FRAME' is | |
2396 | defined. | |
2397 | ||
2398 | The value of the expression must always be the correct address when COUNT is | |
2399 | zero, but may be `NULL_RTX' if there is not way to determine the return | |
2400 | address of other frames. */ | |
2401 | ||
2402 | rtx | |
2403 | frv_return_addr_rtx (count, frame) | |
2404 | int count ATTRIBUTE_UNUSED; | |
2405 | rtx frame; | |
2406 | { | |
2407 | cfun->machine->frame_needed = 1; | |
2408 | return gen_rtx_MEM (Pmode, plus_constant (frame, 8)); | |
2409 | } | |
2410 | ||
2411 | /* Given a memory reference MEMREF, interpret the referenced memory as | |
2412 | an array of MODE values, and return a reference to the element | |
2413 | specified by INDEX. Assume that any pre-modification implicit in | |
2414 | MEMREF has already happened. | |
2415 | ||
2416 | MEMREF must be a legitimate operand for modes larger than SImode. | |
2417 | GO_IF_LEGITIMATE_ADDRESS forbids register+register addresses, which | |
2418 | this function cannot handle. */ | |
2419 | rtx | |
2420 | frv_index_memory (memref, mode, index) | |
2421 | rtx memref; | |
2422 | enum machine_mode mode; | |
2423 | int index; | |
2424 | { | |
2425 | rtx base = XEXP (memref, 0); | |
2426 | if (GET_CODE (base) == PRE_MODIFY) | |
2427 | base = XEXP (base, 0); | |
2428 | return change_address (memref, mode, | |
2429 | plus_constant (base, index * GET_MODE_SIZE (mode))); | |
2430 | } | |
2431 | ||
2432 | \f | |
2433 | /* Print a memory address as an operand to reference that memory location. */ | |
2434 | void | |
2435 | frv_print_operand_address (stream, x) | |
2436 | FILE * stream; | |
2437 | rtx x; | |
2438 | { | |
2439 | if (GET_CODE (x) == MEM) | |
2440 | x = XEXP (x, 0); | |
2441 | ||
2442 | switch (GET_CODE (x)) | |
2443 | { | |
2444 | case REG: | |
2445 | fputs (reg_names [ REGNO (x)], stream); | |
2446 | return; | |
2447 | ||
2448 | case CONST_INT: | |
2449 | fprintf (stream, "%ld", (long) INTVAL (x)); | |
2450 | return; | |
2451 | ||
2452 | case SYMBOL_REF: | |
2453 | assemble_name (stream, XSTR (x, 0)); | |
2454 | return; | |
2455 | ||
2456 | case LABEL_REF: | |
2457 | case CONST: | |
2458 | output_addr_const (stream, x); | |
2459 | return; | |
2460 | ||
2461 | default: | |
2462 | break; | |
2463 | } | |
2464 | ||
2465 | fatal_insn ("Bad insn to frv_print_operand_address:", x); | |
2466 | } | |
2467 | ||
2468 | \f | |
2469 | static void | |
2470 | frv_print_operand_memory_reference_reg (stream, x) | |
2471 | FILE *stream; | |
2472 | rtx x; | |
2473 | { | |
2474 | int regno = true_regnum (x); | |
2475 | if (GPR_P (regno)) | |
2476 | fputs (reg_names[regno], stream); | |
2477 | else | |
2478 | fatal_insn ("Bad register to frv_print_operand_memory_reference_reg:", x); | |
2479 | } | |
2480 | ||
2481 | /* Print a memory reference suitable for the ld/st instructions. */ | |
2482 | ||
2483 | static void | |
2484 | frv_print_operand_memory_reference (stream, x, addr_offset) | |
2485 | FILE *stream; | |
2486 | rtx x; | |
2487 | int addr_offset; | |
2488 | { | |
2489 | rtx x0 = NULL_RTX; | |
2490 | rtx x1 = NULL_RTX; | |
2491 | ||
2492 | switch (GET_CODE (x)) | |
2493 | { | |
2494 | case SUBREG: | |
2495 | case REG: | |
2496 | x0 = x; | |
2497 | break; | |
2498 | ||
2499 | case PRE_MODIFY: /* (pre_modify (reg) (plus (reg) (reg))) */ | |
2500 | x0 = XEXP (x, 0); | |
2501 | x1 = XEXP (XEXP (x, 1), 1); | |
2502 | break; | |
2503 | ||
2504 | case CONST_INT: | |
2505 | x1 = x; | |
2506 | break; | |
2507 | ||
2508 | case PLUS: | |
2509 | x0 = XEXP (x, 0); | |
2510 | x1 = XEXP (x, 1); | |
2511 | if (GET_CODE (x0) == CONST_INT) | |
2512 | { | |
2513 | x0 = XEXP (x, 1); | |
2514 | x1 = XEXP (x, 0); | |
2515 | } | |
2516 | break; | |
2517 | ||
2518 | default: | |
2519 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2520 | break; | |
2521 | ||
2522 | } | |
2523 | ||
2524 | if (addr_offset) | |
2525 | { | |
2526 | if (!x1) | |
2527 | x1 = const0_rtx; | |
2528 | else if (GET_CODE (x1) != CONST_INT) | |
2529 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2530 | } | |
2531 | ||
2532 | fputs ("@(", stream); | |
2533 | if (!x0) | |
2534 | fputs (reg_names[GPR_R0], stream); | |
2535 | else if (GET_CODE (x0) == REG || GET_CODE (x0) == SUBREG) | |
2536 | frv_print_operand_memory_reference_reg (stream, x0); | |
2537 | else | |
2538 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2539 | ||
2540 | fputs (",", stream); | |
2541 | if (!x1) | |
2542 | fputs (reg_names [GPR_R0], stream); | |
2543 | ||
2544 | else | |
2545 | { | |
2546 | switch (GET_CODE (x1)) | |
2547 | { | |
2548 | case SUBREG: | |
2549 | case REG: | |
2550 | frv_print_operand_memory_reference_reg (stream, x1); | |
2551 | break; | |
2552 | ||
2553 | case CONST_INT: | |
2554 | fprintf (stream, "%ld", (long) (INTVAL (x1) + addr_offset)); | |
2555 | break; | |
2556 | ||
2557 | case SYMBOL_REF: | |
2558 | if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG | |
0f6e5d45 | 2559 | && SYMBOL_REF_SMALL_P (x1)) |
36a05131 BS |
2560 | { |
2561 | fputs ("#gprel12(", stream); | |
2562 | assemble_name (stream, XSTR (x1, 0)); | |
2563 | fputs (")", stream); | |
2564 | } | |
2565 | else | |
2566 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2567 | break; | |
2568 | ||
2569 | case CONST: | |
2570 | if (x0 && GET_CODE (x0) == REG && REGNO (x0) == SDA_BASE_REG | |
2571 | && const_small_data_p (x1)) | |
2572 | { | |
2573 | fputs ("#gprel12(", stream); | |
2574 | assemble_name (stream, XSTR (XEXP (XEXP (x1, 0), 0), 0)); | |
6f562bc6 KG |
2575 | fprintf (stream, "+"HOST_WIDE_INT_PRINT_DEC")", |
2576 | INTVAL (XEXP (XEXP (x1, 0), 1))); | |
36a05131 BS |
2577 | } |
2578 | else | |
2579 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2580 | break; | |
2581 | ||
2582 | default: | |
2583 | fatal_insn ("Bad insn to frv_print_operand_memory_reference:", x); | |
2584 | } | |
2585 | } | |
2586 | ||
2587 | fputs (")", stream); | |
2588 | } | |
2589 | ||
2590 | \f | |
2591 | /* Return 2 for likely branches and 0 for non-likely branches */ | |
2592 | ||
2593 | #define FRV_JUMP_LIKELY 2 | |
2594 | #define FRV_JUMP_NOT_LIKELY 0 | |
2595 | ||
2596 | static int | |
2597 | frv_print_operand_jump_hint (insn) | |
2598 | rtx insn; | |
2599 | { | |
2600 | rtx note; | |
2601 | rtx labelref; | |
2602 | int ret; | |
2603 | HOST_WIDE_INT prob = -1; | |
2604 | enum { UNKNOWN, BACKWARD, FORWARD } jump_type = UNKNOWN; | |
2605 | ||
2606 | if (GET_CODE (insn) != JUMP_INSN) | |
2607 | abort (); | |
2608 | ||
2609 | /* Assume any non-conditional jump is likely. */ | |
2610 | if (! any_condjump_p (insn)) | |
2611 | ret = FRV_JUMP_LIKELY; | |
2612 | ||
2613 | else | |
2614 | { | |
2615 | labelref = condjump_label (insn); | |
2616 | if (labelref) | |
2617 | { | |
2618 | rtx label = XEXP (labelref, 0); | |
2619 | jump_type = (insn_current_address > INSN_ADDRESSES (INSN_UID (label)) | |
2620 | ? BACKWARD | |
2621 | : FORWARD); | |
2622 | } | |
2623 | ||
2624 | note = find_reg_note (insn, REG_BR_PROB, 0); | |
2625 | if (!note) | |
2626 | ret = ((jump_type == BACKWARD) ? FRV_JUMP_LIKELY : FRV_JUMP_NOT_LIKELY); | |
2627 | ||
2628 | else | |
2629 | { | |
2630 | prob = INTVAL (XEXP (note, 0)); | |
2631 | ret = ((prob >= (REG_BR_PROB_BASE / 2)) | |
2632 | ? FRV_JUMP_LIKELY | |
2633 | : FRV_JUMP_NOT_LIKELY); | |
2634 | } | |
2635 | } | |
2636 | ||
2637 | #if 0 | |
2638 | if (TARGET_DEBUG) | |
2639 | { | |
2640 | char *direction; | |
2641 | ||
2642 | switch (jump_type) | |
2643 | { | |
2644 | default: | |
2645 | case UNKNOWN: direction = "unknown jump direction"; break; | |
2646 | case BACKWARD: direction = "jump backward"; break; | |
2647 | case FORWARD: direction = "jump forward"; break; | |
2648 | } | |
2649 | ||
2650 | fprintf (stderr, | |
2651 | "%s: uid %ld, %s, probability = %ld, max prob. = %ld, hint = %d\n", | |
2652 | IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), | |
2653 | (long)INSN_UID (insn), direction, (long)prob, | |
2654 | (long)REG_BR_PROB_BASE, ret); | |
2655 | } | |
2656 | #endif | |
2657 | ||
2658 | return ret; | |
2659 | } | |
2660 | ||
2661 | \f | |
43aa4e05 | 2662 | /* Print an operand to an assembler instruction. |
36a05131 BS |
2663 | |
2664 | `%' followed by a letter and a digit says to output an operand in an | |
2665 | alternate fashion. Four letters have standard, built-in meanings described | |
2666 | below. The machine description macro `PRINT_OPERAND' can define additional | |
2667 | letters with nonstandard meanings. | |
2668 | ||
2669 | `%cDIGIT' can be used to substitute an operand that is a constant value | |
2670 | without the syntax that normally indicates an immediate operand. | |
2671 | ||
2672 | `%nDIGIT' is like `%cDIGIT' except that the value of the constant is negated | |
2673 | before printing. | |
2674 | ||
2675 | `%aDIGIT' can be used to substitute an operand as if it were a memory | |
2676 | reference, with the actual operand treated as the address. This may be | |
2677 | useful when outputting a "load address" instruction, because often the | |
2678 | assembler syntax for such an instruction requires you to write the operand | |
2679 | as if it were a memory reference. | |
2680 | ||
2681 | `%lDIGIT' is used to substitute a `label_ref' into a jump instruction. | |
2682 | ||
2683 | `%=' outputs a number which is unique to each instruction in the entire | |
2684 | compilation. This is useful for making local labels to be referred to more | |
2685 | than once in a single template that generates multiple assembler | |
2686 | instructions. | |
2687 | ||
2688 | `%' followed by a punctuation character specifies a substitution that does | |
2689 | not use an operand. Only one case is standard: `%%' outputs a `%' into the | |
2690 | assembler code. Other nonstandard cases can be defined in the | |
2691 | `PRINT_OPERAND' macro. You must also define which punctuation characters | |
2692 | are valid with the `PRINT_OPERAND_PUNCT_VALID_P' macro. */ | |
2693 | ||
2694 | void | |
2695 | frv_print_operand (file, x, code) | |
2696 | FILE * file; | |
2697 | rtx x; | |
2698 | int code; | |
2699 | { | |
2700 | HOST_WIDE_INT value; | |
2701 | int offset; | |
2702 | ||
2703 | if (code != 0 && !isalpha (code)) | |
2704 | value = 0; | |
2705 | ||
2706 | else if (GET_CODE (x) == CONST_INT) | |
2707 | value = INTVAL (x); | |
2708 | ||
2709 | else if (GET_CODE (x) == CONST_DOUBLE) | |
2710 | { | |
2711 | if (GET_MODE (x) == SFmode) | |
2712 | { | |
2713 | REAL_VALUE_TYPE rv; | |
2714 | long l; | |
2715 | ||
2716 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
2717 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
2718 | value = l; | |
2719 | } | |
2720 | ||
2721 | else if (GET_MODE (x) == VOIDmode) | |
2722 | value = CONST_DOUBLE_LOW (x); | |
2723 | ||
2724 | else | |
2725 | fatal_insn ("Bad insn in frv_print_operand, bad const_double", x); | |
2726 | } | |
2727 | ||
2728 | else | |
2729 | value = 0; | |
2730 | ||
2731 | switch (code) | |
2732 | { | |
2733 | ||
2734 | case '.': | |
2735 | /* Output r0 */ | |
2736 | fputs (reg_names[GPR_R0], file); | |
2737 | break; | |
2738 | ||
2739 | case '#': | |
2740 | fprintf (file, "%d", frv_print_operand_jump_hint (current_output_insn)); | |
2741 | break; | |
2742 | ||
0f6e5d45 | 2743 | case '@': |
36a05131 BS |
2744 | /* Output small data area base register (gr16). */ |
2745 | fputs (reg_names[SDA_BASE_REG], file); | |
2746 | break; | |
2747 | ||
2748 | case '~': | |
2749 | /* Output pic register (gr17). */ | |
2750 | fputs (reg_names[PIC_REGNO], file); | |
2751 | break; | |
2752 | ||
2753 | case '*': | |
2754 | /* Output the temporary integer CCR register */ | |
2755 | fputs (reg_names[ICR_TEMP], file); | |
2756 | break; | |
2757 | ||
2758 | case '&': | |
2759 | /* Output the temporary integer CC register */ | |
2760 | fputs (reg_names[ICC_TEMP], file); | |
2761 | break; | |
2762 | ||
2763 | /* case 'a': print an address */ | |
2764 | ||
2765 | case 'C': | |
2766 | /* Print appropriate test for integer branch false operation */ | |
2767 | switch (GET_CODE (x)) | |
2768 | { | |
2769 | default: | |
2770 | fatal_insn ("Bad insn to frv_print_operand, 'C' modifier:", x); | |
2771 | ||
2772 | case EQ: fputs ("ne", file); break; | |
2773 | case NE: fputs ("eq", file); break; | |
2774 | case LT: fputs ("ge", file); break; | |
2775 | case LE: fputs ("gt", file); break; | |
2776 | case GT: fputs ("le", file); break; | |
2777 | case GE: fputs ("lt", file); break; | |
2778 | case LTU: fputs ("nc", file); break; | |
2779 | case LEU: fputs ("hi", file); break; | |
2780 | case GTU: fputs ("ls", file); break; | |
2781 | case GEU: fputs ("c", file); break; | |
2782 | } | |
2783 | break; | |
2784 | ||
2785 | /* case 'c': print a constant without the constant prefix. If | |
2786 | CONSTANT_ADDRESS_P(x) is not true, PRINT_OPERAND is called. */ | |
2787 | ||
2788 | case 'c': | |
2789 | /* Print appropriate test for integer branch true operation */ | |
2790 | switch (GET_CODE (x)) | |
2791 | { | |
2792 | default: | |
2793 | fatal_insn ("Bad insn to frv_print_operand, 'c' modifier:", x); | |
2794 | ||
2795 | case EQ: fputs ("eq", file); break; | |
2796 | case NE: fputs ("ne", file); break; | |
2797 | case LT: fputs ("lt", file); break; | |
2798 | case LE: fputs ("le", file); break; | |
2799 | case GT: fputs ("gt", file); break; | |
2800 | case GE: fputs ("ge", file); break; | |
2801 | case LTU: fputs ("c", file); break; | |
2802 | case LEU: fputs ("ls", file); break; | |
2803 | case GTU: fputs ("hi", file); break; | |
2804 | case GEU: fputs ("nc", file); break; | |
2805 | } | |
2806 | break; | |
2807 | ||
2808 | case 'e': | |
2809 | /* Print 1 for a NE and 0 for an EQ to give the final argument | |
2810 | for a conditional instruction. */ | |
2811 | if (GET_CODE (x) == NE) | |
2812 | fputs ("1", file); | |
2813 | ||
2814 | else if (GET_CODE (x) == EQ) | |
2815 | fputs ("0", file); | |
2816 | ||
2817 | else | |
2818 | fatal_insn ("Bad insn to frv_print_operand, 'e' modifier:", x); | |
2819 | break; | |
2820 | ||
2821 | case 'F': | |
2822 | /* Print appropriate test for floating point branch false operation */ | |
2823 | switch (GET_CODE (x)) | |
2824 | { | |
2825 | default: | |
2826 | fatal_insn ("Bad insn to frv_print_operand, 'F' modifier:", x); | |
2827 | ||
2828 | case EQ: fputs ("ne", file); break; | |
2829 | case NE: fputs ("eq", file); break; | |
2830 | case LT: fputs ("uge", file); break; | |
2831 | case LE: fputs ("ug", file); break; | |
2832 | case GT: fputs ("ule", file); break; | |
2833 | case GE: fputs ("ul", file); break; | |
2834 | } | |
2835 | break; | |
2836 | ||
2837 | case 'f': | |
2838 | /* Print appropriate test for floating point branch true operation */ | |
2839 | switch (GET_CODE (x)) | |
2840 | { | |
2841 | default: | |
2842 | fatal_insn ("Bad insn to frv_print_operand, 'f' modifier:", x); | |
2843 | ||
2844 | case EQ: fputs ("eq", file); break; | |
2845 | case NE: fputs ("ne", file); break; | |
2846 | case LT: fputs ("lt", file); break; | |
2847 | case LE: fputs ("le", file); break; | |
2848 | case GT: fputs ("gt", file); break; | |
2849 | case GE: fputs ("ge", file); break; | |
2850 | } | |
2851 | break; | |
2852 | ||
2853 | case 'I': | |
2854 | /* Print 'i' if the operand is a constant, or is a memory reference that | |
2855 | adds a constant */ | |
2856 | if (GET_CODE (x) == MEM) | |
2857 | x = ((GET_CODE (XEXP (x, 0)) == PLUS) | |
2858 | ? XEXP (XEXP (x, 0), 1) | |
2859 | : XEXP (x, 0)); | |
2860 | ||
2861 | switch (GET_CODE (x)) | |
2862 | { | |
2863 | default: | |
2864 | break; | |
2865 | ||
2866 | case CONST_INT: | |
2867 | case SYMBOL_REF: | |
2868 | case CONST: | |
2869 | fputs ("i", file); | |
2870 | break; | |
2871 | } | |
2872 | break; | |
2873 | ||
2874 | case 'i': | |
2875 | /* For jump instructions, print 'i' if the operand is a constant or | |
2876 | is an expression that adds a constant */ | |
2877 | if (GET_CODE (x) == CONST_INT) | |
2878 | fputs ("i", file); | |
2879 | ||
2880 | else | |
2881 | { | |
2882 | if (GET_CODE (x) == CONST_INT | |
2883 | || (GET_CODE (x) == PLUS | |
2884 | && (GET_CODE (XEXP (x, 1)) == CONST_INT | |
2885 | || GET_CODE (XEXP (x, 0)) == CONST_INT))) | |
2886 | fputs ("i", file); | |
2887 | } | |
2888 | break; | |
2889 | ||
2890 | case 'L': | |
2891 | /* Print the lower register of a double word register pair */ | |
2892 | if (GET_CODE (x) == REG) | |
2893 | fputs (reg_names[ REGNO (x)+1 ], file); | |
2894 | else | |
2895 | fatal_insn ("Bad insn to frv_print_operand, 'L' modifier:", x); | |
2896 | break; | |
2897 | ||
2898 | /* case 'l': print a LABEL_REF */ | |
2899 | ||
2900 | case 'M': | |
2901 | case 'N': | |
2902 | /* Print a memory reference for ld/st/jmp, %N prints a memory reference | |
2903 | for the second word of double memory operations. */ | |
2904 | offset = (code == 'M') ? 0 : UNITS_PER_WORD; | |
2905 | switch (GET_CODE (x)) | |
2906 | { | |
2907 | default: | |
2908 | fatal_insn ("Bad insn to frv_print_operand, 'M/N' modifier:", x); | |
2909 | ||
2910 | case MEM: | |
2911 | frv_print_operand_memory_reference (file, XEXP (x, 0), offset); | |
2912 | break; | |
2913 | ||
2914 | case REG: | |
2915 | case SUBREG: | |
2916 | case CONST_INT: | |
2917 | case PLUS: | |
2918 | case SYMBOL_REF: | |
2919 | frv_print_operand_memory_reference (file, x, offset); | |
2920 | break; | |
2921 | } | |
2922 | break; | |
2923 | ||
2924 | case 'O': | |
2925 | /* Print the opcode of a command. */ | |
2926 | switch (GET_CODE (x)) | |
2927 | { | |
2928 | default: | |
2929 | fatal_insn ("Bad insn to frv_print_operand, 'O' modifier:", x); | |
2930 | ||
2931 | case PLUS: fputs ("add", file); break; | |
2932 | case MINUS: fputs ("sub", file); break; | |
2933 | case AND: fputs ("and", file); break; | |
2934 | case IOR: fputs ("or", file); break; | |
2935 | case XOR: fputs ("xor", file); break; | |
2936 | case ASHIFT: fputs ("sll", file); break; | |
2937 | case ASHIFTRT: fputs ("sra", file); break; | |
2938 | case LSHIFTRT: fputs ("srl", file); break; | |
2939 | } | |
2940 | break; | |
2941 | ||
2942 | /* case 'n': negate and print a constant int */ | |
2943 | ||
2944 | case 'P': | |
2945 | /* Print PIC label using operand as the number. */ | |
2946 | if (GET_CODE (x) != CONST_INT) | |
2947 | fatal_insn ("Bad insn to frv_print_operand, P modifier:", x); | |
2948 | ||
2949 | fprintf (file, ".LCF%ld", (long)INTVAL (x)); | |
2950 | break; | |
2951 | ||
2952 | case 'U': | |
2953 | /* Print 'u' if the operand is a update load/store */ | |
2954 | if (GET_CODE (x) == MEM && GET_CODE (XEXP (x, 0)) == PRE_MODIFY) | |
2955 | fputs ("u", file); | |
2956 | break; | |
2957 | ||
2958 | case 'z': | |
2959 | /* If value is 0, print gr0, otherwise it must be a register */ | |
2960 | if (GET_CODE (x) == CONST_INT && INTVAL (x) == 0) | |
2961 | fputs (reg_names[GPR_R0], file); | |
2962 | ||
2963 | else if (GET_CODE (x) == REG) | |
2964 | fputs (reg_names [REGNO (x)], file); | |
2965 | ||
2966 | else | |
2967 | fatal_insn ("Bad insn in frv_print_operand, z case", x); | |
2968 | break; | |
2969 | ||
2970 | case 'x': | |
2971 | /* Print constant in hex */ | |
2972 | if (GET_CODE (x) == CONST_INT || GET_CODE (x) == CONST_DOUBLE) | |
2973 | { | |
2974 | fprintf (file, "%s0x%.4lx", IMMEDIATE_PREFIX, (long) value); | |
2975 | break; | |
2976 | } | |
2977 | ||
2978 | /* fall through */ | |
2979 | ||
2980 | case '\0': | |
2981 | if (GET_CODE (x) == REG) | |
2982 | fputs (reg_names [REGNO (x)], file); | |
2983 | ||
2984 | else if (GET_CODE (x) == CONST_INT | |
2985 | || GET_CODE (x) == CONST_DOUBLE) | |
2986 | fprintf (file, "%s%ld", IMMEDIATE_PREFIX, (long) value); | |
2987 | ||
2988 | else if (GET_CODE (x) == MEM) | |
2989 | frv_print_operand_address (file, XEXP (x, 0)); | |
2990 | ||
2991 | else if (CONSTANT_ADDRESS_P (x)) | |
2992 | frv_print_operand_address (file, x); | |
2993 | ||
2994 | else | |
2995 | fatal_insn ("Bad insn in frv_print_operand, 0 case", x); | |
2996 | ||
2997 | break; | |
2998 | ||
2999 | default: | |
3000 | fatal_insn ("frv_print_operand: unknown code", x); | |
3001 | break; | |
3002 | } | |
3003 | ||
3004 | return; | |
3005 | } | |
3006 | ||
3007 | \f | |
3008 | /* A C statement (sans semicolon) for initializing the variable CUM for the | |
3009 | state at the beginning of the argument list. The variable has type | |
3010 | `CUMULATIVE_ARGS'. The value of FNTYPE is the tree node for the data type | |
3011 | of the function which will receive the args, or 0 if the args are to a | |
3012 | compiler support library function. The value of INDIRECT is nonzero when | |
3013 | processing an indirect call, for example a call through a function pointer. | |
3014 | The value of INDIRECT is zero for a call to an explicitly named function, a | |
3015 | library function call, or when `INIT_CUMULATIVE_ARGS' is used to find | |
3016 | arguments for the function being compiled. | |
3017 | ||
3018 | When processing a call to a compiler support library function, LIBNAME | |
3019 | identifies which one. It is a `symbol_ref' rtx which contains the name of | |
3020 | the function, as a string. LIBNAME is 0 when an ordinary C function call is | |
3021 | being processed. Thus, each time this macro is called, either LIBNAME or | |
3022 | FNTYPE is nonzero, but never both of them at once. */ | |
3023 | ||
3024 | void | |
563a317a | 3025 | frv_init_cumulative_args (cum, fntype, libname, fndecl, incoming) |
36a05131 BS |
3026 | CUMULATIVE_ARGS *cum; |
3027 | tree fntype; | |
3028 | rtx libname; | |
563a317a | 3029 | tree fndecl; |
36a05131 BS |
3030 | int incoming; |
3031 | { | |
3032 | *cum = FIRST_ARG_REGNUM; | |
3033 | ||
3034 | if (TARGET_DEBUG_ARG) | |
3035 | { | |
3036 | fprintf (stderr, "\ninit_cumulative_args:"); | |
563a317a | 3037 | if (!fndecl && fntype) |
36a05131 BS |
3038 | fputs (" indirect", stderr); |
3039 | ||
3040 | if (incoming) | |
3041 | fputs (" incoming", stderr); | |
3042 | ||
3043 | if (fntype) | |
3044 | { | |
3045 | tree ret_type = TREE_TYPE (fntype); | |
3046 | fprintf (stderr, " return=%s,", | |
3047 | tree_code_name[ (int)TREE_CODE (ret_type) ]); | |
3048 | } | |
3049 | ||
3050 | if (libname && GET_CODE (libname) == SYMBOL_REF) | |
3051 | fprintf (stderr, " libname=%s", XSTR (libname, 0)); | |
3052 | ||
3053 | if (cfun->returns_struct) | |
3054 | fprintf (stderr, " return-struct"); | |
3055 | ||
3056 | putc ('\n', stderr); | |
3057 | } | |
3058 | } | |
3059 | ||
3060 | \f | |
3061 | /* If defined, a C expression that gives the alignment boundary, in bits, of an | |
3062 | argument with the specified mode and type. If it is not defined, | |
3063 | `PARM_BOUNDARY' is used for all arguments. */ | |
3064 | ||
3065 | int | |
3066 | frv_function_arg_boundary (mode, type) | |
3067 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3068 | tree type ATTRIBUTE_UNUSED; | |
3069 | { | |
3070 | return BITS_PER_WORD; | |
3071 | } | |
3072 | ||
3073 | \f | |
3074 | /* A C expression that controls whether a function argument is passed in a | |
3075 | register, and which register. | |
3076 | ||
3077 | The arguments are CUM, of type CUMULATIVE_ARGS, which summarizes (in a way | |
3078 | defined by INIT_CUMULATIVE_ARGS and FUNCTION_ARG_ADVANCE) all of the previous | |
3079 | arguments so far passed in registers; MODE, the machine mode of the argument; | |
3080 | TYPE, the data type of the argument as a tree node or 0 if that is not known | |
3081 | (which happens for C support library functions); and NAMED, which is 1 for an | |
3082 | ordinary argument and 0 for nameless arguments that correspond to `...' in the | |
3083 | called function's prototype. | |
3084 | ||
3085 | The value of the expression should either be a `reg' RTX for the hard | |
3086 | register in which to pass the argument, or zero to pass the argument on the | |
3087 | stack. | |
3088 | ||
4912a07c | 3089 | For machines like the VAX and 68000, where normally all arguments are |
36a05131 BS |
3090 | pushed, zero suffices as a definition. |
3091 | ||
3092 | The usual way to make the ANSI library `stdarg.h' work on a machine where | |
3093 | some arguments are usually passed in registers, is to cause nameless | |
3094 | arguments to be passed on the stack instead. This is done by making | |
3095 | `FUNCTION_ARG' return 0 whenever NAMED is 0. | |
3096 | ||
3097 | You may use the macro `MUST_PASS_IN_STACK (MODE, TYPE)' in the definition of | |
3098 | this macro to determine if this argument is of a type that must be passed in | |
3099 | the stack. If `REG_PARM_STACK_SPACE' is not defined and `FUNCTION_ARG' | |
9cd10576 | 3100 | returns nonzero for such an argument, the compiler will abort. If |
36a05131 BS |
3101 | `REG_PARM_STACK_SPACE' is defined, the argument will be computed in the |
3102 | stack and then loaded into a register. */ | |
3103 | ||
3104 | rtx | |
3105 | frv_function_arg (cum, mode, type, named, incoming) | |
3106 | CUMULATIVE_ARGS *cum; | |
3107 | enum machine_mode mode; | |
3108 | tree type ATTRIBUTE_UNUSED; | |
3109 | int named; | |
3110 | int incoming ATTRIBUTE_UNUSED; | |
3111 | { | |
3112 | enum machine_mode xmode = (mode == BLKmode) ? SImode : mode; | |
3113 | int arg_num = *cum; | |
3114 | rtx ret; | |
3115 | const char *debstr; | |
3116 | ||
3117 | /* Return a marker for use in the call instruction. */ | |
3118 | if (xmode == VOIDmode) | |
3119 | { | |
3120 | ret = const0_rtx; | |
3121 | debstr = "<0>"; | |
3122 | } | |
3123 | ||
3124 | else if (arg_num <= LAST_ARG_REGNUM) | |
3125 | { | |
3126 | ret = gen_rtx (REG, xmode, arg_num); | |
3127 | debstr = reg_names[arg_num]; | |
3128 | } | |
3129 | ||
3130 | else | |
3131 | { | |
3132 | ret = NULL_RTX; | |
3133 | debstr = "memory"; | |
3134 | } | |
3135 | ||
3136 | if (TARGET_DEBUG_ARG) | |
3137 | fprintf (stderr, | |
3138 | "function_arg: words = %2d, mode = %4s, named = %d, size = %3d, arg = %s\n", | |
3139 | arg_num, GET_MODE_NAME (mode), named, GET_MODE_SIZE (mode), debstr); | |
3140 | ||
3141 | return ret; | |
3142 | } | |
3143 | ||
3144 | \f | |
3145 | /* A C statement (sans semicolon) to update the summarizer variable CUM to | |
3146 | advance past an argument in the argument list. The values MODE, TYPE and | |
3147 | NAMED describe that argument. Once this is done, the variable CUM is | |
3148 | suitable for analyzing the *following* argument with `FUNCTION_ARG', etc. | |
3149 | ||
3150 | This macro need not do anything if the argument in question was passed on | |
3151 | the stack. The compiler knows how to track the amount of stack space used | |
3152 | for arguments without any special help. */ | |
3153 | ||
3154 | void | |
3155 | frv_function_arg_advance (cum, mode, type, named) | |
3156 | CUMULATIVE_ARGS *cum; | |
3157 | enum machine_mode mode; | |
3158 | tree type ATTRIBUTE_UNUSED; | |
3159 | int named; | |
3160 | { | |
3161 | enum machine_mode xmode = (mode == BLKmode) ? SImode : mode; | |
3162 | int bytes = GET_MODE_SIZE (xmode); | |
3163 | int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
3164 | int arg_num = *cum; | |
3165 | ||
3166 | *cum = arg_num + words; | |
3167 | ||
3168 | if (TARGET_DEBUG_ARG) | |
3169 | fprintf (stderr, | |
3170 | "function_adv: words = %2d, mode = %4s, named = %d, size = %3d\n", | |
3171 | arg_num, GET_MODE_NAME (mode), named, words * UNITS_PER_WORD); | |
3172 | } | |
3173 | ||
3174 | \f | |
3175 | /* A C expression for the number of words, at the beginning of an argument, | |
3176 | must be put in registers. The value must be zero for arguments that are | |
3177 | passed entirely in registers or that are entirely pushed on the stack. | |
3178 | ||
3179 | On some machines, certain arguments must be passed partially in registers | |
3180 | and partially in memory. On these machines, typically the first N words of | |
3181 | arguments are passed in registers, and the rest on the stack. If a | |
3182 | multi-word argument (a `double' or a structure) crosses that boundary, its | |
3183 | first few words must be passed in registers and the rest must be pushed. | |
3184 | This macro tells the compiler when this occurs, and how many of the words | |
3185 | should go in registers. | |
3186 | ||
3187 | `FUNCTION_ARG' for these arguments should return the first register to be | |
3188 | used by the caller for this argument; likewise `FUNCTION_INCOMING_ARG', for | |
3189 | the called function. */ | |
3190 | ||
3191 | int | |
3192 | frv_function_arg_partial_nregs (cum, mode, type, named) | |
3193 | CUMULATIVE_ARGS *cum; | |
3194 | enum machine_mode mode; | |
3195 | tree type ATTRIBUTE_UNUSED; | |
3196 | int named ATTRIBUTE_UNUSED; | |
3197 | { | |
3198 | enum machine_mode xmode = (mode == BLKmode) ? SImode : mode; | |
3199 | int bytes = GET_MODE_SIZE (xmode); | |
3200 | int words = (bytes + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
3201 | int arg_num = *cum; | |
3202 | int ret; | |
3203 | ||
3204 | ret = ((arg_num <= LAST_ARG_REGNUM && arg_num + words > LAST_ARG_REGNUM+1) | |
3205 | ? LAST_ARG_REGNUM - arg_num + 1 | |
3206 | : 0); | |
3207 | ||
3208 | if (TARGET_DEBUG_ARG && ret) | |
3209 | fprintf (stderr, "function_arg_partial_nregs: %d\n", ret); | |
3210 | ||
3211 | return ret; | |
3212 | ||
3213 | } | |
3214 | ||
3215 | \f | |
3216 | ||
3217 | /* A C expression that indicates when an argument must be passed by reference. | |
3218 | If nonzero for an argument, a copy of that argument is made in memory and a | |
3219 | pointer to the argument is passed instead of the argument itself. The | |
3220 | pointer is passed in whatever way is appropriate for passing a pointer to | |
3221 | that type. | |
3222 | ||
3223 | On machines where `REG_PARM_STACK_SPACE' is not defined, a suitable | |
3224 | definition of this macro might be | |
3225 | #define FUNCTION_ARG_PASS_BY_REFERENCE(CUM, MODE, TYPE, NAMED) \ | |
3226 | MUST_PASS_IN_STACK (MODE, TYPE) */ | |
3227 | ||
3228 | int | |
3229 | frv_function_arg_pass_by_reference (cum, mode, type, named) | |
3230 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; | |
3231 | enum machine_mode mode; | |
3232 | tree type; | |
3233 | int named ATTRIBUTE_UNUSED; | |
3234 | { | |
3235 | return MUST_PASS_IN_STACK (mode, type); | |
3236 | } | |
3237 | ||
3238 | /* If defined, a C expression that indicates when it is the called function's | |
3239 | responsibility to make a copy of arguments passed by invisible reference. | |
3240 | Normally, the caller makes a copy and passes the address of the copy to the | |
3241 | routine being called. When FUNCTION_ARG_CALLEE_COPIES is defined and is | |
3242 | nonzero, the caller does not make a copy. Instead, it passes a pointer to | |
3243 | the "live" value. The called function must not modify this value. If it | |
3244 | can be determined that the value won't be modified, it need not make a copy; | |
3245 | otherwise a copy must be made. */ | |
3246 | ||
3247 | int | |
3248 | frv_function_arg_callee_copies (cum, mode, type, named) | |
3249 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; | |
3250 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3251 | tree type ATTRIBUTE_UNUSED; | |
3252 | int named ATTRIBUTE_UNUSED; | |
3253 | { | |
3254 | return 0; | |
3255 | } | |
3256 | ||
3257 | /* If defined, a C expression that indicates when it is more desirable to keep | |
3258 | an argument passed by invisible reference as a reference, rather than | |
3259 | copying it to a pseudo register. */ | |
3260 | ||
3261 | int | |
3262 | frv_function_arg_keep_as_reference (cum, mode, type, named) | |
3263 | CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED; | |
3264 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3265 | tree type ATTRIBUTE_UNUSED; | |
3266 | int named ATTRIBUTE_UNUSED; | |
3267 | { | |
3268 | return 0; | |
3269 | } | |
3270 | ||
3271 | \f | |
3272 | /* Return true if a register is ok to use as a base or index register. */ | |
3273 | ||
3274 | static FRV_INLINE int | |
3275 | frv_regno_ok_for_base_p (regno, strict_p) | |
3276 | int regno; | |
3277 | int strict_p; | |
3278 | { | |
3279 | if (GPR_P (regno)) | |
3280 | return TRUE; | |
3281 | ||
3282 | if (strict_p) | |
3283 | return (reg_renumber[regno] >= 0 && GPR_P (reg_renumber[regno])); | |
3284 | ||
3285 | if (regno == ARG_POINTER_REGNUM) | |
3286 | return TRUE; | |
3287 | ||
3288 | return (regno >= FIRST_PSEUDO_REGISTER); | |
3289 | } | |
3290 | ||
3291 | \f | |
3292 | /* A C compound statement with a conditional `goto LABEL;' executed if X (an | |
3293 | RTX) is a legitimate memory address on the target machine for a memory | |
3294 | operand of mode MODE. | |
3295 | ||
3296 | It usually pays to define several simpler macros to serve as subroutines for | |
3297 | this one. Otherwise it may be too complicated to understand. | |
3298 | ||
3299 | This macro must exist in two variants: a strict variant and a non-strict | |
3300 | one. The strict variant is used in the reload pass. It must be defined so | |
3301 | that any pseudo-register that has not been allocated a hard register is | |
3302 | considered a memory reference. In contexts where some kind of register is | |
3303 | required, a pseudo-register with no hard register must be rejected. | |
3304 | ||
3305 | The non-strict variant is used in other passes. It must be defined to | |
3306 | accept all pseudo-registers in every context where some kind of register is | |
3307 | required. | |
3308 | ||
3309 | Compiler source files that want to use the strict variant of this macro | |
3310 | define the macro `REG_OK_STRICT'. You should use an `#ifdef REG_OK_STRICT' | |
3311 | conditional to define the strict variant in that case and the non-strict | |
3312 | variant otherwise. | |
3313 | ||
3314 | Subroutines to check for acceptable registers for various purposes (one for | |
3315 | base registers, one for index registers, and so on) are typically among the | |
3316 | subroutines used to define `GO_IF_LEGITIMATE_ADDRESS'. Then only these | |
3317 | subroutine macros need have two variants; the higher levels of macros may be | |
3318 | the same whether strict or not. | |
3319 | ||
3320 | Normally, constant addresses which are the sum of a `symbol_ref' and an | |
3321 | integer are stored inside a `const' RTX to mark them as constant. | |
3322 | Therefore, there is no need to recognize such sums specifically as | |
3323 | legitimate addresses. Normally you would simply recognize any `const' as | |
3324 | legitimate. | |
3325 | ||
3326 | Usually `PRINT_OPERAND_ADDRESS' is not prepared to handle constant sums that | |
3327 | are not marked with `const'. It assumes that a naked `plus' indicates | |
3328 | indexing. If so, then you *must* reject such naked constant sums as | |
3329 | illegitimate addresses, so that none of them will be given to | |
3330 | `PRINT_OPERAND_ADDRESS'. | |
3331 | ||
3332 | On some machines, whether a symbolic address is legitimate depends on the | |
3333 | section that the address refers to. On these machines, define the macro | |
3334 | `ENCODE_SECTION_INFO' to store the information into the `symbol_ref', and | |
3335 | then check for it here. When you see a `const', you will have to look | |
3336 | inside it to find the `symbol_ref' in order to determine the section. | |
3337 | ||
3338 | The best way to modify the name string is by adding text to the beginning, | |
3339 | with suitable punctuation to prevent any ambiguity. Allocate the new name | |
3340 | in `saveable_obstack'. You will have to modify `ASM_OUTPUT_LABELREF' to | |
3341 | remove and decode the added text and output the name accordingly, and define | |
14966b94 | 3342 | `(* targetm.strip_name_encoding)' to access the original name string. |
36a05131 BS |
3343 | |
3344 | You can check the information stored here into the `symbol_ref' in the | |
3345 | definitions of the macros `GO_IF_LEGITIMATE_ADDRESS' and | |
3346 | `PRINT_OPERAND_ADDRESS'. */ | |
3347 | ||
3348 | int | |
3349 | frv_legitimate_address_p (mode, x, strict_p, condexec_p) | |
3350 | enum machine_mode mode; | |
3351 | rtx x; | |
3352 | int strict_p; | |
3353 | int condexec_p; | |
3354 | { | |
3355 | rtx x0, x1; | |
3356 | int ret = 0; | |
3357 | HOST_WIDE_INT value; | |
3358 | unsigned regno0; | |
3359 | ||
3360 | switch (GET_CODE (x)) | |
3361 | { | |
3362 | default: | |
3363 | break; | |
3364 | ||
3365 | case SUBREG: | |
3366 | x = SUBREG_REG (x); | |
3367 | if (GET_CODE (x) != REG) | |
3368 | break; | |
3369 | ||
3370 | /* fall through */ | |
3371 | ||
3372 | case REG: | |
3373 | ret = frv_regno_ok_for_base_p (REGNO (x), strict_p); | |
3374 | break; | |
3375 | ||
3376 | case PRE_MODIFY: | |
3377 | x0 = XEXP (x, 0); | |
3378 | x1 = XEXP (x, 1); | |
3379 | if (GET_CODE (x0) != REG | |
3380 | || ! frv_regno_ok_for_base_p (REGNO (x0), strict_p) | |
3381 | || GET_CODE (x1) != PLUS | |
3382 | || ! rtx_equal_p (x0, XEXP (x1, 0)) | |
3383 | || GET_CODE (XEXP (x1, 1)) != REG | |
3384 | || ! frv_regno_ok_for_base_p (REGNO (XEXP (x1, 1)), strict_p)) | |
3385 | break; | |
3386 | ||
3387 | ret = 1; | |
3388 | break; | |
3389 | ||
3390 | case CONST_INT: | |
3391 | /* 12 bit immediate */ | |
3392 | if (condexec_p) | |
3393 | ret = FALSE; | |
3394 | else | |
3395 | { | |
3396 | ret = IN_RANGE_P (INTVAL (x), -2048, 2047); | |
3397 | ||
3398 | /* If we can't use load/store double operations, make sure we can | |
3399 | address the second word. */ | |
3400 | if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
3401 | ret = IN_RANGE_P (INTVAL (x) + GET_MODE_SIZE (mode) - 1, | |
3402 | -2048, 2047); | |
3403 | } | |
3404 | break; | |
3405 | ||
3406 | case PLUS: | |
3407 | x0 = XEXP (x, 0); | |
3408 | x1 = XEXP (x, 1); | |
3409 | ||
3410 | if (GET_CODE (x0) == SUBREG) | |
3411 | x0 = SUBREG_REG (x0); | |
3412 | ||
3413 | if (GET_CODE (x0) != REG) | |
3414 | break; | |
3415 | ||
3416 | regno0 = REGNO (x0); | |
3417 | if (!frv_regno_ok_for_base_p (regno0, strict_p)) | |
3418 | break; | |
3419 | ||
3420 | switch (GET_CODE (x1)) | |
3421 | { | |
3422 | default: | |
3423 | break; | |
3424 | ||
3425 | case SUBREG: | |
3426 | x1 = SUBREG_REG (x1); | |
3427 | if (GET_CODE (x1) != REG) | |
3428 | break; | |
3429 | ||
3430 | /* fall through */ | |
3431 | ||
3432 | case REG: | |
3433 | /* Do not allow reg+reg addressing for modes > 1 word if we can't depend | |
3434 | on having move double instructions */ | |
3435 | if (GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
3436 | ret = FALSE; | |
3437 | else | |
3438 | ret = frv_regno_ok_for_base_p (REGNO (x1), strict_p); | |
3439 | break; | |
3440 | ||
3441 | case CONST_INT: | |
3442 | /* 12 bit immediate */ | |
3443 | if (condexec_p) | |
3444 | ret = FALSE; | |
3445 | else | |
3446 | { | |
3447 | value = INTVAL (x1); | |
3448 | ret = IN_RANGE_P (value, -2048, 2047); | |
3449 | ||
3450 | /* If we can't use load/store double operations, make sure we can | |
3451 | address the second word. */ | |
3452 | if (ret && GET_MODE_SIZE (mode) > UNITS_PER_WORD) | |
3453 | ret = IN_RANGE_P (value + GET_MODE_SIZE (mode) - 1, -2048, 2047); | |
3454 | } | |
3455 | break; | |
3456 | ||
3457 | case SYMBOL_REF: | |
3458 | if (!condexec_p | |
3459 | && regno0 == SDA_BASE_REG | |
0f6e5d45 | 3460 | && SYMBOL_REF_SMALL_P (x1)) |
36a05131 BS |
3461 | ret = TRUE; |
3462 | break; | |
3463 | ||
3464 | case CONST: | |
3465 | if (!condexec_p && regno0 == SDA_BASE_REG && const_small_data_p (x1)) | |
3466 | ret = TRUE; | |
3467 | break; | |
3468 | ||
3469 | } | |
3470 | break; | |
3471 | } | |
3472 | ||
3473 | if (TARGET_DEBUG_ADDR) | |
3474 | { | |
3475 | fprintf (stderr, "\n========== GO_IF_LEGITIMATE_ADDRESS, mode = %s, result = %d, addresses are %sstrict%s\n", | |
3476 | GET_MODE_NAME (mode), ret, (strict_p) ? "" : "not ", | |
3477 | (condexec_p) ? ", inside conditional code" : ""); | |
3478 | debug_rtx (x); | |
3479 | } | |
3480 | ||
3481 | return ret; | |
3482 | } | |
3483 | ||
3484 | \f | |
3485 | /* A C compound statement that attempts to replace X with a valid memory | |
3486 | address for an operand of mode MODE. WIN will be a C statement label | |
3487 | elsewhere in the code; the macro definition may use | |
3488 | ||
3489 | GO_IF_LEGITIMATE_ADDRESS (MODE, X, WIN); | |
3490 | ||
3491 | to avoid further processing if the address has become legitimate. | |
3492 | ||
3493 | X will always be the result of a call to `break_out_memory_refs', and OLDX | |
3494 | will be the operand that was given to that function to produce X. | |
3495 | ||
3496 | The code generated by this macro should not alter the substructure of X. If | |
3497 | it transforms X into a more legitimate form, it should assign X (which will | |
3498 | always be a C variable) a new value. | |
3499 | ||
3500 | It is not necessary for this macro to come up with a legitimate address. | |
3501 | The compiler has standard ways of doing so in all cases. In fact, it is | |
3502 | safe for this macro to do nothing. But often a machine-dependent strategy | |
3503 | can generate better code. */ | |
3504 | ||
3505 | rtx | |
3506 | frv_legitimize_address (x, oldx, mode) | |
3507 | rtx x; | |
3508 | rtx oldx ATTRIBUTE_UNUSED; | |
3509 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3510 | { | |
3511 | rtx ret = NULL_RTX; | |
3512 | ||
a920aefe | 3513 | /* Don't try to legitimize addresses if we are not optimizing, since the |
36a05131 BS |
3514 | address we generate is not a general operand, and will horribly mess |
3515 | things up when force_reg is called to try and put it in a register because | |
3516 | we aren't optimizing. */ | |
3517 | if (optimize | |
0f6e5d45 | 3518 | && ((GET_CODE (x) == SYMBOL_REF && SYMBOL_REF_SMALL_P (x)) |
36a05131 BS |
3519 | || (GET_CODE (x) == CONST && const_small_data_p (x)))) |
3520 | { | |
3521 | ret = gen_rtx_PLUS (Pmode, gen_rtx_REG (Pmode, SDA_BASE_REG), x); | |
3522 | if (flag_pic) | |
3523 | cfun->uses_pic_offset_table = TRUE; | |
3524 | } | |
3525 | ||
3526 | if (TARGET_DEBUG_ADDR && ret != NULL_RTX) | |
3527 | { | |
3528 | fprintf (stderr, "\n========== LEGITIMIZE_ADDRESS, mode = %s, modified address\n", | |
3529 | GET_MODE_NAME (mode)); | |
3530 | debug_rtx (ret); | |
3531 | } | |
3532 | ||
3533 | return ret; | |
3534 | } | |
3535 | ||
3536 | /* Return 1 if operand is a valid FRV address. CONDEXEC_P is true if | |
3537 | the operand is used by a predicated instruction. */ | |
3538 | ||
3539 | static int | |
3540 | frv_legitimate_memory_operand (op, mode, condexec_p) | |
3541 | rtx op; | |
3542 | enum machine_mode mode; | |
3543 | int condexec_p; | |
3544 | { | |
3545 | return ((GET_MODE (op) == mode || mode == VOIDmode) | |
3546 | && GET_CODE (op) == MEM | |
3547 | && frv_legitimate_address_p (mode, XEXP (op, 0), | |
3548 | reload_completed, condexec_p)); | |
3549 | } | |
3550 | ||
3551 | \f | |
3552 | /* Return 1 is OP is a memory operand, or will be turned into one by | |
3553 | reload. */ | |
3554 | ||
3555 | int frv_load_operand (op, mode) | |
3556 | rtx op; | |
3557 | enum machine_mode mode; | |
3558 | { | |
3559 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3560 | return FALSE; | |
3561 | ||
3562 | if (reload_in_progress) | |
3563 | { | |
3564 | rtx tmp = op; | |
3565 | if (GET_CODE (tmp) == SUBREG) | |
3566 | tmp = SUBREG_REG (tmp); | |
3567 | if (GET_CODE (tmp) == REG | |
3568 | && REGNO (tmp) >= FIRST_PSEUDO_REGISTER) | |
3569 | op = reg_equiv_memory_loc[REGNO (tmp)]; | |
3570 | } | |
3571 | ||
3572 | return op && memory_operand (op, mode); | |
3573 | } | |
3574 | ||
3575 | ||
3576 | /* Return 1 if operand is a GPR register or a FPR register. */ | |
3577 | ||
3578 | int gpr_or_fpr_operand (op, mode) | |
3579 | rtx op; | |
3580 | enum machine_mode mode; | |
3581 | { | |
3582 | int regno; | |
3583 | ||
3584 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3585 | return FALSE; | |
3586 | ||
3587 | if (GET_CODE (op) == SUBREG) | |
3588 | { | |
3589 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3590 | return register_operand (op, mode); | |
3591 | ||
3592 | op = SUBREG_REG (op); | |
3593 | } | |
3594 | ||
3595 | if (GET_CODE (op) != REG) | |
3596 | return FALSE; | |
3597 | ||
3598 | regno = REGNO (op); | |
3599 | if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER) | |
3600 | return TRUE; | |
3601 | ||
3602 | return FALSE; | |
3603 | } | |
3604 | ||
3605 | /* Return 1 if operand is a GPR register or 12 bit signed immediate. */ | |
3606 | ||
3607 | int gpr_or_int12_operand (op, mode) | |
3608 | rtx op; | |
3609 | enum machine_mode mode; | |
3610 | { | |
3611 | if (GET_CODE (op) == CONST_INT) | |
3612 | return IN_RANGE_P (INTVAL (op), -2048, 2047); | |
3613 | ||
3614 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3615 | return FALSE; | |
3616 | ||
3617 | if (GET_CODE (op) == SUBREG) | |
3618 | { | |
3619 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3620 | return register_operand (op, mode); | |
3621 | ||
3622 | op = SUBREG_REG (op); | |
3623 | } | |
3624 | ||
3625 | if (GET_CODE (op) != REG) | |
3626 | return FALSE; | |
3627 | ||
3628 | return GPR_OR_PSEUDO_P (REGNO (op)); | |
3629 | } | |
3630 | ||
3631 | /* Return 1 if operand is a GPR register, or a FPR register, or a 12 bit | |
3632 | signed immediate. */ | |
3633 | ||
3634 | int gpr_fpr_or_int12_operand (op, mode) | |
3635 | rtx op; | |
3636 | enum machine_mode mode; | |
3637 | { | |
3638 | int regno; | |
3639 | ||
3640 | if (GET_CODE (op) == CONST_INT) | |
3641 | return IN_RANGE_P (INTVAL (op), -2048, 2047); | |
3642 | ||
3643 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3644 | return FALSE; | |
3645 | ||
3646 | if (GET_CODE (op) == SUBREG) | |
3647 | { | |
3648 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3649 | return register_operand (op, mode); | |
3650 | ||
3651 | op = SUBREG_REG (op); | |
3652 | } | |
3653 | ||
3654 | if (GET_CODE (op) != REG) | |
3655 | return FALSE; | |
3656 | ||
3657 | regno = REGNO (op); | |
3658 | if (GPR_P (regno) || FPR_P (regno) || regno >= FIRST_PSEUDO_REGISTER) | |
3659 | return TRUE; | |
3660 | ||
3661 | return FALSE; | |
3662 | } | |
3663 | ||
3664 | /* Return 1 if operand is a register or 6 bit signed immediate. */ | |
3665 | ||
3666 | int fpr_or_int6_operand (op, mode) | |
3667 | rtx op; | |
3668 | enum machine_mode mode; | |
3669 | { | |
3670 | if (GET_CODE (op) == CONST_INT) | |
3671 | return IN_RANGE_P (INTVAL (op), -32, 31); | |
3672 | ||
3673 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3674 | return FALSE; | |
3675 | ||
3676 | if (GET_CODE (op) == SUBREG) | |
3677 | { | |
3678 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3679 | return register_operand (op, mode); | |
3680 | ||
3681 | op = SUBREG_REG (op); | |
3682 | } | |
3683 | ||
3684 | if (GET_CODE (op) != REG) | |
3685 | return FALSE; | |
3686 | ||
3687 | return FPR_OR_PSEUDO_P (REGNO (op)); | |
3688 | } | |
3689 | ||
3690 | /* Return 1 if operand is a register or 10 bit signed immediate. */ | |
3691 | ||
3692 | int gpr_or_int10_operand (op, mode) | |
3693 | rtx op; | |
3694 | enum machine_mode mode; | |
3695 | { | |
3696 | if (GET_CODE (op) == CONST_INT) | |
3697 | return IN_RANGE_P (INTVAL (op), -512, 511); | |
3698 | ||
3699 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3700 | return FALSE; | |
3701 | ||
3702 | if (GET_CODE (op) == SUBREG) | |
3703 | { | |
3704 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3705 | return register_operand (op, mode); | |
3706 | ||
3707 | op = SUBREG_REG (op); | |
3708 | } | |
3709 | ||
3710 | if (GET_CODE (op) != REG) | |
3711 | return FALSE; | |
3712 | ||
3713 | return GPR_OR_PSEUDO_P (REGNO (op)); | |
3714 | } | |
3715 | ||
3716 | /* Return 1 if operand is a register or an integer immediate. */ | |
3717 | ||
3718 | int gpr_or_int_operand (op, mode) | |
3719 | rtx op; | |
3720 | enum machine_mode mode; | |
3721 | { | |
3722 | if (GET_CODE (op) == CONST_INT) | |
3723 | return TRUE; | |
3724 | ||
3725 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3726 | return FALSE; | |
3727 | ||
3728 | if (GET_CODE (op) == SUBREG) | |
3729 | { | |
3730 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3731 | return register_operand (op, mode); | |
3732 | ||
3733 | op = SUBREG_REG (op); | |
3734 | } | |
3735 | ||
3736 | if (GET_CODE (op) != REG) | |
3737 | return FALSE; | |
3738 | ||
3739 | return GPR_OR_PSEUDO_P (REGNO (op)); | |
3740 | } | |
3741 | ||
3742 | /* Return 1 if operand is a 12 bit signed immediate. */ | |
3743 | ||
3744 | int int12_operand (op, mode) | |
3745 | rtx op; | |
3746 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3747 | { | |
3748 | if (GET_CODE (op) != CONST_INT) | |
3749 | return FALSE; | |
3750 | ||
3751 | return IN_RANGE_P (INTVAL (op), -2048, 2047); | |
3752 | } | |
3753 | ||
3754 | /* Return 1 if operand is a 6 bit signed immediate. */ | |
3755 | ||
3756 | int int6_operand (op, mode) | |
3757 | rtx op; | |
3758 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3759 | { | |
3760 | if (GET_CODE (op) != CONST_INT) | |
3761 | return FALSE; | |
3762 | ||
3763 | return IN_RANGE_P (INTVAL (op), -32, 31); | |
3764 | } | |
3765 | ||
3766 | /* Return 1 if operand is a 5 bit signed immediate. */ | |
3767 | ||
3768 | int int5_operand (op, mode) | |
3769 | rtx op; | |
3770 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3771 | { | |
3772 | return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), -16, 15); | |
3773 | } | |
3774 | ||
3775 | /* Return 1 if operand is a 5 bit unsigned immediate. */ | |
3776 | ||
3777 | int uint5_operand (op, mode) | |
3778 | rtx op; | |
3779 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3780 | { | |
3781 | return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 31); | |
3782 | } | |
3783 | ||
3784 | /* Return 1 if operand is a 4 bit unsigned immediate. */ | |
3785 | ||
3786 | int uint4_operand (op, mode) | |
3787 | rtx op; | |
3788 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3789 | { | |
3790 | return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 15); | |
3791 | } | |
3792 | ||
3793 | /* Return 1 if operand is a 1 bit unsigned immediate (0 or 1). */ | |
3794 | ||
3795 | int uint1_operand (op, mode) | |
3796 | rtx op; | |
3797 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3798 | { | |
3799 | return GET_CODE (op) == CONST_INT && IN_RANGE_P (INTVAL (op), 0, 1); | |
3800 | } | |
3801 | ||
3802 | /* Return 1 if operand is an integer constant that takes 2 instructions | |
3803 | to load up and can be split into sethi/setlo instructions.. */ | |
3804 | ||
3805 | int int_2word_operand (op, mode) | |
3806 | rtx op; | |
3807 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3808 | { | |
3809 | HOST_WIDE_INT value; | |
3810 | REAL_VALUE_TYPE rv; | |
3811 | long l; | |
3812 | ||
3813 | switch (GET_CODE (op)) | |
3814 | { | |
3815 | default: | |
3816 | break; | |
3817 | ||
3818 | case LABEL_REF: | |
3819 | return (flag_pic == 0); | |
3820 | ||
3821 | case CONST: | |
3822 | /* small data references are already 1 word */ | |
3823 | return (flag_pic == 0) && (! const_small_data_p (op)); | |
3824 | ||
3825 | case SYMBOL_REF: | |
3826 | /* small data references are already 1 word */ | |
0f6e5d45 | 3827 | return (flag_pic == 0) && (! SYMBOL_REF_SMALL_P (op)); |
36a05131 BS |
3828 | |
3829 | case CONST_INT: | |
3830 | return ! IN_RANGE_P (INTVAL (op), -32768, 32767); | |
3831 | ||
3832 | case CONST_DOUBLE: | |
3833 | if (GET_MODE (op) == SFmode) | |
3834 | { | |
3835 | REAL_VALUE_FROM_CONST_DOUBLE (rv, op); | |
3836 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
3837 | value = l; | |
3838 | return ! IN_RANGE_P (value, -32768, 32767); | |
3839 | } | |
3840 | else if (GET_MODE (op) == VOIDmode) | |
3841 | { | |
3842 | value = CONST_DOUBLE_LOW (op); | |
3843 | return ! IN_RANGE_P (value, -32768, 32767); | |
3844 | } | |
3845 | break; | |
3846 | } | |
3847 | ||
3848 | return FALSE; | |
3849 | } | |
3850 | ||
3851 | /* Return 1 if operand is the pic address register. */ | |
3852 | int | |
3853 | pic_register_operand (op, mode) | |
3854 | rtx op; | |
3855 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3856 | { | |
3857 | if (! flag_pic) | |
3858 | return FALSE; | |
3859 | ||
3860 | if (GET_CODE (op) != REG) | |
3861 | return FALSE; | |
3862 | ||
3863 | if (REGNO (op) != PIC_REGNO) | |
3864 | return FALSE; | |
3865 | ||
3866 | return TRUE; | |
3867 | } | |
3868 | ||
3869 | /* Return 1 if operand is a symbolic reference when a PIC option is specified | |
3870 | that takes 3 seperate instructions to form. */ | |
3871 | ||
3872 | int pic_symbolic_operand (op, mode) | |
3873 | rtx op; | |
3874 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3875 | { | |
3876 | if (! flag_pic) | |
3877 | return FALSE; | |
3878 | ||
3879 | switch (GET_CODE (op)) | |
3880 | { | |
3881 | default: | |
3882 | break; | |
3883 | ||
3884 | case LABEL_REF: | |
3885 | return TRUE; | |
3886 | ||
3887 | case SYMBOL_REF: | |
3888 | /* small data references are already 1 word */ | |
0f6e5d45 | 3889 | return ! SYMBOL_REF_SMALL_P (op); |
36a05131 BS |
3890 | |
3891 | case CONST: | |
3892 | /* small data references are already 1 word */ | |
3893 | return ! const_small_data_p (op); | |
3894 | } | |
3895 | ||
3896 | return FALSE; | |
3897 | } | |
3898 | ||
3899 | /* Return 1 if operand is the small data register. */ | |
3900 | int | |
3901 | small_data_register_operand (op, mode) | |
3902 | rtx op; | |
3903 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3904 | { | |
3905 | if (GET_CODE (op) != REG) | |
3906 | return FALSE; | |
3907 | ||
3908 | if (REGNO (op) != SDA_BASE_REG) | |
3909 | return FALSE; | |
3910 | ||
3911 | return TRUE; | |
3912 | } | |
3913 | ||
3914 | /* Return 1 if operand is a symbolic reference to a small data area static or | |
3915 | global object. */ | |
3916 | ||
3917 | int small_data_symbolic_operand (op, mode) | |
3918 | rtx op; | |
3919 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3920 | { | |
3921 | switch (GET_CODE (op)) | |
3922 | { | |
3923 | default: | |
3924 | break; | |
3925 | ||
3926 | case CONST: | |
3927 | return const_small_data_p (op); | |
3928 | ||
3929 | case SYMBOL_REF: | |
0f6e5d45 | 3930 | return SYMBOL_REF_SMALL_P (op); |
36a05131 BS |
3931 | } |
3932 | ||
3933 | return FALSE; | |
3934 | } | |
3935 | ||
3936 | /* Return 1 if operand is a 16 bit unsigned immediate */ | |
3937 | ||
3938 | int uint16_operand (op, mode) | |
3939 | rtx op; | |
3940 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3941 | { | |
3942 | if (GET_CODE (op) != CONST_INT) | |
3943 | return FALSE; | |
3944 | ||
3945 | return IN_RANGE_P (INTVAL (op), 0, 0xffff); | |
3946 | } | |
3947 | ||
3948 | /* Return 1 if operand is an integer constant with the bottom 16 bits clear */ | |
3949 | ||
3950 | int upper_int16_operand (op, mode) | |
3951 | rtx op; | |
3952 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
3953 | { | |
3954 | if (GET_CODE (op) != CONST_INT) | |
3955 | return FALSE; | |
3956 | ||
3957 | return ((INTVAL (op) & 0xffff) == 0); | |
3958 | } | |
3959 | ||
3960 | /* Return true if operand is a GPR register. */ | |
3961 | ||
3962 | int | |
3963 | integer_register_operand (op, mode) | |
3964 | rtx op; | |
3965 | enum machine_mode mode; | |
3966 | { | |
3967 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3968 | return FALSE; | |
3969 | ||
3970 | if (GET_CODE (op) == SUBREG) | |
3971 | { | |
3972 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
3973 | return register_operand (op, mode); | |
3974 | ||
3975 | op = SUBREG_REG (op); | |
3976 | } | |
3977 | ||
3978 | if (GET_CODE (op) != REG) | |
3979 | return FALSE; | |
3980 | ||
3981 | return GPR_OR_PSEUDO_P (REGNO (op)); | |
3982 | } | |
3983 | ||
3984 | /* Return true if operand is a GPR register. Do not allow SUBREG's | |
3985 | here, in order to prevent a combine bug. */ | |
3986 | ||
3987 | int | |
3988 | gpr_no_subreg_operand (op, mode) | |
3989 | rtx op; | |
3990 | enum machine_mode mode; | |
3991 | { | |
3992 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
3993 | return FALSE; | |
3994 | ||
3995 | if (GET_CODE (op) != REG) | |
3996 | return FALSE; | |
3997 | ||
3998 | return GPR_OR_PSEUDO_P (REGNO (op)); | |
3999 | } | |
4000 | ||
4001 | /* Return true if operand is a FPR register. */ | |
4002 | ||
4003 | int | |
4004 | fpr_operand (op, mode) | |
4005 | rtx op; | |
4006 | enum machine_mode mode; | |
4007 | { | |
4008 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4009 | return FALSE; | |
4010 | ||
4011 | if (GET_CODE (op) == SUBREG) | |
4012 | { | |
4013 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4014 | return register_operand (op, mode); | |
4015 | ||
4016 | op = SUBREG_REG (op); | |
4017 | } | |
4018 | ||
4019 | if (GET_CODE (op) != REG) | |
4020 | return FALSE; | |
4021 | ||
4022 | return FPR_OR_PSEUDO_P (REGNO (op)); | |
4023 | } | |
4024 | ||
4025 | /* Return true if operand is an even GPR or FPR register. */ | |
4026 | ||
4027 | int | |
4028 | even_reg_operand (op, mode) | |
4029 | rtx op; | |
4030 | enum machine_mode mode; | |
4031 | { | |
4032 | int regno; | |
4033 | ||
4034 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4035 | return FALSE; | |
4036 | ||
4037 | if (GET_CODE (op) == SUBREG) | |
4038 | { | |
4039 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4040 | return register_operand (op, mode); | |
4041 | ||
4042 | op = SUBREG_REG (op); | |
4043 | } | |
4044 | ||
4045 | if (GET_CODE (op) != REG) | |
4046 | return FALSE; | |
4047 | ||
4048 | regno = REGNO (op); | |
4049 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4050 | return TRUE; | |
4051 | ||
4052 | if (GPR_P (regno)) | |
4053 | return (((regno - GPR_FIRST) & 1) == 0); | |
4054 | ||
4055 | if (FPR_P (regno)) | |
4056 | return (((regno - FPR_FIRST) & 1) == 0); | |
4057 | ||
4058 | return FALSE; | |
4059 | } | |
4060 | ||
4061 | /* Return true if operand is an odd GPR register. */ | |
4062 | ||
4063 | int | |
4064 | odd_reg_operand (op, mode) | |
4065 | rtx op; | |
4066 | enum machine_mode mode; | |
4067 | { | |
4068 | int regno; | |
4069 | ||
4070 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4071 | return FALSE; | |
4072 | ||
4073 | if (GET_CODE (op) == SUBREG) | |
4074 | { | |
4075 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4076 | return register_operand (op, mode); | |
4077 | ||
4078 | op = SUBREG_REG (op); | |
4079 | } | |
4080 | ||
4081 | if (GET_CODE (op) != REG) | |
4082 | return FALSE; | |
4083 | ||
4084 | regno = REGNO (op); | |
4085 | /* assume that reload will give us an even register */ | |
4086 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4087 | return FALSE; | |
4088 | ||
4089 | if (GPR_P (regno)) | |
4090 | return (((regno - GPR_FIRST) & 1) != 0); | |
4091 | ||
4092 | if (FPR_P (regno)) | |
4093 | return (((regno - FPR_FIRST) & 1) != 0); | |
4094 | ||
4095 | return FALSE; | |
4096 | } | |
4097 | ||
4098 | /* Return true if operand is an even GPR register. */ | |
4099 | ||
4100 | int | |
4101 | even_gpr_operand (op, mode) | |
4102 | rtx op; | |
4103 | enum machine_mode mode; | |
4104 | { | |
4105 | int regno; | |
4106 | ||
4107 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4108 | return FALSE; | |
4109 | ||
4110 | if (GET_CODE (op) == SUBREG) | |
4111 | { | |
4112 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4113 | return register_operand (op, mode); | |
4114 | ||
4115 | op = SUBREG_REG (op); | |
4116 | } | |
4117 | ||
4118 | if (GET_CODE (op) != REG) | |
4119 | return FALSE; | |
4120 | ||
4121 | regno = REGNO (op); | |
4122 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4123 | return TRUE; | |
4124 | ||
4125 | if (! GPR_P (regno)) | |
4126 | return FALSE; | |
4127 | ||
4128 | return (((regno - GPR_FIRST) & 1) == 0); | |
4129 | } | |
4130 | ||
4131 | /* Return true if operand is an odd GPR register. */ | |
4132 | ||
4133 | int | |
4134 | odd_gpr_operand (op, mode) | |
4135 | rtx op; | |
4136 | enum machine_mode mode; | |
4137 | { | |
4138 | int regno; | |
4139 | ||
4140 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4141 | return FALSE; | |
4142 | ||
4143 | if (GET_CODE (op) == SUBREG) | |
4144 | { | |
4145 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4146 | return register_operand (op, mode); | |
4147 | ||
4148 | op = SUBREG_REG (op); | |
4149 | } | |
4150 | ||
4151 | if (GET_CODE (op) != REG) | |
4152 | return FALSE; | |
4153 | ||
4154 | regno = REGNO (op); | |
4155 | /* assume that reload will give us an even register */ | |
4156 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4157 | return FALSE; | |
4158 | ||
4159 | if (! GPR_P (regno)) | |
4160 | return FALSE; | |
4161 | ||
4162 | return (((regno - GPR_FIRST) & 1) != 0); | |
4163 | } | |
4164 | ||
4165 | /* Return true if operand is a quad aligned FPR register. */ | |
4166 | ||
4167 | int | |
4168 | quad_fpr_operand (op, mode) | |
4169 | rtx op; | |
4170 | enum machine_mode mode; | |
4171 | { | |
4172 | int regno; | |
4173 | ||
4174 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4175 | return FALSE; | |
4176 | ||
4177 | if (GET_CODE (op) == SUBREG) | |
4178 | { | |
4179 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4180 | return register_operand (op, mode); | |
4181 | ||
4182 | op = SUBREG_REG (op); | |
4183 | } | |
4184 | ||
4185 | if (GET_CODE (op) != REG) | |
4186 | return FALSE; | |
4187 | ||
4188 | regno = REGNO (op); | |
4189 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4190 | return TRUE; | |
4191 | ||
4192 | if (! FPR_P (regno)) | |
4193 | return FALSE; | |
4194 | ||
4195 | return (((regno - FPR_FIRST) & 3) == 0); | |
4196 | } | |
4197 | ||
4198 | /* Return true if operand is an even FPR register. */ | |
4199 | ||
4200 | int | |
4201 | even_fpr_operand (op, mode) | |
4202 | rtx op; | |
4203 | enum machine_mode mode; | |
4204 | { | |
4205 | int regno; | |
4206 | ||
4207 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4208 | return FALSE; | |
4209 | ||
4210 | if (GET_CODE (op) == SUBREG) | |
4211 | { | |
4212 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4213 | return register_operand (op, mode); | |
4214 | ||
4215 | op = SUBREG_REG (op); | |
4216 | } | |
4217 | ||
4218 | if (GET_CODE (op) != REG) | |
4219 | return FALSE; | |
4220 | ||
4221 | regno = REGNO (op); | |
4222 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4223 | return TRUE; | |
4224 | ||
4225 | if (! FPR_P (regno)) | |
4226 | return FALSE; | |
4227 | ||
4228 | return (((regno - FPR_FIRST) & 1) == 0); | |
4229 | } | |
4230 | ||
4231 | /* Return true if operand is an odd FPR register. */ | |
4232 | ||
4233 | int | |
4234 | odd_fpr_operand (op, mode) | |
4235 | rtx op; | |
4236 | enum machine_mode mode; | |
4237 | { | |
4238 | int regno; | |
4239 | ||
4240 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4241 | return FALSE; | |
4242 | ||
4243 | if (GET_CODE (op) == SUBREG) | |
4244 | { | |
4245 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
4246 | return register_operand (op, mode); | |
4247 | ||
4248 | op = SUBREG_REG (op); | |
4249 | } | |
4250 | ||
4251 | if (GET_CODE (op) != REG) | |
4252 | return FALSE; | |
4253 | ||
4254 | regno = REGNO (op); | |
4255 | /* assume that reload will give us an even register */ | |
4256 | if (regno >= FIRST_PSEUDO_REGISTER) | |
4257 | return FALSE; | |
4258 | ||
4259 | if (! FPR_P (regno)) | |
4260 | return FALSE; | |
4261 | ||
4262 | return (((regno - FPR_FIRST) & 1) != 0); | |
4263 | } | |
4264 | ||
4265 | /* Return true if operand is a 2 word memory address that can be loaded in one | |
4266 | instruction to load or store. We assume the stack and frame pointers are | |
4267 | suitably aligned, and variables in the small data area. FIXME -- at some we | |
4268 | should recognize other globals and statics. We can't assume that any old | |
4269 | pointer is aligned, given that arguments could be passed on an odd word on | |
4270 | the stack and the address taken and passed through to another function. */ | |
4271 | ||
4272 | int | |
4273 | dbl_memory_one_insn_operand (op, mode) | |
4274 | rtx op; | |
4275 | enum machine_mode mode; | |
4276 | { | |
4277 | rtx addr; | |
4278 | rtx addr_reg; | |
4279 | ||
4280 | if (! TARGET_DWORD) | |
4281 | return FALSE; | |
4282 | ||
4283 | if (GET_CODE (op) != MEM) | |
4284 | return FALSE; | |
4285 | ||
4286 | if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD) | |
4287 | return FALSE; | |
4288 | ||
4289 | addr = XEXP (op, 0); | |
4290 | if (GET_CODE (addr) == REG) | |
4291 | addr_reg = addr; | |
4292 | ||
4293 | else if (GET_CODE (addr) == PLUS) | |
4294 | { | |
4295 | rtx addr0 = XEXP (addr, 0); | |
4296 | rtx addr1 = XEXP (addr, 1); | |
4297 | ||
4298 | if (GET_CODE (addr0) != REG) | |
4299 | return FALSE; | |
4300 | ||
4301 | if (plus_small_data_p (addr0, addr1)) | |
4302 | return TRUE; | |
4303 | ||
4304 | if (GET_CODE (addr1) != CONST_INT) | |
4305 | return FALSE; | |
4306 | ||
4307 | if ((INTVAL (addr1) & 7) != 0) | |
4308 | return FALSE; | |
4309 | ||
4310 | addr_reg = addr0; | |
4311 | } | |
4312 | ||
4313 | else | |
4314 | return FALSE; | |
4315 | ||
4316 | if (addr_reg == frame_pointer_rtx || addr_reg == stack_pointer_rtx) | |
4317 | return TRUE; | |
4318 | ||
4319 | return FALSE; | |
4320 | } | |
4321 | ||
4322 | /* Return true if operand is a 2 word memory address that needs to | |
4323 | use two instructions to load or store. */ | |
4324 | ||
4325 | int | |
4326 | dbl_memory_two_insn_operand (op, mode) | |
4327 | rtx op; | |
4328 | enum machine_mode mode; | |
4329 | { | |
4330 | if (GET_CODE (op) != MEM) | |
4331 | return FALSE; | |
4332 | ||
4333 | if (mode != VOIDmode && GET_MODE_SIZE (mode) != 2*UNITS_PER_WORD) | |
4334 | return FALSE; | |
4335 | ||
4336 | if (! TARGET_DWORD) | |
4337 | return TRUE; | |
4338 | ||
4339 | return ! dbl_memory_one_insn_operand (op, mode); | |
4340 | } | |
4341 | ||
4342 | /* Return true if operand is something that can be an output for a move | |
4343 | operation. */ | |
4344 | ||
4345 | int | |
4346 | move_destination_operand (op, mode) | |
4347 | rtx op; | |
4348 | enum machine_mode mode; | |
4349 | { | |
4350 | rtx subreg; | |
4351 | enum rtx_code code; | |
4352 | ||
4353 | switch (GET_CODE (op)) | |
4354 | { | |
4355 | default: | |
4356 | break; | |
4357 | ||
4358 | case SUBREG: | |
4359 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4360 | return FALSE; | |
4361 | ||
4362 | subreg = SUBREG_REG (op); | |
4363 | code = GET_CODE (subreg); | |
4364 | if (code == MEM) | |
4365 | return frv_legitimate_address_p (mode, XEXP (subreg, 0), | |
4366 | reload_completed, FALSE); | |
4367 | ||
4368 | return (code == REG); | |
4369 | ||
4370 | case REG: | |
4371 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4372 | return FALSE; | |
4373 | ||
4374 | return TRUE; | |
4375 | ||
4376 | case MEM: | |
4377 | if (GET_CODE (XEXP (op, 0)) == ADDRESSOF) | |
4378 | return TRUE; | |
4379 | ||
4380 | return frv_legitimate_memory_operand (op, mode, FALSE); | |
4381 | } | |
4382 | ||
4383 | return FALSE; | |
4384 | } | |
4385 | ||
4386 | /* Return true if operand is something that can be an input for a move | |
4387 | operation. */ | |
4388 | ||
4389 | int | |
4390 | move_source_operand (op, mode) | |
4391 | rtx op; | |
4392 | enum machine_mode mode; | |
4393 | { | |
4394 | rtx subreg; | |
4395 | enum rtx_code code; | |
4396 | ||
4397 | switch (GET_CODE (op)) | |
4398 | { | |
4399 | default: | |
4400 | break; | |
4401 | ||
4402 | case CONST_INT: | |
4403 | case CONST_DOUBLE: | |
4404 | case SYMBOL_REF: | |
4405 | case LABEL_REF: | |
4406 | case CONST: | |
4407 | return immediate_operand (op, mode); | |
4408 | ||
4409 | case SUBREG: | |
4410 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4411 | return FALSE; | |
4412 | ||
4413 | subreg = SUBREG_REG (op); | |
4414 | code = GET_CODE (subreg); | |
4415 | if (code == MEM) | |
4416 | return frv_legitimate_address_p (mode, XEXP (subreg, 0), | |
4417 | reload_completed, FALSE); | |
4418 | ||
4419 | return (code == REG); | |
4420 | ||
4421 | case REG: | |
4422 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4423 | return FALSE; | |
4424 | ||
4425 | return TRUE; | |
4426 | ||
4427 | case MEM: | |
4428 | if (GET_CODE (XEXP (op, 0)) == ADDRESSOF) | |
4429 | return TRUE; | |
4430 | ||
4431 | return frv_legitimate_memory_operand (op, mode, FALSE); | |
4432 | } | |
4433 | ||
4434 | return FALSE; | |
4435 | } | |
4436 | ||
4437 | /* Return true if operand is something that can be an output for a conditional | |
4438 | move operation. */ | |
4439 | ||
4440 | int | |
4441 | condexec_dest_operand (op, mode) | |
4442 | rtx op; | |
4443 | enum machine_mode mode; | |
4444 | { | |
4445 | rtx subreg; | |
4446 | enum rtx_code code; | |
4447 | ||
4448 | switch (GET_CODE (op)) | |
4449 | { | |
4450 | default: | |
4451 | break; | |
4452 | ||
4453 | case SUBREG: | |
4454 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4455 | return FALSE; | |
4456 | ||
4457 | subreg = SUBREG_REG (op); | |
4458 | code = GET_CODE (subreg); | |
4459 | if (code == MEM) | |
4460 | return frv_legitimate_address_p (mode, XEXP (subreg, 0), | |
4461 | reload_completed, TRUE); | |
4462 | ||
4463 | return (code == REG); | |
4464 | ||
4465 | case REG: | |
4466 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4467 | return FALSE; | |
4468 | ||
4469 | return TRUE; | |
4470 | ||
4471 | case MEM: | |
4472 | if (GET_CODE (XEXP (op, 0)) == ADDRESSOF) | |
4473 | return TRUE; | |
4474 | ||
4475 | return frv_legitimate_memory_operand (op, mode, TRUE); | |
4476 | } | |
4477 | ||
4478 | return FALSE; | |
4479 | } | |
4480 | ||
4481 | /* Return true if operand is something that can be an input for a conditional | |
4482 | move operation. */ | |
4483 | ||
4484 | int | |
4485 | condexec_source_operand (op, mode) | |
4486 | rtx op; | |
4487 | enum machine_mode mode; | |
4488 | { | |
4489 | rtx subreg; | |
4490 | enum rtx_code code; | |
4491 | ||
4492 | switch (GET_CODE (op)) | |
4493 | { | |
4494 | default: | |
4495 | break; | |
4496 | ||
4497 | case CONST_INT: | |
4498 | case CONST_DOUBLE: | |
4499 | return ZERO_P (op); | |
4500 | ||
4501 | case SUBREG: | |
4502 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4503 | return FALSE; | |
4504 | ||
4505 | subreg = SUBREG_REG (op); | |
4506 | code = GET_CODE (subreg); | |
4507 | if (code == MEM) | |
4508 | return frv_legitimate_address_p (mode, XEXP (subreg, 0), | |
4509 | reload_completed, TRUE); | |
4510 | ||
4511 | return (code == REG); | |
4512 | ||
4513 | case REG: | |
4514 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4515 | return FALSE; | |
4516 | ||
4517 | return TRUE; | |
4518 | ||
4519 | case MEM: | |
4520 | if (GET_CODE (XEXP (op, 0)) == ADDRESSOF) | |
4521 | return TRUE; | |
4522 | ||
4523 | return frv_legitimate_memory_operand (op, mode, TRUE); | |
4524 | } | |
4525 | ||
4526 | return FALSE; | |
4527 | } | |
4528 | ||
4529 | /* Return true if operand is a register of any flavor or a 0 of the | |
4530 | appropriate type. */ | |
4531 | ||
4532 | int | |
4533 | reg_or_0_operand (op, mode) | |
4534 | rtx op; | |
4535 | enum machine_mode mode; | |
4536 | { | |
4537 | switch (GET_CODE (op)) | |
4538 | { | |
4539 | default: | |
4540 | break; | |
4541 | ||
4542 | case REG: | |
4543 | case SUBREG: | |
4544 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4545 | return FALSE; | |
4546 | ||
4547 | return register_operand (op, mode); | |
4548 | ||
4549 | case CONST_INT: | |
4550 | case CONST_DOUBLE: | |
4551 | return ZERO_P (op); | |
4552 | } | |
4553 | ||
4554 | return FALSE; | |
4555 | } | |
4556 | ||
4557 | /* Return true if operand is the link register */ | |
4558 | ||
4559 | int | |
4560 | lr_operand (op, mode) | |
4561 | rtx op; | |
4562 | enum machine_mode mode; | |
4563 | { | |
4564 | if (GET_CODE (op) != REG) | |
4565 | return FALSE; | |
4566 | ||
4567 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4568 | return FALSE; | |
4569 | ||
4570 | if (REGNO (op) != LR_REGNO && REGNO (op) < FIRST_PSEUDO_REGISTER) | |
4571 | return FALSE; | |
4572 | ||
4573 | return TRUE; | |
4574 | } | |
4575 | ||
4576 | /* Return true if operand is a gpr register or a valid memory operation. */ | |
4577 | ||
4578 | int | |
4579 | gpr_or_memory_operand (op, mode) | |
4580 | rtx op; | |
4581 | enum machine_mode mode; | |
4582 | { | |
4583 | return (integer_register_operand (op, mode) | |
4584 | || frv_legitimate_memory_operand (op, mode, FALSE)); | |
4585 | } | |
4586 | ||
4587 | /* Return true if operand is a fpr register or a valid memory operation. */ | |
4588 | ||
4589 | int | |
4590 | fpr_or_memory_operand (op, mode) | |
4591 | rtx op; | |
4592 | enum machine_mode mode; | |
4593 | { | |
4594 | return (fpr_operand (op, mode) | |
4595 | || frv_legitimate_memory_operand (op, mode, FALSE)); | |
4596 | } | |
4597 | ||
4598 | /* Return true if operand is an icc register */ | |
4599 | ||
4600 | int | |
4601 | icc_operand (op, mode) | |
4602 | rtx op; | |
4603 | enum machine_mode mode; | |
4604 | { | |
4605 | int regno; | |
4606 | ||
4607 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4608 | return FALSE; | |
4609 | ||
4610 | if (GET_CODE (op) != REG) | |
4611 | return FALSE; | |
4612 | ||
4613 | regno = REGNO (op); | |
4614 | return ICC_OR_PSEUDO_P (regno); | |
4615 | } | |
4616 | ||
4617 | /* Return true if operand is an fcc register */ | |
4618 | ||
4619 | int | |
4620 | fcc_operand (op, mode) | |
4621 | rtx op; | |
4622 | enum machine_mode mode; | |
4623 | { | |
4624 | int regno; | |
4625 | ||
4626 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4627 | return FALSE; | |
4628 | ||
4629 | if (GET_CODE (op) != REG) | |
4630 | return FALSE; | |
4631 | ||
4632 | regno = REGNO (op); | |
4633 | return FCC_OR_PSEUDO_P (regno); | |
4634 | } | |
4635 | ||
4636 | /* Return true if operand is either an fcc or icc register */ | |
4637 | ||
4638 | int | |
4639 | cc_operand (op, mode) | |
4640 | rtx op; | |
4641 | enum machine_mode mode; | |
4642 | { | |
4643 | int regno; | |
4644 | ||
4645 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4646 | return FALSE; | |
4647 | ||
4648 | if (GET_CODE (op) != REG) | |
4649 | return FALSE; | |
4650 | ||
4651 | regno = REGNO (op); | |
4652 | if (CC_OR_PSEUDO_P (regno)) | |
4653 | return TRUE; | |
4654 | ||
4655 | return FALSE; | |
4656 | } | |
4657 | ||
4658 | /* Return true if operand is an integer CCR register */ | |
4659 | ||
4660 | int | |
4661 | icr_operand (op, mode) | |
4662 | rtx op; | |
4663 | enum machine_mode mode; | |
4664 | { | |
4665 | int regno; | |
4666 | ||
4667 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4668 | return FALSE; | |
4669 | ||
4670 | if (GET_CODE (op) != REG) | |
4671 | return FALSE; | |
4672 | ||
4673 | regno = REGNO (op); | |
4674 | return ICR_OR_PSEUDO_P (regno); | |
4675 | } | |
4676 | ||
4677 | /* Return true if operand is an fcc register */ | |
4678 | ||
4679 | int | |
4680 | fcr_operand (op, mode) | |
4681 | rtx op; | |
4682 | enum machine_mode mode; | |
4683 | { | |
4684 | int regno; | |
4685 | ||
4686 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4687 | return FALSE; | |
4688 | ||
4689 | if (GET_CODE (op) != REG) | |
4690 | return FALSE; | |
4691 | ||
4692 | regno = REGNO (op); | |
4693 | return FCR_OR_PSEUDO_P (regno); | |
4694 | } | |
4695 | ||
4696 | /* Return true if operand is either an fcc or icc register */ | |
4697 | ||
4698 | int | |
4699 | cr_operand (op, mode) | |
4700 | rtx op; | |
4701 | enum machine_mode mode; | |
4702 | { | |
4703 | int regno; | |
4704 | ||
4705 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
4706 | return FALSE; | |
4707 | ||
4708 | if (GET_CODE (op) != REG) | |
4709 | return FALSE; | |
4710 | ||
4711 | regno = REGNO (op); | |
4712 | if (CR_OR_PSEUDO_P (regno)) | |
4713 | return TRUE; | |
4714 | ||
4715 | return FALSE; | |
4716 | } | |
4717 | ||
4718 | /* Return true if operand is a memory reference suitable for a call. */ | |
4719 | ||
4720 | int | |
4721 | call_operand (op, mode) | |
4722 | rtx op; | |
4723 | enum machine_mode mode; | |
4724 | { | |
4725 | if (GET_MODE (op) != mode && mode != VOIDmode && GET_CODE (op) != CONST_INT) | |
4726 | return FALSE; | |
4727 | ||
4728 | if (GET_CODE (op) == SYMBOL_REF) | |
4729 | return TRUE; | |
4730 | ||
4731 | /* Note this doesn't allow reg+reg or reg+imm12 addressing (which should | |
4732 | never occur anyway), but prevents reload from not handling the case | |
4733 | properly of a call through a pointer on a function that calls | |
4734 | vfork/setjmp, etc. due to the need to flush all of the registers to stack. */ | |
4735 | return gpr_or_int12_operand (op, mode); | |
4736 | } | |
4737 | ||
5bdc5878 | 4738 | /* Return true if operator is a kind of relational operator. */ |
36a05131 BS |
4739 | |
4740 | int | |
4741 | relational_operator (op, mode) | |
4742 | rtx op; | |
4743 | enum machine_mode mode; | |
4744 | { | |
4745 | rtx op0; | |
4746 | rtx op1; | |
4747 | int regno; | |
4748 | ||
4749 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4750 | return FALSE; | |
4751 | ||
4752 | switch (GET_CODE (op)) | |
4753 | { | |
4754 | default: | |
4755 | return FALSE; | |
4756 | ||
4757 | case EQ: | |
4758 | case NE: | |
4759 | case LE: | |
4760 | case LT: | |
4761 | case GE: | |
4762 | case GT: | |
4763 | case LEU: | |
4764 | case LTU: | |
4765 | case GEU: | |
4766 | case GTU: | |
4767 | break; | |
4768 | } | |
4769 | ||
4770 | op1 = XEXP (op, 1); | |
4771 | if (op1 != const0_rtx) | |
4772 | return FALSE; | |
4773 | ||
4774 | op0 = XEXP (op, 0); | |
4775 | if (GET_CODE (op0) != REG) | |
4776 | return FALSE; | |
4777 | ||
4778 | regno = REGNO (op0); | |
4779 | switch (GET_MODE (op0)) | |
4780 | { | |
4781 | default: | |
4782 | break; | |
4783 | ||
4784 | case CCmode: | |
4785 | case CC_UNSmode: | |
4786 | return ICC_OR_PSEUDO_P (regno); | |
4787 | ||
4788 | case CC_FPmode: | |
4789 | return FCC_OR_PSEUDO_P (regno); | |
4790 | ||
4791 | case CC_CCRmode: | |
4792 | return CR_OR_PSEUDO_P (regno); | |
4793 | } | |
4794 | ||
4795 | return FALSE; | |
4796 | } | |
4797 | ||
4798 | /* Return true if operator is a signed integer relational operator */ | |
4799 | ||
4800 | int | |
4801 | signed_relational_operator (op, mode) | |
4802 | rtx op; | |
4803 | enum machine_mode mode; | |
4804 | { | |
4805 | rtx op0; | |
4806 | rtx op1; | |
4807 | int regno; | |
4808 | ||
4809 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4810 | return FALSE; | |
4811 | ||
4812 | switch (GET_CODE (op)) | |
4813 | { | |
4814 | default: | |
4815 | return FALSE; | |
4816 | ||
4817 | case EQ: | |
4818 | case NE: | |
4819 | case LE: | |
4820 | case LT: | |
4821 | case GE: | |
4822 | case GT: | |
4823 | break; | |
4824 | } | |
4825 | ||
4826 | op1 = XEXP (op, 1); | |
4827 | if (op1 != const0_rtx) | |
4828 | return FALSE; | |
4829 | ||
4830 | op0 = XEXP (op, 0); | |
4831 | if (GET_CODE (op0) != REG) | |
4832 | return FALSE; | |
4833 | ||
4834 | regno = REGNO (op0); | |
4835 | if (GET_MODE (op0) == CCmode && ICC_OR_PSEUDO_P (regno)) | |
4836 | return TRUE; | |
4837 | ||
4838 | if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno)) | |
4839 | return TRUE; | |
4840 | ||
4841 | return FALSE; | |
4842 | } | |
4843 | ||
4844 | /* Return true if operator is a signed integer relational operator */ | |
4845 | ||
4846 | int | |
4847 | unsigned_relational_operator (op, mode) | |
4848 | rtx op; | |
4849 | enum machine_mode mode; | |
4850 | { | |
4851 | rtx op0; | |
4852 | rtx op1; | |
4853 | int regno; | |
4854 | ||
4855 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4856 | return FALSE; | |
4857 | ||
4858 | switch (GET_CODE (op)) | |
4859 | { | |
4860 | default: | |
4861 | return FALSE; | |
4862 | ||
4863 | case LEU: | |
4864 | case LTU: | |
4865 | case GEU: | |
4866 | case GTU: | |
4867 | break; | |
4868 | } | |
4869 | ||
4870 | op1 = XEXP (op, 1); | |
4871 | if (op1 != const0_rtx) | |
4872 | return FALSE; | |
4873 | ||
4874 | op0 = XEXP (op, 0); | |
4875 | if (GET_CODE (op0) != REG) | |
4876 | return FALSE; | |
4877 | ||
4878 | regno = REGNO (op0); | |
4879 | if (GET_MODE (op0) == CC_UNSmode && ICC_OR_PSEUDO_P (regno)) | |
4880 | return TRUE; | |
4881 | ||
4882 | if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno)) | |
4883 | return TRUE; | |
4884 | ||
4885 | return FALSE; | |
4886 | } | |
4887 | ||
4888 | /* Return true if operator is a floating point relational operator */ | |
4889 | ||
4890 | int | |
4891 | float_relational_operator (op, mode) | |
4892 | rtx op; | |
4893 | enum machine_mode mode; | |
4894 | { | |
4895 | rtx op0; | |
4896 | rtx op1; | |
4897 | int regno; | |
4898 | ||
4899 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4900 | return FALSE; | |
4901 | ||
4902 | switch (GET_CODE (op)) | |
4903 | { | |
4904 | default: | |
4905 | return FALSE; | |
4906 | ||
4907 | case EQ: case NE: | |
4908 | case LE: case LT: | |
4909 | case GE: case GT: | |
4910 | #if 0 | |
4911 | case UEQ: case UNE: | |
4912 | case ULE: case ULT: | |
4913 | case UGE: case UGT: | |
4914 | case ORDERED: | |
4915 | case UNORDERED: | |
4916 | #endif | |
4917 | break; | |
4918 | } | |
4919 | ||
4920 | op1 = XEXP (op, 1); | |
4921 | if (op1 != const0_rtx) | |
4922 | return FALSE; | |
4923 | ||
4924 | op0 = XEXP (op, 0); | |
4925 | if (GET_CODE (op0) != REG) | |
4926 | return FALSE; | |
4927 | ||
4928 | regno = REGNO (op0); | |
4929 | if (GET_MODE (op0) == CC_FPmode && FCC_OR_PSEUDO_P (regno)) | |
4930 | return TRUE; | |
4931 | ||
4932 | if (GET_MODE (op0) == CC_CCRmode && CR_OR_PSEUDO_P (regno)) | |
4933 | return TRUE; | |
4934 | ||
4935 | return FALSE; | |
4936 | } | |
4937 | ||
4938 | /* Return true if operator is EQ/NE of a conditional execution register. */ | |
4939 | ||
4940 | int | |
4941 | ccr_eqne_operator (op, mode) | |
4942 | rtx op; | |
4943 | enum machine_mode mode; | |
4944 | { | |
4945 | enum machine_mode op_mode = GET_MODE (op); | |
4946 | rtx op0; | |
4947 | rtx op1; | |
4948 | int regno; | |
4949 | ||
4950 | if (mode != VOIDmode && op_mode != mode) | |
4951 | return FALSE; | |
4952 | ||
4953 | switch (GET_CODE (op)) | |
4954 | { | |
4955 | default: | |
4956 | return FALSE; | |
4957 | ||
4958 | case EQ: | |
4959 | case NE: | |
4960 | break; | |
4961 | } | |
4962 | ||
4963 | op1 = XEXP (op, 1); | |
4964 | if (op1 != const0_rtx) | |
4965 | return FALSE; | |
4966 | ||
4967 | op0 = XEXP (op, 0); | |
4968 | if (GET_CODE (op0) != REG) | |
4969 | return FALSE; | |
4970 | ||
4971 | regno = REGNO (op0); | |
4972 | if (op_mode == CC_CCRmode && CR_OR_PSEUDO_P (regno)) | |
4973 | return TRUE; | |
4974 | ||
4975 | return FALSE; | |
4976 | } | |
4977 | ||
4978 | /* Return true if operator is a minimum or maximum operator (both signed and | |
4979 | unsigned). */ | |
4980 | ||
4981 | int | |
4982 | minmax_operator (op, mode) | |
4983 | rtx op; | |
4984 | enum machine_mode mode; | |
4985 | { | |
4986 | if (mode != VOIDmode && mode != GET_MODE (op)) | |
4987 | return FALSE; | |
4988 | ||
4989 | switch (GET_CODE (op)) | |
4990 | { | |
4991 | default: | |
4992 | return FALSE; | |
4993 | ||
4994 | case SMIN: | |
4995 | case SMAX: | |
4996 | case UMIN: | |
4997 | case UMAX: | |
4998 | break; | |
4999 | } | |
5000 | ||
5001 | if (! integer_register_operand (XEXP (op, 0), mode)) | |
5002 | return FALSE; | |
5003 | ||
5004 | if (! gpr_or_int10_operand (XEXP (op, 1), mode)) | |
5005 | return FALSE; | |
5006 | ||
5007 | return TRUE; | |
5008 | } | |
5009 | ||
5010 | /* Return true if operator is an integer binary operator that can executed | |
5011 | conditionally and takes 1 cycle. */ | |
5012 | ||
5013 | int | |
5014 | condexec_si_binary_operator (op, mode) | |
5015 | rtx op; | |
5016 | enum machine_mode mode; | |
5017 | { | |
5018 | enum machine_mode op_mode = GET_MODE (op); | |
5019 | ||
5020 | if (mode != VOIDmode && op_mode != mode) | |
5021 | return FALSE; | |
5022 | ||
5023 | switch (GET_CODE (op)) | |
5024 | { | |
5025 | default: | |
5026 | return FALSE; | |
5027 | ||
5028 | case PLUS: | |
5029 | case MINUS: | |
5030 | case AND: | |
5031 | case IOR: | |
5032 | case XOR: | |
5033 | case ASHIFT: | |
5034 | case ASHIFTRT: | |
5035 | case LSHIFTRT: | |
5036 | return TRUE; | |
5037 | } | |
5038 | } | |
5039 | ||
5040 | /* Return true if operator is an integer binary operator that can be | |
5041 | executed conditionally by a media instruction. */ | |
5042 | ||
5043 | int | |
5044 | condexec_si_media_operator (op, mode) | |
5045 | rtx op; | |
5046 | enum machine_mode mode; | |
5047 | { | |
5048 | enum machine_mode op_mode = GET_MODE (op); | |
5049 | ||
5050 | if (mode != VOIDmode && op_mode != mode) | |
5051 | return FALSE; | |
5052 | ||
5053 | switch (GET_CODE (op)) | |
5054 | { | |
5055 | default: | |
5056 | return FALSE; | |
5057 | ||
5058 | case AND: | |
5059 | case IOR: | |
5060 | case XOR: | |
5061 | return TRUE; | |
5062 | } | |
5063 | } | |
5064 | ||
5065 | /* Return true if operator is an integer division operator that can executed | |
5066 | conditionally. */ | |
5067 | ||
5068 | int | |
5069 | condexec_si_divide_operator (op, mode) | |
5070 | rtx op; | |
5071 | enum machine_mode mode; | |
5072 | { | |
5073 | enum machine_mode op_mode = GET_MODE (op); | |
5074 | ||
5075 | if (mode != VOIDmode && op_mode != mode) | |
5076 | return FALSE; | |
5077 | ||
5078 | switch (GET_CODE (op)) | |
5079 | { | |
5080 | default: | |
5081 | return FALSE; | |
5082 | ||
5083 | case DIV: | |
5084 | case UDIV: | |
5085 | return TRUE; | |
5086 | } | |
5087 | } | |
5088 | ||
5089 | /* Return true if operator is an integer unary operator that can executed | |
5090 | conditionally. */ | |
5091 | ||
5092 | int | |
5093 | condexec_si_unary_operator (op, mode) | |
5094 | rtx op; | |
5095 | enum machine_mode mode; | |
5096 | { | |
5097 | enum machine_mode op_mode = GET_MODE (op); | |
5098 | ||
5099 | if (mode != VOIDmode && op_mode != mode) | |
5100 | return FALSE; | |
5101 | ||
5102 | switch (GET_CODE (op)) | |
5103 | { | |
5104 | default: | |
5105 | return FALSE; | |
5106 | ||
5107 | case NEG: | |
5108 | case NOT: | |
5109 | return TRUE; | |
5110 | } | |
5111 | } | |
5112 | ||
5113 | /* Return true if operator is a conversion-type expression that can be | |
5114 | evaluated conditionally by floating-point instructions. */ | |
5115 | ||
5116 | int | |
5117 | condexec_sf_conv_operator (op, mode) | |
5118 | rtx op; | |
5119 | enum machine_mode mode; | |
5120 | { | |
5121 | enum machine_mode op_mode = GET_MODE (op); | |
5122 | ||
5123 | if (mode != VOIDmode && op_mode != mode) | |
5124 | return FALSE; | |
5125 | ||
5126 | switch (GET_CODE (op)) | |
5127 | { | |
5128 | default: | |
5129 | return FALSE; | |
5130 | ||
5131 | case NEG: | |
5132 | case ABS: | |
5133 | return TRUE; | |
5134 | } | |
5135 | } | |
5136 | ||
5137 | /* Return true if operator is an addition or subtraction expression. | |
5138 | Such expressions can be evaluated conditionally by floating-point | |
5139 | instructions. */ | |
5140 | ||
5141 | int | |
5142 | condexec_sf_add_operator (op, mode) | |
5143 | rtx op; | |
5144 | enum machine_mode mode; | |
5145 | { | |
5146 | enum machine_mode op_mode = GET_MODE (op); | |
5147 | ||
5148 | if (mode != VOIDmode && op_mode != mode) | |
5149 | return FALSE; | |
5150 | ||
5151 | switch (GET_CODE (op)) | |
5152 | { | |
5153 | default: | |
5154 | return FALSE; | |
5155 | ||
5156 | case PLUS: | |
5157 | case MINUS: | |
5158 | return TRUE; | |
5159 | } | |
5160 | } | |
5161 | ||
5162 | /* Return true if the memory operand is one that can be conditionally | |
5163 | executed. */ | |
5164 | ||
5165 | int | |
5166 | condexec_memory_operand (op, mode) | |
5167 | rtx op; | |
5168 | enum machine_mode mode; | |
5169 | { | |
5170 | enum machine_mode op_mode = GET_MODE (op); | |
5171 | rtx addr; | |
5172 | ||
5173 | if (mode != VOIDmode && op_mode != mode) | |
5174 | return FALSE; | |
5175 | ||
5176 | switch (op_mode) | |
5177 | { | |
5178 | default: | |
5179 | return FALSE; | |
5180 | ||
5181 | case QImode: | |
5182 | case HImode: | |
5183 | case SImode: | |
5184 | case SFmode: | |
5185 | break; | |
5186 | } | |
5187 | ||
5188 | if (GET_CODE (op) != MEM) | |
5189 | return FALSE; | |
5190 | ||
5191 | addr = XEXP (op, 0); | |
5192 | if (GET_CODE (addr) == ADDRESSOF) | |
5193 | return TRUE; | |
5194 | ||
5195 | return frv_legitimate_address_p (mode, addr, reload_completed, TRUE); | |
5196 | } | |
5197 | ||
5198 | /* Return true if operator is an integer binary operator that can be combined | |
5199 | with a setcc operation. Do not allow the arithmetic operations that could | |
5200 | potentially overflow since the FR-V sets the condition code based on the | |
5201 | "true" value of the result, not the result after truncating to a 32-bit | |
5202 | register. */ | |
5203 | ||
5204 | int | |
5205 | intop_compare_operator (op, mode) | |
5206 | rtx op; | |
5207 | enum machine_mode mode; | |
5208 | { | |
5209 | enum machine_mode op_mode = GET_MODE (op); | |
5210 | ||
5211 | if (mode != VOIDmode && op_mode != mode) | |
5212 | return FALSE; | |
5213 | ||
5214 | switch (GET_CODE (op)) | |
5215 | { | |
5216 | default: | |
5217 | return FALSE; | |
5218 | ||
5219 | case AND: | |
5220 | case IOR: | |
5221 | case XOR: | |
5222 | case ASHIFTRT: | |
5223 | case LSHIFTRT: | |
5224 | break; | |
5225 | } | |
5226 | ||
5227 | if (! integer_register_operand (XEXP (op, 0), SImode)) | |
5228 | return FALSE; | |
5229 | ||
5230 | if (! gpr_or_int10_operand (XEXP (op, 1), SImode)) | |
5231 | return FALSE; | |
5232 | ||
5233 | return TRUE; | |
5234 | } | |
5235 | ||
5236 | /* Return true if operator is an integer binary operator that can be combined | |
5237 | with a setcc operation inside of a conditional execution. */ | |
5238 | ||
5239 | int | |
5240 | condexec_intop_cmp_operator (op, mode) | |
5241 | rtx op; | |
5242 | enum machine_mode mode; | |
5243 | { | |
5244 | enum machine_mode op_mode = GET_MODE (op); | |
5245 | ||
5246 | if (mode != VOIDmode && op_mode != mode) | |
5247 | return FALSE; | |
5248 | ||
5249 | switch (GET_CODE (op)) | |
5250 | { | |
5251 | default: | |
5252 | return FALSE; | |
5253 | ||
5254 | case AND: | |
5255 | case IOR: | |
5256 | case XOR: | |
5257 | case ASHIFTRT: | |
5258 | case LSHIFTRT: | |
5259 | break; | |
5260 | } | |
5261 | ||
5262 | if (! integer_register_operand (XEXP (op, 0), SImode)) | |
5263 | return FALSE; | |
5264 | ||
5265 | if (! integer_register_operand (XEXP (op, 1), SImode)) | |
5266 | return FALSE; | |
5267 | ||
5268 | return TRUE; | |
5269 | } | |
5270 | ||
5271 | /* Return 1 if operand is a valid ACC register number */ | |
5272 | ||
5273 | int | |
5274 | acc_operand (op, mode) | |
5275 | rtx op; | |
5276 | enum machine_mode mode; | |
5277 | { | |
5278 | int regno; | |
5279 | ||
5280 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
5281 | return FALSE; | |
5282 | ||
5283 | if (GET_CODE (op) == SUBREG) | |
5284 | { | |
5285 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
5286 | return register_operand (op, mode); | |
5287 | ||
5288 | op = SUBREG_REG (op); | |
5289 | } | |
5290 | ||
5291 | if (GET_CODE (op) != REG) | |
5292 | return FALSE; | |
5293 | ||
5294 | regno = REGNO (op); | |
5295 | return ACC_OR_PSEUDO_P (regno); | |
5296 | } | |
5297 | ||
5298 | /* Return 1 if operand is a valid even ACC register number */ | |
5299 | ||
5300 | int | |
5301 | even_acc_operand (op, mode) | |
5302 | rtx op; | |
5303 | enum machine_mode mode; | |
5304 | { | |
5305 | int regno; | |
5306 | ||
5307 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
5308 | return FALSE; | |
5309 | ||
5310 | if (GET_CODE (op) == SUBREG) | |
5311 | { | |
5312 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
5313 | return register_operand (op, mode); | |
5314 | ||
5315 | op = SUBREG_REG (op); | |
5316 | } | |
5317 | ||
5318 | if (GET_CODE (op) != REG) | |
5319 | return FALSE; | |
5320 | ||
5321 | regno = REGNO (op); | |
5322 | return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 1) == 0); | |
5323 | } | |
5324 | ||
5325 | /* Return 1 if operand is zero or four */ | |
5326 | ||
5327 | int | |
5328 | quad_acc_operand (op, mode) | |
5329 | rtx op; | |
5330 | enum machine_mode mode; | |
5331 | { | |
5332 | int regno; | |
5333 | ||
5334 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
5335 | return FALSE; | |
5336 | ||
5337 | if (GET_CODE (op) == SUBREG) | |
5338 | { | |
5339 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
5340 | return register_operand (op, mode); | |
5341 | ||
5342 | op = SUBREG_REG (op); | |
5343 | } | |
5344 | ||
5345 | if (GET_CODE (op) != REG) | |
5346 | return FALSE; | |
5347 | ||
5348 | regno = REGNO (op); | |
5349 | return (ACC_OR_PSEUDO_P (regno) && ((regno - ACC_FIRST) & 3) == 0); | |
5350 | } | |
5351 | ||
5352 | /* Return 1 if operand is a valid ACCG register number */ | |
5353 | ||
5354 | int | |
5355 | accg_operand (op, mode) | |
5356 | rtx op; | |
5357 | enum machine_mode mode; | |
5358 | { | |
5359 | if (GET_MODE (op) != mode && mode != VOIDmode) | |
5360 | return FALSE; | |
5361 | ||
5362 | if (GET_CODE (op) == SUBREG) | |
5363 | { | |
5364 | if (GET_CODE (SUBREG_REG (op)) != REG) | |
5365 | return register_operand (op, mode); | |
5366 | ||
5367 | op = SUBREG_REG (op); | |
5368 | } | |
5369 | ||
5370 | if (GET_CODE (op) != REG) | |
5371 | return FALSE; | |
5372 | ||
5373 | return ACCG_OR_PSEUDO_P (REGNO (op)); | |
5374 | } | |
5375 | ||
5376 | \f | |
5377 | /* Return true if the bare return instruction can be used outside of the | |
5378 | epilog code. For frv, we only do it if there was no stack allocation. */ | |
5379 | ||
5380 | int | |
5381 | direct_return_p () | |
5382 | { | |
5383 | frv_stack_t *info; | |
5384 | ||
5385 | if (!reload_completed) | |
5386 | return FALSE; | |
5387 | ||
5388 | info = frv_stack_info (); | |
5389 | return (info->total_size == 0); | |
5390 | } | |
5391 | ||
5392 | \f | |
5393 | /* Emit code to handle a MOVSI, adding in the small data register or pic | |
5394 | register if needed to load up addresses. Return TRUE if the appropriate | |
5395 | instructions are emitted. */ | |
5396 | ||
5397 | int | |
5398 | frv_emit_movsi (dest, src) | |
5399 | rtx dest; | |
5400 | rtx src; | |
5401 | { | |
5402 | int base_regno = -1; | |
5403 | ||
5404 | if (!reload_in_progress | |
5405 | && !reload_completed | |
5406 | && !register_operand (dest, SImode) | |
5407 | && (!reg_or_0_operand (src, SImode) | |
5408 | /* Virtual registers will almost always be replaced by an | |
5409 | add instruction, so expose this to CSE by copying to | |
5410 | an intermediate register */ | |
5411 | || (GET_CODE (src) == REG | |
5412 | && IN_RANGE_P (REGNO (src), | |
5413 | FIRST_VIRTUAL_REGISTER, | |
5414 | LAST_VIRTUAL_REGISTER)))) | |
5415 | { | |
5416 | emit_insn (gen_rtx_SET (VOIDmode, dest, copy_to_mode_reg (SImode, src))); | |
5417 | return TRUE; | |
5418 | } | |
5419 | ||
5420 | /* Explicitly add in the PIC or small data register if needed. */ | |
5421 | switch (GET_CODE (src)) | |
5422 | { | |
5423 | default: | |
5424 | break; | |
5425 | ||
5426 | case LABEL_REF: | |
5427 | if (flag_pic) | |
5428 | base_regno = PIC_REGNO; | |
5429 | ||
5430 | break; | |
5431 | ||
5432 | case CONST: | |
5433 | if (const_small_data_p (src)) | |
5434 | base_regno = SDA_BASE_REG; | |
5435 | ||
5436 | else if (flag_pic) | |
5437 | base_regno = PIC_REGNO; | |
5438 | ||
5439 | break; | |
5440 | ||
5441 | case SYMBOL_REF: | |
0f6e5d45 | 5442 | if (SYMBOL_REF_SMALL_P (src)) |
36a05131 BS |
5443 | base_regno = SDA_BASE_REG; |
5444 | ||
5445 | else if (flag_pic) | |
5446 | base_regno = PIC_REGNO; | |
5447 | ||
5448 | break; | |
5449 | } | |
5450 | ||
5451 | if (base_regno >= 0) | |
5452 | { | |
5453 | emit_insn (gen_rtx_SET (VOIDmode, dest, | |
5454 | gen_rtx_PLUS (Pmode, | |
5455 | gen_rtx_REG (Pmode, base_regno), | |
5456 | src))); | |
5457 | ||
5458 | if (base_regno == PIC_REGNO) | |
5459 | cfun->uses_pic_offset_table = TRUE; | |
5460 | ||
5461 | return TRUE; | |
5462 | } | |
5463 | ||
5464 | return FALSE; | |
5465 | } | |
5466 | ||
5467 | \f | |
5468 | /* Return a string to output a single word move. */ | |
5469 | ||
5470 | const char * | |
5471 | output_move_single (operands, insn) | |
5472 | rtx operands[]; | |
5473 | rtx insn; | |
5474 | { | |
5475 | rtx dest = operands[0]; | |
5476 | rtx src = operands[1]; | |
5477 | ||
5478 | if (GET_CODE (dest) == REG) | |
5479 | { | |
5480 | int dest_regno = REGNO (dest); | |
5481 | enum machine_mode mode = GET_MODE (dest); | |
5482 | ||
5483 | if (GPR_P (dest_regno)) | |
5484 | { | |
5485 | if (GET_CODE (src) == REG) | |
5486 | { | |
5487 | /* gpr <- some sort of register */ | |
5488 | int src_regno = REGNO (src); | |
5489 | ||
5490 | if (GPR_P (src_regno)) | |
5491 | return "mov %1, %0"; | |
5492 | ||
5493 | else if (FPR_P (src_regno)) | |
5494 | return "movfg %1, %0"; | |
5495 | ||
5496 | else if (SPR_P (src_regno)) | |
5497 | return "movsg %1, %0"; | |
5498 | } | |
5499 | ||
5500 | else if (GET_CODE (src) == MEM) | |
5501 | { | |
5502 | /* gpr <- memory */ | |
5503 | switch (mode) | |
5504 | { | |
5505 | default: | |
5506 | break; | |
5507 | ||
5508 | case QImode: | |
5509 | return "ldsb%I1%U1 %M1,%0"; | |
5510 | ||
5511 | case HImode: | |
5512 | return "ldsh%I1%U1 %M1,%0"; | |
5513 | ||
5514 | case SImode: | |
5515 | case SFmode: | |
5516 | return "ld%I1%U1 %M1, %0"; | |
5517 | } | |
5518 | } | |
5519 | ||
5520 | else if (GET_CODE (src) == CONST_INT | |
5521 | || GET_CODE (src) == CONST_DOUBLE) | |
5522 | { | |
5523 | /* gpr <- integer/floating constant */ | |
5524 | HOST_WIDE_INT value; | |
5525 | ||
5526 | if (GET_CODE (src) == CONST_INT) | |
5527 | value = INTVAL (src); | |
5528 | ||
5529 | else if (mode == SFmode) | |
5530 | { | |
5531 | REAL_VALUE_TYPE rv; | |
5532 | long l; | |
5533 | ||
5534 | REAL_VALUE_FROM_CONST_DOUBLE (rv, src); | |
5535 | REAL_VALUE_TO_TARGET_SINGLE (rv, l); | |
5536 | value = l; | |
5537 | } | |
5538 | ||
5539 | else | |
5540 | value = CONST_DOUBLE_LOW (src); | |
5541 | ||
5542 | if (IN_RANGE_P (value, -32768, 32767)) | |
5543 | return "setlos %1, %0"; | |
5544 | ||
5545 | return "#"; | |
5546 | } | |
5547 | ||
5548 | else if (GET_CODE (src) == SYMBOL_REF | |
5549 | || GET_CODE (src) == LABEL_REF | |
5550 | || GET_CODE (src) == CONST) | |
5551 | { | |
5552 | /* Silently fix up instances where the small data pointer is not | |
5553 | used in the address. */ | |
5554 | if (small_data_symbolic_operand (src, GET_MODE (src))) | |
5555 | return "addi %@, #gprel12(%1), %0"; | |
5556 | ||
5557 | return "#"; | |
5558 | } | |
5559 | } | |
5560 | ||
5561 | else if (FPR_P (dest_regno)) | |
5562 | { | |
5563 | if (GET_CODE (src) == REG) | |
5564 | { | |
5565 | /* fpr <- some sort of register */ | |
5566 | int src_regno = REGNO (src); | |
5567 | ||
5568 | if (GPR_P (src_regno)) | |
5569 | return "movgf %1, %0"; | |
5570 | ||
5571 | else if (FPR_P (src_regno)) | |
5572 | { | |
5573 | if (TARGET_HARD_FLOAT) | |
5574 | return "fmovs %1, %0"; | |
5575 | else | |
5576 | return "mor %1, %1, %0"; | |
5577 | } | |
5578 | } | |
5579 | ||
5580 | else if (GET_CODE (src) == MEM) | |
5581 | { | |
5582 | /* fpr <- memory */ | |
5583 | switch (mode) | |
5584 | { | |
5585 | default: | |
5586 | break; | |
5587 | ||
5588 | case QImode: | |
5589 | return "ldbf%I1%U1 %M1,%0"; | |
5590 | ||
5591 | case HImode: | |
5592 | return "ldhf%I1%U1 %M1,%0"; | |
5593 | ||
5594 | case SImode: | |
5595 | case SFmode: | |
5596 | return "ldf%I1%U1 %M1, %0"; | |
5597 | } | |
5598 | } | |
5599 | ||
5600 | else if (ZERO_P (src)) | |
5601 | return "movgf %., %0"; | |
5602 | } | |
5603 | ||
5604 | else if (SPR_P (dest_regno)) | |
5605 | { | |
5606 | if (GET_CODE (src) == REG) | |
5607 | { | |
5608 | /* spr <- some sort of register */ | |
5609 | int src_regno = REGNO (src); | |
5610 | ||
5611 | if (GPR_P (src_regno)) | |
5612 | return "movgs %1, %0"; | |
5613 | } | |
5614 | } | |
5615 | } | |
5616 | ||
5617 | else if (GET_CODE (dest) == MEM) | |
5618 | { | |
5619 | if (GET_CODE (src) == REG) | |
5620 | { | |
5621 | int src_regno = REGNO (src); | |
5622 | enum machine_mode mode = GET_MODE (dest); | |
5623 | ||
5624 | if (GPR_P (src_regno)) | |
5625 | { | |
5626 | switch (mode) | |
5627 | { | |
5628 | default: | |
5629 | break; | |
5630 | ||
5631 | case QImode: | |
5632 | return "stb%I0%U0 %1, %M0"; | |
5633 | ||
5634 | case HImode: | |
5635 | return "sth%I0%U0 %1, %M0"; | |
5636 | ||
5637 | case SImode: | |
5638 | case SFmode: | |
5639 | return "st%I0%U0 %1, %M0"; | |
5640 | } | |
5641 | } | |
5642 | ||
5643 | else if (FPR_P (src_regno)) | |
5644 | { | |
5645 | switch (mode) | |
5646 | { | |
5647 | default: | |
5648 | break; | |
5649 | ||
5650 | case QImode: | |
5651 | return "stbf%I0%U0 %1, %M0"; | |
5652 | ||
5653 | case HImode: | |
5654 | return "sthf%I0%U0 %1, %M0"; | |
5655 | ||
5656 | case SImode: | |
5657 | case SFmode: | |
5658 | return "stf%I0%U0 %1, %M0"; | |
5659 | } | |
5660 | } | |
5661 | } | |
5662 | ||
5663 | else if (ZERO_P (src)) | |
5664 | { | |
5665 | switch (GET_MODE (dest)) | |
5666 | { | |
5667 | default: | |
5668 | break; | |
5669 | ||
5670 | case QImode: | |
5671 | return "stb%I0%U0 %., %M0"; | |
5672 | ||
5673 | case HImode: | |
5674 | return "sth%I0%U0 %., %M0"; | |
5675 | ||
5676 | case SImode: | |
5677 | case SFmode: | |
5678 | return "st%I0%U0 %., %M0"; | |
5679 | } | |
5680 | } | |
5681 | } | |
5682 | ||
5683 | fatal_insn ("Bad output_move_single operand", insn); | |
5684 | return ""; | |
5685 | } | |
5686 | ||
5687 | \f | |
5688 | /* Return a string to output a double word move. */ | |
5689 | ||
5690 | const char * | |
5691 | output_move_double (operands, insn) | |
5692 | rtx operands[]; | |
5693 | rtx insn; | |
5694 | { | |
5695 | rtx dest = operands[0]; | |
5696 | rtx src = operands[1]; | |
5697 | enum machine_mode mode = GET_MODE (dest); | |
5698 | ||
5699 | if (GET_CODE (dest) == REG) | |
5700 | { | |
5701 | int dest_regno = REGNO (dest); | |
5702 | ||
5703 | if (GPR_P (dest_regno)) | |
5704 | { | |
5705 | if (GET_CODE (src) == REG) | |
5706 | { | |
5707 | /* gpr <- some sort of register */ | |
5708 | int src_regno = REGNO (src); | |
5709 | ||
5710 | if (GPR_P (src_regno)) | |
5711 | return "#"; | |
5712 | ||
5713 | else if (FPR_P (src_regno)) | |
5714 | { | |
5715 | if (((dest_regno - GPR_FIRST) & 1) == 0 | |
5716 | && ((src_regno - FPR_FIRST) & 1) == 0) | |
5717 | return "movfgd %1, %0"; | |
5718 | ||
5719 | return "#"; | |
5720 | } | |
5721 | } | |
5722 | ||
5723 | else if (GET_CODE (src) == MEM) | |
5724 | { | |
5725 | /* gpr <- memory */ | |
5726 | if (dbl_memory_one_insn_operand (src, mode)) | |
5727 | return "ldd%I1%U1 %M1, %0"; | |
5728 | ||
5729 | return "#"; | |
5730 | } | |
5731 | ||
5732 | else if (GET_CODE (src) == CONST_INT | |
5733 | || GET_CODE (src) == CONST_DOUBLE) | |
5734 | return "#"; | |
5735 | } | |
5736 | ||
5737 | else if (FPR_P (dest_regno)) | |
5738 | { | |
5739 | if (GET_CODE (src) == REG) | |
5740 | { | |
5741 | /* fpr <- some sort of register */ | |
5742 | int src_regno = REGNO (src); | |
5743 | ||
5744 | if (GPR_P (src_regno)) | |
5745 | { | |
5746 | if (((dest_regno - FPR_FIRST) & 1) == 0 | |
5747 | && ((src_regno - GPR_FIRST) & 1) == 0) | |
5748 | return "movgfd %1, %0"; | |
5749 | ||
5750 | return "#"; | |
5751 | } | |
5752 | ||
5753 | else if (FPR_P (src_regno)) | |
5754 | { | |
5755 | if (TARGET_DOUBLE | |
5756 | && ((dest_regno - FPR_FIRST) & 1) == 0 | |
5757 | && ((src_regno - FPR_FIRST) & 1) == 0) | |
5758 | return "fmovd %1, %0"; | |
5759 | ||
5760 | return "#"; | |
5761 | } | |
5762 | } | |
5763 | ||
5764 | else if (GET_CODE (src) == MEM) | |
5765 | { | |
5766 | /* fpr <- memory */ | |
5767 | if (dbl_memory_one_insn_operand (src, mode)) | |
5768 | return "lddf%I1%U1 %M1, %0"; | |
5769 | ||
5770 | return "#"; | |
5771 | } | |
5772 | ||
5773 | else if (ZERO_P (src)) | |
5774 | return "#"; | |
5775 | } | |
5776 | } | |
5777 | ||
5778 | else if (GET_CODE (dest) == MEM) | |
5779 | { | |
5780 | if (GET_CODE (src) == REG) | |
5781 | { | |
5782 | int src_regno = REGNO (src); | |
5783 | ||
5784 | if (GPR_P (src_regno)) | |
5785 | { | |
5786 | if (((src_regno - GPR_FIRST) & 1) == 0 | |
5787 | && dbl_memory_one_insn_operand (dest, mode)) | |
5788 | return "std%I0%U0 %1, %M0"; | |
5789 | ||
5790 | return "#"; | |
5791 | } | |
5792 | ||
5793 | if (FPR_P (src_regno)) | |
5794 | { | |
5795 | if (((src_regno - FPR_FIRST) & 1) == 0 | |
5796 | && dbl_memory_one_insn_operand (dest, mode)) | |
5797 | return "stdf%I0%U0 %1, %M0"; | |
5798 | ||
5799 | return "#"; | |
5800 | } | |
5801 | } | |
5802 | ||
5803 | else if (ZERO_P (src)) | |
5804 | { | |
5805 | if (dbl_memory_one_insn_operand (dest, mode)) | |
5806 | return "std%I0%U0 %., %M0"; | |
5807 | ||
5808 | return "#"; | |
5809 | } | |
5810 | } | |
5811 | ||
5812 | fatal_insn ("Bad output_move_double operand", insn); | |
5813 | return ""; | |
5814 | } | |
5815 | ||
5816 | \f | |
5817 | /* Return a string to output a single word conditional move. | |
5818 | Operand0 -- EQ/NE of ccr register and 0 | |
5819 | Operand1 -- CCR register | |
5820 | Operand2 -- destination | |
5821 | Operand3 -- source */ | |
5822 | ||
5823 | const char * | |
5824 | output_condmove_single (operands, insn) | |
5825 | rtx operands[]; | |
5826 | rtx insn; | |
5827 | { | |
5828 | rtx dest = operands[2]; | |
5829 | rtx src = operands[3]; | |
5830 | ||
5831 | if (GET_CODE (dest) == REG) | |
5832 | { | |
5833 | int dest_regno = REGNO (dest); | |
5834 | enum machine_mode mode = GET_MODE (dest); | |
5835 | ||
5836 | if (GPR_P (dest_regno)) | |
5837 | { | |
5838 | if (GET_CODE (src) == REG) | |
5839 | { | |
5840 | /* gpr <- some sort of register */ | |
5841 | int src_regno = REGNO (src); | |
5842 | ||
5843 | if (GPR_P (src_regno)) | |
5844 | return "cmov %z3, %2, %1, %e0"; | |
5845 | ||
5846 | else if (FPR_P (src_regno)) | |
5847 | return "cmovfg %3, %2, %1, %e0"; | |
5848 | } | |
5849 | ||
5850 | else if (GET_CODE (src) == MEM) | |
5851 | { | |
5852 | /* gpr <- memory */ | |
5853 | switch (mode) | |
5854 | { | |
5855 | default: | |
5856 | break; | |
5857 | ||
5858 | case QImode: | |
5859 | return "cldsb%I3%U3 %M3, %2, %1, %e0"; | |
5860 | ||
5861 | case HImode: | |
5862 | return "cldsh%I3%U3 %M3, %2, %1, %e0"; | |
5863 | ||
5864 | case SImode: | |
5865 | case SFmode: | |
5866 | return "cld%I3%U3 %M3, %2, %1, %e0"; | |
5867 | } | |
5868 | } | |
5869 | ||
5870 | else if (ZERO_P (src)) | |
5871 | return "cmov %., %2, %1, %e0"; | |
5872 | } | |
5873 | ||
5874 | else if (FPR_P (dest_regno)) | |
5875 | { | |
5876 | if (GET_CODE (src) == REG) | |
5877 | { | |
5878 | /* fpr <- some sort of register */ | |
5879 | int src_regno = REGNO (src); | |
5880 | ||
5881 | if (GPR_P (src_regno)) | |
5882 | return "cmovgf %3, %2, %1, %e0"; | |
5883 | ||
5884 | else if (FPR_P (src_regno)) | |
5885 | { | |
5886 | if (TARGET_HARD_FLOAT) | |
5887 | return "cfmovs %3,%2,%1,%e0"; | |
5888 | else | |
5889 | return "cmor %3, %3, %2, %1, %e0"; | |
5890 | } | |
5891 | } | |
5892 | ||
5893 | else if (GET_CODE (src) == MEM) | |
5894 | { | |
5895 | /* fpr <- memory */ | |
5896 | if (mode == SImode || mode == SFmode) | |
5897 | return "cldf%I3%U3 %M3, %2, %1, %e0"; | |
5898 | } | |
5899 | ||
5900 | else if (ZERO_P (src)) | |
5901 | return "cmovgf %., %2, %1, %e0"; | |
5902 | } | |
5903 | } | |
5904 | ||
5905 | else if (GET_CODE (dest) == MEM) | |
5906 | { | |
5907 | if (GET_CODE (src) == REG) | |
5908 | { | |
5909 | int src_regno = REGNO (src); | |
5910 | enum machine_mode mode = GET_MODE (dest); | |
5911 | ||
5912 | if (GPR_P (src_regno)) | |
5913 | { | |
5914 | switch (mode) | |
5915 | { | |
5916 | default: | |
5917 | break; | |
5918 | ||
5919 | case QImode: | |
5920 | return "cstb%I2%U2 %3, %M2, %1, %e0"; | |
5921 | ||
5922 | case HImode: | |
5923 | return "csth%I2%U2 %3, %M2, %1, %e0"; | |
5924 | ||
5925 | case SImode: | |
5926 | case SFmode: | |
5927 | return "cst%I2%U2 %3, %M2, %1, %e0"; | |
5928 | } | |
5929 | } | |
5930 | ||
5931 | else if (FPR_P (src_regno) && (mode == SImode || mode == SFmode)) | |
5932 | return "cstf%I2%U2 %3, %M2, %1, %e0"; | |
5933 | } | |
5934 | ||
5935 | else if (ZERO_P (src)) | |
5936 | { | |
5937 | enum machine_mode mode = GET_MODE (dest); | |
5938 | switch (mode) | |
5939 | { | |
5940 | default: | |
5941 | break; | |
5942 | ||
5943 | case QImode: | |
5944 | return "cstb%I2%U2 %., %M2, %1, %e0"; | |
5945 | ||
5946 | case HImode: | |
5947 | return "csth%I2%U2 %., %M2, %1, %e0"; | |
5948 | ||
5949 | case SImode: | |
5950 | case SFmode: | |
5951 | return "cst%I2%U2 %., %M2, %1, %e0"; | |
5952 | } | |
5953 | } | |
5954 | } | |
5955 | ||
5956 | fatal_insn ("Bad output_condmove_single operand", insn); | |
5957 | return ""; | |
5958 | } | |
5959 | ||
5960 | \f | |
5961 | /* Emit the appropriate code to do a comparison, returning the register the | |
5962 | comparison was done it. */ | |
5963 | ||
5964 | static rtx | |
5965 | frv_emit_comparison (test, op0, op1) | |
5966 | enum rtx_code test; | |
5967 | rtx op0; | |
5968 | rtx op1; | |
5969 | { | |
5970 | enum machine_mode cc_mode; | |
5971 | rtx cc_reg; | |
5972 | ||
5973 | /* Floating point doesn't have comparison against a constant */ | |
5974 | if (GET_MODE (op0) == CC_FPmode && GET_CODE (op1) != REG) | |
5975 | op1 = force_reg (GET_MODE (op0), op1); | |
5976 | ||
5977 | /* Possibly disable using anything but a fixed register in order to work | |
5978 | around cse moving comparisons past function calls. */ | |
5979 | cc_mode = SELECT_CC_MODE (test, op0, op1); | |
5980 | cc_reg = ((TARGET_ALLOC_CC) | |
5981 | ? gen_reg_rtx (cc_mode) | |
5982 | : gen_rtx_REG (cc_mode, | |
5983 | (cc_mode == CC_FPmode) ? FCC_FIRST : ICC_FIRST)); | |
5984 | ||
5985 | emit_insn (gen_rtx_SET (VOIDmode, cc_reg, | |
5986 | gen_rtx_COMPARE (cc_mode, op0, op1))); | |
5987 | ||
5988 | return cc_reg; | |
5989 | } | |
5990 | ||
5991 | \f | |
5992 | /* Emit code for a conditional branch. The comparison operands were previously | |
5993 | stored in frv_compare_op0 and frv_compare_op1. | |
5994 | ||
5995 | XXX: I originally wanted to add a clobber of a CCR register to use in | |
5996 | conditional execution, but that confuses the rest of the compiler. */ | |
5997 | ||
5998 | int | |
5999 | frv_emit_cond_branch (test, label) | |
6000 | enum rtx_code test; | |
6001 | rtx label; | |
6002 | { | |
6003 | rtx test_rtx; | |
6004 | rtx label_ref; | |
6005 | rtx if_else; | |
6006 | rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1); | |
6007 | enum machine_mode cc_mode = GET_MODE (cc_reg); | |
6008 | ||
6009 | /* Branches generate: | |
6010 | (set (pc) | |
6011 | (if_then_else (<test>, <cc_reg>, (const_int 0)) | |
6012 | (label_ref <branch_label>) | |
6013 | (pc))) */ | |
6014 | label_ref = gen_rtx_LABEL_REF (VOIDmode, label); | |
6015 | test_rtx = gen_rtx (test, cc_mode, cc_reg, const0_rtx); | |
6016 | if_else = gen_rtx_IF_THEN_ELSE (cc_mode, test_rtx, label_ref, pc_rtx); | |
6017 | emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, if_else)); | |
6018 | return TRUE; | |
6019 | } | |
6020 | ||
6021 | \f | |
6022 | /* Emit code to set a gpr to 1/0 based on a comparison. The comparison | |
6023 | operands were previously stored in frv_compare_op0 and frv_compare_op1. */ | |
6024 | ||
6025 | int | |
6026 | frv_emit_scc (test, target) | |
6027 | enum rtx_code test; | |
6028 | rtx target; | |
6029 | { | |
6030 | rtx set; | |
6031 | rtx test_rtx; | |
6032 | rtx clobber; | |
6033 | rtx cr_reg; | |
6034 | rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1); | |
6035 | ||
6036 | /* SCC instructions generate: | |
6037 | (parallel [(set <target> (<test>, <cc_reg>, (const_int 0)) | |
6038 | (clobber (<ccr_reg>))]) */ | |
6039 | test_rtx = gen_rtx_fmt_ee (test, SImode, cc_reg, const0_rtx); | |
6040 | set = gen_rtx_SET (VOIDmode, target, test_rtx); | |
6041 | ||
6042 | cr_reg = ((TARGET_ALLOC_CC) | |
6043 | ? gen_reg_rtx (CC_CCRmode) | |
6044 | : gen_rtx_REG (CC_CCRmode, | |
6045 | ((GET_MODE (cc_reg) == CC_FPmode) | |
6046 | ? FCR_FIRST | |
6047 | : ICR_FIRST))); | |
6048 | ||
6049 | clobber = gen_rtx_CLOBBER (VOIDmode, cr_reg); | |
6050 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber))); | |
6051 | return TRUE; | |
6052 | } | |
6053 | ||
6054 | \f | |
6055 | /* Split a SCC instruction into component parts, returning a SEQUENCE to hold | |
6056 | the seperate insns. */ | |
6057 | ||
6058 | rtx | |
6059 | frv_split_scc (dest, test, cc_reg, cr_reg, value) | |
6060 | rtx dest; | |
6061 | rtx test; | |
6062 | rtx cc_reg; | |
6063 | rtx cr_reg; | |
6064 | HOST_WIDE_INT value; | |
6065 | { | |
6066 | rtx ret; | |
6067 | ||
6068 | start_sequence (); | |
6069 | ||
6070 | /* Set the appropriate CCR bit. */ | |
6071 | emit_insn (gen_rtx_SET (VOIDmode, | |
6072 | cr_reg, | |
6073 | gen_rtx_fmt_ee (GET_CODE (test), | |
6074 | GET_MODE (cr_reg), | |
6075 | cc_reg, | |
6076 | const0_rtx))); | |
6077 | ||
6078 | /* Move the value into the destination. */ | |
6079 | emit_move_insn (dest, GEN_INT (value)); | |
6080 | ||
6081 | /* Move 0 into the destination if the test failed */ | |
6082 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6083 | gen_rtx_EQ (GET_MODE (cr_reg), | |
6084 | cr_reg, | |
6085 | const0_rtx), | |
6086 | gen_rtx_SET (VOIDmode, dest, const0_rtx))); | |
6087 | ||
6088 | /* Finish up, return sequence. */ | |
6089 | ret = get_insns (); | |
6090 | end_sequence (); | |
6091 | return ret; | |
6092 | } | |
6093 | ||
6094 | \f | |
6095 | /* Emit the code for a conditional move, return TRUE if we could do the | |
6096 | move. */ | |
6097 | ||
6098 | int | |
6099 | frv_emit_cond_move (dest, test_rtx, src1, src2) | |
6100 | rtx dest; | |
6101 | rtx test_rtx; | |
6102 | rtx src1; | |
6103 | rtx src2; | |
6104 | { | |
6105 | rtx set; | |
6106 | rtx clobber_cc; | |
6107 | rtx test2; | |
6108 | rtx cr_reg; | |
6109 | rtx if_rtx; | |
6110 | enum rtx_code test = GET_CODE (test_rtx); | |
6111 | rtx cc_reg = frv_emit_comparison (test, frv_compare_op0, frv_compare_op1); | |
6112 | enum machine_mode cc_mode = GET_MODE (cc_reg); | |
6113 | ||
6114 | /* Conditional move instructions generate: | |
6115 | (parallel [(set <target> | |
6116 | (if_then_else (<test> <cc_reg> (const_int 0)) | |
6117 | <src1> | |
6118 | <src2>)) | |
6119 | (clobber (<ccr_reg>))]) */ | |
6120 | ||
6121 | /* Handle various cases of conditional move involving two constants. */ | |
6122 | if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT) | |
6123 | { | |
6124 | HOST_WIDE_INT value1 = INTVAL (src1); | |
6125 | HOST_WIDE_INT value2 = INTVAL (src2); | |
6126 | ||
6127 | /* having 0 as one of the constants can be done by loading the other | |
6128 | constant, and optionally moving in gr0. */ | |
6129 | if (value1 == 0 || value2 == 0) | |
6130 | ; | |
6131 | ||
6132 | /* If the first value is within an addi range and also the difference | |
6133 | between the two fits in an addi's range, load up the difference, then | |
6134 | conditionally move in 0, and then unconditionally add the first | |
6135 | value. */ | |
6136 | else if (IN_RANGE_P (value1, -2048, 2047) | |
6137 | && IN_RANGE_P (value2 - value1, -2048, 2047)) | |
6138 | ; | |
6139 | ||
6140 | /* If neither condition holds, just force the constant into a | |
6141 | register. */ | |
6142 | else | |
6143 | { | |
6144 | src1 = force_reg (GET_MODE (dest), src1); | |
6145 | src2 = force_reg (GET_MODE (dest), src2); | |
6146 | } | |
6147 | } | |
6148 | ||
6149 | /* If one value is a register, insure the other value is either 0 or a | |
6150 | register. */ | |
6151 | else | |
6152 | { | |
6153 | if (GET_CODE (src1) == CONST_INT && INTVAL (src1) != 0) | |
6154 | src1 = force_reg (GET_MODE (dest), src1); | |
6155 | ||
6156 | if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0) | |
6157 | src2 = force_reg (GET_MODE (dest), src2); | |
6158 | } | |
6159 | ||
6160 | test2 = gen_rtx_fmt_ee (test, cc_mode, cc_reg, const0_rtx); | |
6161 | if_rtx = gen_rtx_IF_THEN_ELSE (GET_MODE (dest), test2, src1, src2); | |
6162 | ||
6163 | set = gen_rtx_SET (VOIDmode, dest, if_rtx); | |
6164 | ||
6165 | cr_reg = ((TARGET_ALLOC_CC) | |
6166 | ? gen_reg_rtx (CC_CCRmode) | |
6167 | : gen_rtx_REG (CC_CCRmode, | |
6168 | (cc_mode == CC_FPmode) ? FCR_FIRST : ICR_FIRST)); | |
6169 | ||
6170 | clobber_cc = gen_rtx_CLOBBER (VOIDmode, cr_reg); | |
6171 | emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber_cc))); | |
6172 | return TRUE; | |
6173 | } | |
6174 | ||
6175 | \f | |
6176 | /* Split a conditonal move into constituent parts, returning a SEQUENCE | |
6177 | containing all of the insns. */ | |
6178 | ||
6179 | rtx | |
6180 | frv_split_cond_move (operands) | |
6181 | rtx operands[]; | |
6182 | { | |
6183 | rtx dest = operands[0]; | |
6184 | rtx test = operands[1]; | |
6185 | rtx cc_reg = operands[2]; | |
6186 | rtx src1 = operands[3]; | |
6187 | rtx src2 = operands[4]; | |
6188 | rtx cr_reg = operands[5]; | |
6189 | rtx ret; | |
6190 | enum machine_mode cr_mode = GET_MODE (cr_reg); | |
6191 | ||
6192 | start_sequence (); | |
6193 | ||
6194 | /* Set the appropriate CCR bit. */ | |
6195 | emit_insn (gen_rtx_SET (VOIDmode, | |
6196 | cr_reg, | |
6197 | gen_rtx_fmt_ee (GET_CODE (test), | |
6198 | GET_MODE (cr_reg), | |
6199 | cc_reg, | |
6200 | const0_rtx))); | |
6201 | ||
6202 | /* Handle various cases of conditional move involving two constants. */ | |
6203 | if (GET_CODE (src1) == CONST_INT && GET_CODE (src2) == CONST_INT) | |
6204 | { | |
6205 | HOST_WIDE_INT value1 = INTVAL (src1); | |
6206 | HOST_WIDE_INT value2 = INTVAL (src2); | |
6207 | ||
6208 | /* having 0 as one of the constants can be done by loading the other | |
6209 | constant, and optionally moving in gr0. */ | |
6210 | if (value1 == 0) | |
6211 | { | |
6212 | emit_move_insn (dest, src2); | |
6213 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6214 | gen_rtx_NE (cr_mode, cr_reg, | |
6215 | const0_rtx), | |
6216 | gen_rtx_SET (VOIDmode, dest, src1))); | |
6217 | } | |
6218 | ||
6219 | else if (value2 == 0) | |
6220 | { | |
6221 | emit_move_insn (dest, src1); | |
6222 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6223 | gen_rtx_EQ (cr_mode, cr_reg, | |
6224 | const0_rtx), | |
6225 | gen_rtx_SET (VOIDmode, dest, src2))); | |
6226 | } | |
6227 | ||
6228 | /* If the first value is within an addi range and also the difference | |
6229 | between the two fits in an addi's range, load up the difference, then | |
6230 | conditionally move in 0, and then unconditionally add the first | |
6231 | value. */ | |
6232 | else if (IN_RANGE_P (value1, -2048, 2047) | |
6233 | && IN_RANGE_P (value2 - value1, -2048, 2047)) | |
6234 | { | |
6235 | rtx dest_si = ((GET_MODE (dest) == SImode) | |
6236 | ? dest | |
6237 | : gen_rtx_SUBREG (SImode, dest, 0)); | |
6238 | ||
6239 | emit_move_insn (dest_si, GEN_INT (value2 - value1)); | |
6240 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6241 | gen_rtx_NE (cr_mode, cr_reg, | |
6242 | const0_rtx), | |
6243 | gen_rtx_SET (VOIDmode, dest_si, | |
6244 | const0_rtx))); | |
6245 | emit_insn (gen_addsi3 (dest_si, dest_si, src1)); | |
6246 | } | |
6247 | ||
6248 | else | |
6249 | abort (); | |
6250 | } | |
6251 | else | |
6252 | { | |
6253 | /* Emit the conditional move for the test being true if needed. */ | |
6254 | if (! rtx_equal_p (dest, src1)) | |
6255 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6256 | gen_rtx_NE (cr_mode, cr_reg, const0_rtx), | |
6257 | gen_rtx_SET (VOIDmode, dest, src1))); | |
6258 | ||
6259 | /* Emit the conditional move for the test being false if needed. */ | |
6260 | if (! rtx_equal_p (dest, src2)) | |
6261 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6262 | gen_rtx_EQ (cr_mode, cr_reg, const0_rtx), | |
6263 | gen_rtx_SET (VOIDmode, dest, src2))); | |
6264 | } | |
6265 | ||
6266 | /* Finish up, return sequence. */ | |
6267 | ret = get_insns (); | |
6268 | end_sequence (); | |
6269 | return ret; | |
6270 | } | |
6271 | ||
6272 | \f | |
6273 | /* Split (set DEST SOURCE), where DEST is a double register and SOURCE is a | |
6274 | memory location that is not known to be dword-aligned. */ | |
6275 | void | |
6276 | frv_split_double_load (dest, source) | |
6277 | rtx dest; | |
6278 | rtx source; | |
6279 | { | |
6280 | int regno = REGNO (dest); | |
6281 | rtx dest1 = gen_highpart (SImode, dest); | |
6282 | rtx dest2 = gen_lowpart (SImode, dest); | |
6283 | rtx address = XEXP (source, 0); | |
6284 | ||
6285 | /* If the address is pre-modified, load the lower-numbered register | |
6286 | first, then load the other register using an integer offset from | |
6287 | the modified base register. This order should always be safe, | |
6288 | since the pre-modification cannot affect the same registers as the | |
6289 | load does. | |
6290 | ||
6291 | The situation for other loads is more complicated. Loading one | |
6292 | of the registers could affect the value of ADDRESS, so we must | |
6293 | be careful which order we do them in. */ | |
6294 | if (GET_CODE (address) == PRE_MODIFY | |
6295 | || ! refers_to_regno_p (regno, regno + 1, address, NULL)) | |
6296 | { | |
6297 | /* It is safe to load the lower-numbered register first. */ | |
6298 | emit_move_insn (dest1, change_address (source, SImode, NULL)); | |
6299 | emit_move_insn (dest2, frv_index_memory (source, SImode, 1)); | |
6300 | } | |
6301 | else | |
6302 | { | |
6303 | /* ADDRESS is not pre-modified and the address depends on the | |
6304 | lower-numbered register. Load the higher-numbered register | |
6305 | first. */ | |
6306 | emit_move_insn (dest2, frv_index_memory (source, SImode, 1)); | |
6307 | emit_move_insn (dest1, change_address (source, SImode, NULL)); | |
6308 | } | |
6309 | } | |
6310 | ||
6311 | /* Split (set DEST SOURCE), where DEST refers to a dword memory location | |
6312 | and SOURCE is either a double register or the constant zero. */ | |
6313 | void | |
6314 | frv_split_double_store (dest, source) | |
6315 | rtx dest; | |
6316 | rtx source; | |
6317 | { | |
6318 | rtx dest1 = change_address (dest, SImode, NULL); | |
6319 | rtx dest2 = frv_index_memory (dest, SImode, 1); | |
6320 | if (ZERO_P (source)) | |
6321 | { | |
6322 | emit_move_insn (dest1, CONST0_RTX (SImode)); | |
6323 | emit_move_insn (dest2, CONST0_RTX (SImode)); | |
6324 | } | |
6325 | else | |
6326 | { | |
6327 | emit_move_insn (dest1, gen_highpart (SImode, source)); | |
6328 | emit_move_insn (dest2, gen_lowpart (SImode, source)); | |
6329 | } | |
6330 | } | |
6331 | ||
6332 | \f | |
6333 | /* Split a min/max operation returning a SEQUENCE containing all of the | |
6334 | insns. */ | |
6335 | ||
6336 | rtx | |
6337 | frv_split_minmax (operands) | |
6338 | rtx operands[]; | |
6339 | { | |
6340 | rtx dest = operands[0]; | |
6341 | rtx minmax = operands[1]; | |
6342 | rtx src1 = operands[2]; | |
6343 | rtx src2 = operands[3]; | |
6344 | rtx cc_reg = operands[4]; | |
6345 | rtx cr_reg = operands[5]; | |
6346 | rtx ret; | |
6347 | enum rtx_code test_code; | |
6348 | enum machine_mode cr_mode = GET_MODE (cr_reg); | |
6349 | ||
6350 | start_sequence (); | |
6351 | ||
6352 | /* Figure out which test to use */ | |
6353 | switch (GET_CODE (minmax)) | |
6354 | { | |
6355 | default: | |
6356 | abort (); | |
6357 | ||
6358 | case SMIN: test_code = LT; break; | |
6359 | case SMAX: test_code = GT; break; | |
6360 | case UMIN: test_code = LTU; break; | |
6361 | case UMAX: test_code = GTU; break; | |
6362 | } | |
6363 | ||
6364 | /* Issue the compare instruction. */ | |
6365 | emit_insn (gen_rtx_SET (VOIDmode, | |
6366 | cc_reg, | |
6367 | gen_rtx_COMPARE (GET_MODE (cc_reg), | |
6368 | src1, src2))); | |
6369 | ||
6370 | /* Set the appropriate CCR bit. */ | |
6371 | emit_insn (gen_rtx_SET (VOIDmode, | |
6372 | cr_reg, | |
6373 | gen_rtx_fmt_ee (test_code, | |
6374 | GET_MODE (cr_reg), | |
6375 | cc_reg, | |
6376 | const0_rtx))); | |
6377 | ||
9cd10576 | 6378 | /* If are taking the min/max of a nonzero constant, load that first, and |
36a05131 BS |
6379 | then do a conditional move of the other value. */ |
6380 | if (GET_CODE (src2) == CONST_INT && INTVAL (src2) != 0) | |
6381 | { | |
6382 | if (rtx_equal_p (dest, src1)) | |
6383 | abort (); | |
6384 | ||
6385 | emit_move_insn (dest, src2); | |
6386 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6387 | gen_rtx_NE (cr_mode, cr_reg, const0_rtx), | |
6388 | gen_rtx_SET (VOIDmode, dest, src1))); | |
6389 | } | |
6390 | ||
6391 | /* Otherwise, do each half of the move. */ | |
6392 | else | |
6393 | { | |
6394 | /* Emit the conditional move for the test being true if needed. */ | |
6395 | if (! rtx_equal_p (dest, src1)) | |
6396 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6397 | gen_rtx_NE (cr_mode, cr_reg, const0_rtx), | |
6398 | gen_rtx_SET (VOIDmode, dest, src1))); | |
6399 | ||
6400 | /* Emit the conditional move for the test being false if needed. */ | |
6401 | if (! rtx_equal_p (dest, src2)) | |
6402 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6403 | gen_rtx_EQ (cr_mode, cr_reg, const0_rtx), | |
6404 | gen_rtx_SET (VOIDmode, dest, src2))); | |
6405 | } | |
6406 | ||
6407 | /* Finish up, return sequence. */ | |
6408 | ret = get_insns (); | |
6409 | end_sequence (); | |
6410 | return ret; | |
6411 | } | |
6412 | ||
6413 | \f | |
6414 | /* Split an integer abs operation returning a SEQUENCE containing all of the | |
6415 | insns. */ | |
6416 | ||
6417 | rtx | |
6418 | frv_split_abs (operands) | |
6419 | rtx operands[]; | |
6420 | { | |
6421 | rtx dest = operands[0]; | |
6422 | rtx src = operands[1]; | |
6423 | rtx cc_reg = operands[2]; | |
6424 | rtx cr_reg = operands[3]; | |
6425 | rtx ret; | |
6426 | ||
6427 | start_sequence (); | |
6428 | ||
6429 | /* Issue the compare < 0 instruction. */ | |
6430 | emit_insn (gen_rtx_SET (VOIDmode, | |
6431 | cc_reg, | |
6432 | gen_rtx_COMPARE (CCmode, src, const0_rtx))); | |
6433 | ||
6434 | /* Set the appropriate CCR bit. */ | |
6435 | emit_insn (gen_rtx_SET (VOIDmode, | |
6436 | cr_reg, | |
6437 | gen_rtx_fmt_ee (LT, CC_CCRmode, cc_reg, const0_rtx))); | |
6438 | ||
6439 | /* Emit the conditional negate if the value is negative */ | |
6440 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6441 | gen_rtx_NE (CC_CCRmode, cr_reg, const0_rtx), | |
6442 | gen_negsi2 (dest, src))); | |
6443 | ||
6444 | /* Emit the conditional move for the test being false if needed. */ | |
6445 | if (! rtx_equal_p (dest, src)) | |
6446 | emit_insn (gen_rtx_COND_EXEC (VOIDmode, | |
6447 | gen_rtx_EQ (CC_CCRmode, cr_reg, const0_rtx), | |
6448 | gen_rtx_SET (VOIDmode, dest, src))); | |
6449 | ||
6450 | /* Finish up, return sequence. */ | |
6451 | ret = get_insns (); | |
6452 | end_sequence (); | |
6453 | return ret; | |
6454 | } | |
6455 | ||
6456 | \f | |
6457 | /* An internal function called by for_each_rtx to clear in a hard_reg set each | |
6458 | register used in an insn. */ | |
6459 | ||
6460 | static int | |
6461 | frv_clear_registers_used (ptr, data) | |
6462 | rtx *ptr; | |
6463 | void *data; | |
6464 | { | |
6465 | if (GET_CODE (*ptr) == REG) | |
6466 | { | |
6467 | int regno = REGNO (*ptr); | |
6468 | HARD_REG_SET *p_regs = (HARD_REG_SET *)data; | |
6469 | ||
6470 | if (regno < FIRST_PSEUDO_REGISTER) | |
6471 | { | |
6472 | int reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (*ptr)); | |
6473 | ||
6474 | while (regno < reg_max) | |
6475 | { | |
6476 | CLEAR_HARD_REG_BIT (*p_regs, regno); | |
6477 | regno++; | |
6478 | } | |
6479 | } | |
6480 | } | |
6481 | ||
6482 | return 0; | |
6483 | } | |
6484 | ||
6485 | \f | |
6486 | /* Initialize the extra fields provided by IFCVT_EXTRA_FIELDS. */ | |
6487 | ||
6488 | /* On the FR-V, we don't have any extra fields per se, but it is useful hook to | |
6489 | initialize the static storage. */ | |
6490 | void | |
6491 | frv_ifcvt_init_extra_fields (ce_info) | |
6492 | ce_if_block_t *ce_info ATTRIBUTE_UNUSED; | |
6493 | { | |
6494 | frv_ifcvt.added_insns_list = NULL_RTX; | |
6495 | frv_ifcvt.cur_scratch_regs = 0; | |
6496 | frv_ifcvt.num_nested_cond_exec = 0; | |
6497 | frv_ifcvt.cr_reg = NULL_RTX; | |
6498 | frv_ifcvt.nested_cc_reg = NULL_RTX; | |
6499 | frv_ifcvt.extra_int_cr = NULL_RTX; | |
6500 | frv_ifcvt.extra_fp_cr = NULL_RTX; | |
6501 | frv_ifcvt.last_nested_if_cr = NULL_RTX; | |
6502 | } | |
6503 | ||
6504 | \f | |
6505 | /* Internal function to add a potenial insn to the list of insns to be inserted | |
6506 | if the conditional execution conversion is successful. */ | |
6507 | ||
6508 | static void | |
6509 | frv_ifcvt_add_insn (pattern, insn, before_p) | |
6510 | rtx pattern; | |
6511 | rtx insn; | |
6512 | int before_p; | |
6513 | { | |
6514 | rtx link = alloc_EXPR_LIST (VOIDmode, pattern, insn); | |
6515 | ||
6516 | link->jump = before_p; /* mark to add this before or after insn */ | |
6517 | frv_ifcvt.added_insns_list = alloc_EXPR_LIST (VOIDmode, link, | |
6518 | frv_ifcvt.added_insns_list); | |
6519 | ||
6520 | if (TARGET_DEBUG_COND_EXEC) | |
6521 | { | |
6522 | fprintf (stderr, | |
6523 | "\n:::::::::: frv_ifcvt_add_insn: add the following %s insn %d:\n", | |
6524 | (before_p) ? "before" : "after", | |
6525 | (int)INSN_UID (insn)); | |
6526 | ||
6527 | debug_rtx (pattern); | |
6528 | } | |
6529 | } | |
6530 | ||
6531 | \f | |
6532 | /* A C expression to modify the code described by the conditional if | |
6533 | information CE_INFO, possibly updating the tests in TRUE_EXPR, and | |
6534 | FALSE_EXPR for converting if-then and if-then-else code to conditional | |
6535 | instructions. Set either TRUE_EXPR or FALSE_EXPR to a null pointer if the | |
6536 | tests cannot be converted. */ | |
6537 | ||
6538 | void | |
6539 | frv_ifcvt_modify_tests (ce_info, p_true, p_false) | |
6540 | ce_if_block_t *ce_info; | |
6541 | rtx *p_true; | |
6542 | rtx *p_false; | |
6543 | { | |
6544 | basic_block test_bb = ce_info->test_bb; /* test basic block */ | |
6545 | basic_block then_bb = ce_info->then_bb; /* THEN */ | |
6546 | basic_block else_bb = ce_info->else_bb; /* ELSE or NULL */ | |
6547 | basic_block join_bb = ce_info->join_bb; /* join block or NULL */ | |
6548 | rtx true_expr = *p_true; | |
6549 | rtx cr; | |
6550 | rtx cc; | |
6551 | rtx nested_cc; | |
6552 | enum machine_mode mode = GET_MODE (true_expr); | |
6553 | int j; | |
6554 | basic_block *bb; | |
6555 | int num_bb; | |
6556 | frv_tmp_reg_t *tmp_reg = &frv_ifcvt.tmp_reg; | |
6557 | rtx check_insn; | |
6558 | rtx sub_cond_exec_reg; | |
6559 | enum rtx_code code; | |
6560 | enum rtx_code code_true; | |
6561 | enum rtx_code code_false; | |
6562 | enum reg_class cc_class; | |
6563 | enum reg_class cr_class; | |
6564 | int cc_first; | |
6565 | int cc_last; | |
6566 | ||
6567 | /* Make sure we are only dealing with hard registers. Also honor the | |
6568 | -mno-cond-exec switch, and -mno-nested-cond-exec switches if | |
6569 | applicable. */ | |
6570 | if (!reload_completed || TARGET_NO_COND_EXEC | |
6571 | || (TARGET_NO_NESTED_CE && ce_info->pass > 1)) | |
6572 | goto fail; | |
6573 | ||
6574 | /* Figure out which registers we can allocate for our own purposes. Only | |
6575 | consider registers that are not preserved across function calls and are | |
6576 | not fixed. However, allow the ICC/ICR temporary registers to be allocated | |
6577 | if we did not need to use them in reloading other registers. */ | |
fad205ff | 6578 | memset (&tmp_reg->regs, 0, sizeof (tmp_reg->regs)); |
36a05131 BS |
6579 | COPY_HARD_REG_SET (tmp_reg->regs, call_used_reg_set); |
6580 | AND_COMPL_HARD_REG_SET (tmp_reg->regs, fixed_reg_set); | |
6581 | SET_HARD_REG_BIT (tmp_reg->regs, ICC_TEMP); | |
6582 | SET_HARD_REG_BIT (tmp_reg->regs, ICR_TEMP); | |
6583 | ||
6584 | /* If this is a nested IF, we need to discover whether the CC registers that | |
6585 | are set/used inside of the block are used anywhere else. If not, we can | |
6586 | change them to be the CC register that is paired with the CR register that | |
6587 | controls the outermost IF block. */ | |
6588 | if (ce_info->pass > 1) | |
6589 | { | |
6590 | CLEAR_HARD_REG_SET (frv_ifcvt.nested_cc_ok_rewrite); | |
6591 | for (j = CC_FIRST; j <= CC_LAST; j++) | |
6592 | if (TEST_HARD_REG_BIT (tmp_reg->regs, j)) | |
6593 | { | |
6594 | if (REGNO_REG_SET_P (then_bb->global_live_at_start, j)) | |
6595 | continue; | |
6596 | ||
6597 | if (else_bb && REGNO_REG_SET_P (else_bb->global_live_at_start, j)) | |
6598 | continue; | |
6599 | ||
6600 | if (join_bb && REGNO_REG_SET_P (join_bb->global_live_at_start, j)) | |
6601 | continue; | |
6602 | ||
6603 | SET_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j); | |
6604 | } | |
6605 | } | |
6606 | ||
6607 | for (j = 0; j < frv_ifcvt.cur_scratch_regs; j++) | |
6608 | frv_ifcvt.scratch_regs[j] = NULL_RTX; | |
6609 | ||
6610 | frv_ifcvt.added_insns_list = NULL_RTX; | |
6611 | frv_ifcvt.cur_scratch_regs = 0; | |
6612 | ||
6613 | bb = (basic_block *) alloca ((2 + ce_info->num_multiple_test_blocks) | |
6614 | * sizeof (basic_block)); | |
6615 | ||
6616 | if (join_bb) | |
6617 | { | |
6618 | int regno; | |
6619 | ||
6620 | /* Remove anything live at the beginning of the join block from being | |
6621 | available for allocation. */ | |
6622 | EXECUTE_IF_SET_IN_REG_SET (join_bb->global_live_at_start, 0, regno, | |
6623 | { | |
6624 | if (regno < FIRST_PSEUDO_REGISTER) | |
6625 | CLEAR_HARD_REG_BIT (tmp_reg->regs, regno); | |
6626 | }); | |
6627 | } | |
6628 | ||
6629 | /* Add in all of the blocks in multiple &&/|| blocks to be scanned. */ | |
6630 | num_bb = 0; | |
6631 | if (ce_info->num_multiple_test_blocks) | |
6632 | { | |
6633 | basic_block multiple_test_bb = ce_info->last_test_bb; | |
6634 | ||
6635 | while (multiple_test_bb != test_bb) | |
6636 | { | |
6637 | bb[num_bb++] = multiple_test_bb; | |
6638 | multiple_test_bb = multiple_test_bb->pred->src; | |
6639 | } | |
6640 | } | |
6641 | ||
6642 | /* Add in the THEN and ELSE blocks to be scanned. */ | |
6643 | bb[num_bb++] = then_bb; | |
6644 | if (else_bb) | |
6645 | bb[num_bb++] = else_bb; | |
6646 | ||
6647 | sub_cond_exec_reg = NULL_RTX; | |
6648 | frv_ifcvt.num_nested_cond_exec = 0; | |
6649 | ||
6650 | /* Scan all of the blocks for registers that must not be allocated. */ | |
6651 | for (j = 0; j < num_bb; j++) | |
6652 | { | |
6653 | rtx last_insn = bb[j]->end; | |
6654 | rtx insn = bb[j]->head; | |
6655 | int regno; | |
6656 | ||
6657 | if (rtl_dump_file) | |
6658 | fprintf (rtl_dump_file, "Scanning %s block %d, start %d, end %d\n", | |
6659 | (bb[j] == else_bb) ? "else" : ((bb[j] == then_bb) ? "then" : "test"), | |
6660 | (int) bb[j]->index, | |
6661 | (int) INSN_UID (bb[j]->head), | |
6662 | (int) INSN_UID (bb[j]->end)); | |
6663 | ||
6664 | /* Anything live at the beginning of the block is obviously unavailable | |
6665 | for allocation. */ | |
6666 | EXECUTE_IF_SET_IN_REG_SET (bb[j]->global_live_at_start, 0, regno, | |
6667 | { | |
6668 | if (regno < FIRST_PSEUDO_REGISTER) | |
6669 | CLEAR_HARD_REG_BIT (tmp_reg->regs, regno); | |
6670 | }); | |
6671 | ||
6672 | /* loop through the insns in the block. */ | |
6673 | for (;;) | |
6674 | { | |
6675 | /* Mark any new registers that are created as being unavailable for | |
6676 | allocation. Also see if the CC register used in nested IFs can be | |
6677 | reallocated. */ | |
6678 | if (INSN_P (insn)) | |
6679 | { | |
6680 | rtx pattern; | |
6681 | rtx set; | |
6682 | int skip_nested_if = FALSE; | |
6683 | ||
6684 | for_each_rtx (&PATTERN (insn), frv_clear_registers_used, | |
6685 | (void *)&tmp_reg->regs); | |
6686 | ||
6687 | pattern = PATTERN (insn); | |
6688 | if (GET_CODE (pattern) == COND_EXEC) | |
6689 | { | |
6690 | rtx reg = XEXP (COND_EXEC_TEST (pattern), 0); | |
6691 | ||
6692 | if (reg != sub_cond_exec_reg) | |
6693 | { | |
6694 | sub_cond_exec_reg = reg; | |
6695 | frv_ifcvt.num_nested_cond_exec++; | |
6696 | } | |
6697 | } | |
6698 | ||
6699 | set = single_set_pattern (pattern); | |
6700 | if (set) | |
6701 | { | |
6702 | rtx dest = SET_DEST (set); | |
6703 | rtx src = SET_SRC (set); | |
6704 | ||
6705 | if (GET_CODE (dest) == REG) | |
6706 | { | |
6707 | int regno = REGNO (dest); | |
6708 | enum rtx_code src_code = GET_CODE (src); | |
6709 | ||
6710 | if (CC_P (regno) && src_code == COMPARE) | |
6711 | skip_nested_if = TRUE; | |
6712 | ||
6713 | else if (CR_P (regno) | |
6714 | && (src_code == IF_THEN_ELSE | |
6715 | || GET_RTX_CLASS (src_code) == '<')) | |
6716 | skip_nested_if = TRUE; | |
6717 | } | |
6718 | } | |
6719 | ||
6720 | if (! skip_nested_if) | |
6721 | for_each_rtx (&PATTERN (insn), frv_clear_registers_used, | |
6722 | (void *)&frv_ifcvt.nested_cc_ok_rewrite); | |
6723 | } | |
6724 | ||
6725 | if (insn == last_insn) | |
6726 | break; | |
6727 | ||
6728 | insn = NEXT_INSN (insn); | |
6729 | } | |
6730 | } | |
6731 | ||
6732 | /* If this is a nested if, rewrite the CC registers that are available to | |
6733 | include the ones that can be rewritten, to increase the chance of being | |
6734 | able to allocate a paired CC/CR register combination. */ | |
6735 | if (ce_info->pass > 1) | |
6736 | { | |
6737 | for (j = CC_FIRST; j <= CC_LAST; j++) | |
6738 | if (TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, j)) | |
6739 | SET_HARD_REG_BIT (tmp_reg->regs, j); | |
6740 | else | |
6741 | CLEAR_HARD_REG_BIT (tmp_reg->regs, j); | |
6742 | } | |
6743 | ||
6744 | if (rtl_dump_file) | |
6745 | { | |
6746 | int num_gprs = 0; | |
6747 | fprintf (rtl_dump_file, "Available GPRs: "); | |
6748 | ||
6749 | for (j = GPR_FIRST; j <= GPR_LAST; j++) | |
6750 | if (TEST_HARD_REG_BIT (tmp_reg->regs, j)) | |
6751 | { | |
6752 | fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]); | |
6753 | if (++num_gprs > GPR_TEMP_NUM+2) | |
6754 | break; | |
6755 | } | |
6756 | ||
6757 | fprintf (rtl_dump_file, "%s\nAvailable CRs: ", | |
6758 | (num_gprs > GPR_TEMP_NUM+2) ? " ..." : ""); | |
6759 | ||
6760 | for (j = CR_FIRST; j <= CR_LAST; j++) | |
6761 | if (TEST_HARD_REG_BIT (tmp_reg->regs, j)) | |
6762 | fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]); | |
6763 | ||
6764 | fputs ("\n", rtl_dump_file); | |
6765 | ||
6766 | if (ce_info->pass > 1) | |
6767 | { | |
6768 | fprintf (rtl_dump_file, "Modifiable CCs: "); | |
6769 | for (j = CC_FIRST; j <= CC_LAST; j++) | |
6770 | if (TEST_HARD_REG_BIT (tmp_reg->regs, j)) | |
6771 | fprintf (rtl_dump_file, " %d [%s]", j, reg_names[j]); | |
6772 | ||
6773 | fprintf (rtl_dump_file, "\n%d nested COND_EXEC statements\n", | |
6774 | frv_ifcvt.num_nested_cond_exec); | |
6775 | } | |
6776 | } | |
6777 | ||
6778 | /* Allocate the appropriate temporary condition code register. Try to | |
6779 | allocate the ICR/FCR register that corresponds to the ICC/FCC register so | |
6780 | that conditional cmp's can be done. */ | |
6781 | if (mode == CCmode || mode == CC_UNSmode) | |
6782 | { | |
6783 | cr_class = ICR_REGS; | |
6784 | cc_class = ICC_REGS; | |
6785 | cc_first = ICC_FIRST; | |
6786 | cc_last = ICC_LAST; | |
6787 | } | |
6788 | else if (mode == CC_FPmode) | |
6789 | { | |
6790 | cr_class = FCR_REGS; | |
6791 | cc_class = FCC_REGS; | |
6792 | cc_first = FCC_FIRST; | |
6793 | cc_last = FCC_LAST; | |
6794 | } | |
6795 | else | |
6796 | { | |
6797 | cc_first = cc_last = 0; | |
6798 | cr_class = cc_class = NO_REGS; | |
6799 | } | |
6800 | ||
6801 | cc = XEXP (true_expr, 0); | |
6802 | nested_cc = cr = NULL_RTX; | |
6803 | if (cc_class != NO_REGS) | |
6804 | { | |
6805 | /* For nested IFs and &&/||, see if we can find a CC and CR register pair | |
6806 | so we can execute a csubcc/caddcc/cfcmps instruction. */ | |
6807 | int cc_regno; | |
6808 | ||
6809 | for (cc_regno = cc_first; cc_regno <= cc_last; cc_regno++) | |
6810 | { | |
6811 | int cr_regno = cc_regno - CC_FIRST + CR_FIRST; | |
6812 | ||
6813 | if (TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cc_regno) | |
6814 | && TEST_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, cr_regno)) | |
6815 | { | |
6816 | frv_ifcvt.tmp_reg.next_reg[ (int)cr_class ] = cr_regno; | |
6817 | cr = frv_alloc_temp_reg (tmp_reg, cr_class, CC_CCRmode, TRUE, | |
6818 | TRUE); | |
6819 | ||
6820 | frv_ifcvt.tmp_reg.next_reg[ (int)cc_class ] = cc_regno; | |
6821 | nested_cc = frv_alloc_temp_reg (tmp_reg, cc_class, CCmode, | |
6822 | TRUE, TRUE); | |
6823 | break; | |
6824 | } | |
6825 | } | |
6826 | } | |
6827 | ||
6828 | if (! cr) | |
6829 | { | |
6830 | if (rtl_dump_file) | |
6831 | fprintf (rtl_dump_file, "Could not allocate a CR temporary register\n"); | |
6832 | ||
6833 | goto fail; | |
6834 | } | |
6835 | ||
6836 | if (rtl_dump_file) | |
6837 | fprintf (rtl_dump_file, | |
6838 | "Will use %s for conditional execution, %s for nested comparisons\n", | |
6839 | reg_names[ REGNO (cr)], | |
6840 | (nested_cc) ? reg_names[ REGNO (nested_cc) ] : "<none>"); | |
6841 | ||
6842 | /* Set the CCR bit. Note for integer tests, we reverse the condition so that | |
6843 | in an IF-THEN-ELSE sequence, we are testing the TRUE case against the CCR | |
6844 | bit being true. We don't do this for floating point, because of NaNs. */ | |
6845 | code = GET_CODE (true_expr); | |
6846 | if (GET_MODE (cc) != CC_FPmode) | |
6847 | { | |
6848 | code = reverse_condition (code); | |
6849 | code_true = EQ; | |
6850 | code_false = NE; | |
6851 | } | |
6852 | else | |
6853 | { | |
6854 | code_true = NE; | |
6855 | code_false = EQ; | |
6856 | } | |
6857 | ||
6858 | check_insn = gen_rtx_SET (VOIDmode, cr, | |
6859 | gen_rtx_fmt_ee (code, CC_CCRmode, cc, const0_rtx)); | |
6860 | ||
6861 | /* Record the check insn to be inserted later. */ | |
6862 | frv_ifcvt_add_insn (check_insn, test_bb->end, TRUE); | |
6863 | ||
6864 | /* Update the tests. */ | |
6865 | frv_ifcvt.cr_reg = cr; | |
6866 | frv_ifcvt.nested_cc_reg = nested_cc; | |
6867 | *p_true = gen_rtx_fmt_ee (code_true, CC_CCRmode, cr, const0_rtx); | |
6868 | *p_false = gen_rtx_fmt_ee (code_false, CC_CCRmode, cr, const0_rtx); | |
6869 | return; | |
6870 | ||
6871 | /* Fail, don't do this conditional execution. */ | |
6872 | fail: | |
6873 | *p_true = NULL_RTX; | |
6874 | *p_false = NULL_RTX; | |
6875 | if (rtl_dump_file) | |
6876 | fprintf (rtl_dump_file, "Disabling this conditional execution.\n"); | |
6877 | ||
6878 | return; | |
6879 | } | |
6880 | ||
6881 | \f | |
6882 | /* A C expression to modify the code described by the conditional if | |
6883 | information CE_INFO, for the basic block BB, possibly updating the tests in | |
6884 | TRUE_EXPR, and FALSE_EXPR for converting the && and || parts of if-then or | |
6885 | if-then-else code to conditional instructions. Set either TRUE_EXPR or | |
6886 | FALSE_EXPR to a null pointer if the tests cannot be converted. */ | |
6887 | ||
6888 | /* p_true and p_false are given expressions of the form: | |
6889 | ||
6890 | (and (eq:CC_CCR (reg:CC_CCR) | |
6891 | (const_int 0)) | |
6892 | (eq:CC (reg:CC) | |
6893 | (const_int 0))) */ | |
6894 | ||
6895 | void | |
6896 | frv_ifcvt_modify_multiple_tests (ce_info, bb, p_true, p_false) | |
6897 | ce_if_block_t *ce_info; | |
6898 | basic_block bb; | |
6899 | rtx *p_true; | |
6900 | rtx *p_false; | |
6901 | { | |
6902 | rtx old_true = XEXP (*p_true, 0); | |
6903 | rtx old_false = XEXP (*p_false, 0); | |
6904 | rtx true_expr = XEXP (*p_true, 1); | |
6905 | rtx false_expr = XEXP (*p_false, 1); | |
6906 | rtx test_expr; | |
6907 | rtx old_test; | |
6908 | rtx cr = XEXP (old_true, 0); | |
6909 | rtx check_insn; | |
6910 | rtx new_cr = NULL_RTX; | |
6911 | rtx *p_new_cr = (rtx *)0; | |
6912 | rtx if_else; | |
6913 | rtx compare; | |
6914 | rtx cc; | |
6915 | enum reg_class cr_class; | |
6916 | enum machine_mode mode = GET_MODE (true_expr); | |
6917 | rtx (*logical_func)(rtx, rtx, rtx); | |
6918 | ||
6919 | if (TARGET_DEBUG_COND_EXEC) | |
6920 | { | |
6921 | fprintf (stderr, | |
6922 | "\n:::::::::: frv_ifcvt_modify_multiple_tests, before modification for %s\ntrue insn:\n", | |
6923 | ce_info->and_and_p ? "&&" : "||"); | |
6924 | ||
6925 | debug_rtx (*p_true); | |
6926 | ||
6927 | fputs ("\nfalse insn:\n", stderr); | |
6928 | debug_rtx (*p_false); | |
6929 | } | |
6930 | ||
6931 | if (TARGET_NO_MULTI_CE) | |
6932 | goto fail; | |
6933 | ||
6934 | if (GET_CODE (cr) != REG) | |
6935 | goto fail; | |
b16c1435 | 6936 | |
36a05131 BS |
6937 | if (mode == CCmode || mode == CC_UNSmode) |
6938 | { | |
6939 | cr_class = ICR_REGS; | |
6940 | p_new_cr = &frv_ifcvt.extra_int_cr; | |
6941 | } | |
6942 | else if (mode == CC_FPmode) | |
6943 | { | |
6944 | cr_class = FCR_REGS; | |
6945 | p_new_cr = &frv_ifcvt.extra_fp_cr; | |
6946 | } | |
6947 | else | |
6948 | goto fail; | |
6949 | ||
6950 | /* Allocate a temp CR, reusing a previously allocated temp CR if we have 3 or | |
6951 | more &&/|| tests. */ | |
6952 | new_cr = *p_new_cr; | |
6953 | if (! new_cr) | |
6954 | { | |
6955 | new_cr = *p_new_cr = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, cr_class, | |
6956 | CC_CCRmode, TRUE, TRUE); | |
6957 | if (! new_cr) | |
6958 | goto fail; | |
6959 | } | |
6960 | ||
6961 | if (ce_info->and_and_p) | |
6962 | { | |
6963 | old_test = old_false; | |
6964 | test_expr = true_expr; | |
6965 | logical_func = (GET_CODE (old_true) == EQ) ? gen_andcr : gen_andncr; | |
6966 | *p_true = gen_rtx_NE (CC_CCRmode, cr, const0_rtx); | |
6967 | *p_false = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx); | |
6968 | } | |
6969 | else | |
6970 | { | |
6971 | old_test = old_false; | |
6972 | test_expr = false_expr; | |
6973 | logical_func = (GET_CODE (old_false) == EQ) ? gen_orcr : gen_orncr; | |
6974 | *p_true = gen_rtx_EQ (CC_CCRmode, cr, const0_rtx); | |
6975 | *p_false = gen_rtx_NE (CC_CCRmode, cr, const0_rtx); | |
6976 | } | |
6977 | ||
6978 | /* First add the andcr/andncr/orcr/orncr, which will be added after the | |
6979 | conditional check instruction, due to frv_ifcvt_add_insn being a LIFO | |
6980 | stack. */ | |
6981 | frv_ifcvt_add_insn ((*logical_func) (cr, cr, new_cr), bb->end, TRUE); | |
6982 | ||
6983 | /* Now add the conditional check insn. */ | |
6984 | cc = XEXP (test_expr, 0); | |
6985 | compare = gen_rtx_fmt_ee (GET_CODE (test_expr), CC_CCRmode, cc, const0_rtx); | |
6986 | if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, old_test, compare, const0_rtx); | |
6987 | ||
6988 | check_insn = gen_rtx_SET (VOIDmode, new_cr, if_else); | |
6989 | ||
6990 | /* add the new check insn to the list of check insns that need to be | |
6991 | inserted. */ | |
6992 | frv_ifcvt_add_insn (check_insn, bb->end, TRUE); | |
6993 | ||
6994 | if (TARGET_DEBUG_COND_EXEC) | |
6995 | { | |
6996 | fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, after modification\ntrue insn:\n", | |
6997 | stderr); | |
6998 | ||
6999 | debug_rtx (*p_true); | |
7000 | ||
7001 | fputs ("\nfalse insn:\n", stderr); | |
7002 | debug_rtx (*p_false); | |
7003 | } | |
7004 | ||
7005 | return; | |
7006 | ||
7007 | fail: | |
7008 | *p_true = *p_false = NULL_RTX; | |
7009 | ||
7010 | /* If we allocated a CR register, release it. */ | |
7011 | if (new_cr) | |
7012 | { | |
7013 | CLEAR_HARD_REG_BIT (frv_ifcvt.tmp_reg.regs, REGNO (new_cr)); | |
7014 | *p_new_cr = NULL_RTX; | |
7015 | } | |
7016 | ||
7017 | if (TARGET_DEBUG_COND_EXEC) | |
7018 | fputs ("\n:::::::::: frv_ifcvt_modify_multiple_tests, failed.\n", stderr); | |
7019 | ||
7020 | return; | |
7021 | } | |
7022 | ||
7023 | \f | |
7024 | /* Return a register which will be loaded with a value if an IF block is | |
7025 | converted to conditional execution. This is used to rewrite instructions | |
7026 | that use constants to ones that just use registers. */ | |
7027 | ||
7028 | static rtx | |
7029 | frv_ifcvt_load_value (value, insn) | |
7030 | rtx value; | |
7031 | rtx insn ATTRIBUTE_UNUSED; | |
7032 | { | |
7033 | int num_alloc = frv_ifcvt.cur_scratch_regs; | |
7034 | int i; | |
7035 | rtx reg; | |
7036 | ||
7037 | /* We know gr0 == 0, so replace any errant uses. */ | |
7038 | if (value == const0_rtx) | |
7039 | return gen_rtx_REG (SImode, GPR_FIRST); | |
7040 | ||
7041 | /* First search all registers currently loaded to see if we have an | |
7042 | applicable constant. */ | |
7043 | if (CONSTANT_P (value) | |
7044 | || (GET_CODE (value) == REG && REGNO (value) == LR_REGNO)) | |
7045 | { | |
7046 | for (i = 0; i < num_alloc; i++) | |
7047 | { | |
7048 | if (rtx_equal_p (SET_SRC (frv_ifcvt.scratch_regs[i]), value)) | |
7049 | return SET_DEST (frv_ifcvt.scratch_regs[i]); | |
7050 | } | |
7051 | } | |
7052 | ||
7053 | /* Have we exhausted the number of registers available? */ | |
7054 | if (num_alloc >= GPR_TEMP_NUM) | |
7055 | { | |
7056 | if (rtl_dump_file) | |
7057 | fprintf (rtl_dump_file, "Too many temporary registers allocated\n"); | |
7058 | ||
7059 | return NULL_RTX; | |
7060 | } | |
7061 | ||
7062 | /* Allocate the new register. */ | |
7063 | reg = frv_alloc_temp_reg (&frv_ifcvt.tmp_reg, GPR_REGS, SImode, TRUE, TRUE); | |
7064 | if (! reg) | |
7065 | { | |
7066 | if (rtl_dump_file) | |
7067 | fputs ("Could not find a scratch register\n", rtl_dump_file); | |
7068 | ||
7069 | return NULL_RTX; | |
7070 | } | |
7071 | ||
7072 | frv_ifcvt.cur_scratch_regs++; | |
7073 | frv_ifcvt.scratch_regs[num_alloc] = gen_rtx_SET (VOIDmode, reg, value); | |
7074 | ||
7075 | if (rtl_dump_file) | |
7076 | { | |
7077 | if (GET_CODE (value) == CONST_INT) | |
7078 | fprintf (rtl_dump_file, "Register %s will hold %ld\n", | |
7079 | reg_names[ REGNO (reg)], (long)INTVAL (value)); | |
7080 | ||
7081 | else if (GET_CODE (value) == REG && REGNO (value) == LR_REGNO) | |
7082 | fprintf (rtl_dump_file, "Register %s will hold LR\n", | |
7083 | reg_names[ REGNO (reg)]); | |
7084 | ||
7085 | else | |
7086 | fprintf (rtl_dump_file, "Register %s will hold a saved value\n", | |
7087 | reg_names[ REGNO (reg)]); | |
7088 | } | |
7089 | ||
7090 | return reg; | |
7091 | } | |
7092 | ||
7093 | \f | |
7094 | /* Update a MEM used in conditional code that might contain an offset to put | |
7095 | the offset into a scratch register, so that the conditional load/store | |
7096 | operations can be used. This function returns the original pointer if the | |
7097 | MEM is valid to use in conditional code, NULL if we can't load up the offset | |
7098 | into a temporary register, or the new MEM if we were successful. */ | |
7099 | ||
7100 | static rtx | |
7101 | frv_ifcvt_rewrite_mem (mem, mode, insn) | |
7102 | rtx mem; | |
7103 | enum machine_mode mode; | |
7104 | rtx insn; | |
7105 | { | |
7106 | rtx addr = XEXP (mem, 0); | |
7107 | ||
7108 | if (!frv_legitimate_address_p (mode, addr, reload_completed, TRUE)) | |
7109 | { | |
7110 | if (GET_CODE (addr) == PLUS) | |
7111 | { | |
7112 | rtx addr_op0 = XEXP (addr, 0); | |
7113 | rtx addr_op1 = XEXP (addr, 1); | |
7114 | ||
7115 | if (plus_small_data_p (addr_op0, addr_op1)) | |
7116 | addr = frv_ifcvt_load_value (addr, insn); | |
7117 | ||
7118 | else if (GET_CODE (addr_op0) == REG && CONSTANT_P (addr_op1)) | |
7119 | { | |
7120 | rtx reg = frv_ifcvt_load_value (addr_op1, insn); | |
7121 | if (!reg) | |
7122 | return NULL_RTX; | |
7123 | ||
7124 | addr = gen_rtx_PLUS (Pmode, addr_op0, reg); | |
7125 | } | |
7126 | ||
7127 | else | |
7128 | return NULL_RTX; | |
7129 | } | |
7130 | ||
7131 | else if (CONSTANT_P (addr)) | |
7132 | addr = frv_ifcvt_load_value (addr, insn); | |
7133 | ||
7134 | else | |
7135 | return NULL_RTX; | |
7136 | ||
7137 | if (addr == NULL_RTX) | |
7138 | return NULL_RTX; | |
7139 | ||
7140 | else if (XEXP (mem, 0) != addr) | |
7141 | return change_address (mem, mode, addr); | |
7142 | } | |
7143 | ||
7144 | return mem; | |
7145 | } | |
7146 | ||
7147 | \f | |
7148 | /* Given a PATTERN, return a SET expression if this PATTERN has only a single | |
7149 | SET, possibly conditionally executed. It may also have CLOBBERs, USEs. */ | |
7150 | ||
7151 | static rtx | |
7152 | single_set_pattern (pattern) | |
7153 | rtx pattern; | |
7154 | { | |
7155 | rtx set; | |
7156 | int i; | |
7157 | ||
7158 | if (GET_CODE (pattern) == COND_EXEC) | |
7159 | pattern = COND_EXEC_CODE (pattern); | |
7160 | ||
7161 | if (GET_CODE (pattern) == SET) | |
7162 | return pattern; | |
7163 | ||
7164 | else if (GET_CODE (pattern) == PARALLEL) | |
7165 | { | |
7166 | for (i = 0, set = 0; i < XVECLEN (pattern, 0); i++) | |
7167 | { | |
7168 | rtx sub = XVECEXP (pattern, 0, i); | |
7169 | ||
7170 | switch (GET_CODE (sub)) | |
7171 | { | |
7172 | case USE: | |
7173 | case CLOBBER: | |
7174 | break; | |
7175 | ||
7176 | case SET: | |
7177 | if (set) | |
7178 | return 0; | |
7179 | else | |
7180 | set = sub; | |
7181 | break; | |
7182 | ||
7183 | default: | |
7184 | return 0; | |
7185 | } | |
7186 | } | |
7187 | return set; | |
7188 | } | |
7189 | ||
7190 | return 0; | |
7191 | } | |
7192 | ||
7193 | \f | |
7194 | /* A C expression to modify the code described by the conditional if | |
7195 | information CE_INFO with the new PATTERN in INSN. If PATTERN is a null | |
7196 | pointer after the IFCVT_MODIFY_INSN macro executes, it is assumed that that | |
7197 | insn cannot be converted to be executed conditionally. */ | |
7198 | ||
7199 | rtx | |
7200 | frv_ifcvt_modify_insn (ce_info, pattern, insn) | |
7201 | ce_if_block_t *ce_info ATTRIBUTE_UNUSED; | |
7202 | rtx pattern; | |
7203 | rtx insn; | |
7204 | { | |
7205 | rtx orig_ce_pattern = pattern; | |
7206 | rtx set; | |
7207 | rtx op0; | |
7208 | rtx op1; | |
7209 | rtx test; | |
7210 | ||
7211 | if (GET_CODE (pattern) != COND_EXEC) | |
7212 | abort (); | |
7213 | ||
7214 | test = COND_EXEC_TEST (pattern); | |
7215 | if (GET_CODE (test) == AND) | |
7216 | { | |
7217 | rtx cr = frv_ifcvt.cr_reg; | |
7218 | rtx test_reg; | |
7219 | ||
7220 | op0 = XEXP (test, 0); | |
7221 | if (! rtx_equal_p (cr, XEXP (op0, 0))) | |
7222 | goto fail; | |
7223 | ||
7224 | op1 = XEXP (test, 1); | |
7225 | test_reg = XEXP (op1, 0); | |
7226 | if (GET_CODE (test_reg) != REG) | |
7227 | goto fail; | |
7228 | ||
7229 | /* Is this the first nested if block in this sequence? If so, generate | |
7230 | an andcr or andncr. */ | |
7231 | if (! frv_ifcvt.last_nested_if_cr) | |
7232 | { | |
7233 | rtx and_op; | |
7234 | ||
7235 | frv_ifcvt.last_nested_if_cr = test_reg; | |
7236 | if (GET_CODE (op0) == NE) | |
7237 | and_op = gen_andcr (test_reg, cr, test_reg); | |
7238 | else | |
7239 | and_op = gen_andncr (test_reg, cr, test_reg); | |
7240 | ||
7241 | frv_ifcvt_add_insn (and_op, insn, TRUE); | |
7242 | } | |
7243 | ||
7244 | /* If this isn't the first statement in the nested if sequence, see if we | |
7245 | are dealing with the same register. */ | |
7246 | else if (! rtx_equal_p (test_reg, frv_ifcvt.last_nested_if_cr)) | |
7247 | goto fail; | |
7248 | ||
7249 | COND_EXEC_TEST (pattern) = test = op1; | |
7250 | } | |
7251 | ||
7252 | /* If this isn't a nested if, reset state variables. */ | |
7253 | else | |
7254 | { | |
7255 | frv_ifcvt.last_nested_if_cr = NULL_RTX; | |
7256 | } | |
7257 | ||
7258 | set = single_set_pattern (pattern); | |
7259 | if (set) | |
7260 | { | |
7261 | rtx dest = SET_DEST (set); | |
7262 | rtx src = SET_SRC (set); | |
7263 | enum machine_mode mode = GET_MODE (dest); | |
7264 | ||
7265 | /* Check for normal binary operators */ | |
7266 | if (mode == SImode | |
7267 | && (GET_RTX_CLASS (GET_CODE (src)) == '2' | |
7268 | || GET_RTX_CLASS (GET_CODE (src)) == 'c')) | |
7269 | { | |
7270 | op0 = XEXP (src, 0); | |
7271 | op1 = XEXP (src, 1); | |
7272 | ||
7273 | /* Special case load of small data address which looks like: | |
7274 | r16+symbol_ref */ | |
7275 | if (GET_CODE (src) == PLUS && plus_small_data_p (op0, op1)) | |
7276 | { | |
7277 | src = frv_ifcvt_load_value (src, insn); | |
7278 | if (src) | |
7279 | COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src); | |
7280 | else | |
7281 | goto fail; | |
7282 | } | |
7283 | ||
7284 | else if (integer_register_operand (op0, SImode) && CONSTANT_P (op1)) | |
7285 | { | |
7286 | op1 = frv_ifcvt_load_value (op1, insn); | |
7287 | if (op1) | |
7288 | COND_EXEC_CODE (pattern) | |
7289 | = gen_rtx_SET (VOIDmode, dest, gen_rtx_fmt_ee (GET_CODE (src), | |
7290 | GET_MODE (src), | |
7291 | op0, op1)); | |
7292 | else | |
7293 | goto fail; | |
7294 | } | |
7295 | } | |
7296 | ||
7297 | /* For multiply by a constant, we need to handle the sign extending | |
7298 | correctly. Add a USE of the value after the multiply to prevent flow | |
7299 | from cratering because only one register out of the two were used. */ | |
7300 | else if (mode == DImode && GET_CODE (src) == MULT) | |
7301 | { | |
7302 | op0 = XEXP (src, 0); | |
7303 | op1 = XEXP (src, 1); | |
7304 | if (GET_CODE (op0) == SIGN_EXTEND && GET_CODE (op1) == CONST_INT) | |
7305 | { | |
7306 | op1 = frv_ifcvt_load_value (op1, insn); | |
7307 | if (op1) | |
7308 | { | |
7309 | op1 = gen_rtx_SIGN_EXTEND (DImode, op1); | |
7310 | COND_EXEC_CODE (pattern) | |
7311 | = gen_rtx_SET (VOIDmode, dest, | |
7312 | gen_rtx_MULT (DImode, op0, op1)); | |
7313 | } | |
7314 | else | |
7315 | goto fail; | |
7316 | } | |
7317 | ||
7318 | frv_ifcvt_add_insn (gen_rtx_USE (VOIDmode, dest), insn, FALSE); | |
7319 | } | |
7320 | ||
7321 | /* If we are just loading a constant created for a nested conditional | |
7322 | execution statement, just load the constant without any conditional | |
7323 | execution, since we know that the constant will not interfere with any | |
7324 | other registers. */ | |
7325 | else if (frv_ifcvt.scratch_insns_bitmap | |
7326 | && bitmap_bit_p (frv_ifcvt.scratch_insns_bitmap, | |
7327 | INSN_UID (insn))) | |
7328 | pattern = set; | |
7329 | ||
7330 | else if (mode == QImode || mode == HImode || mode == SImode | |
7331 | || mode == SFmode) | |
7332 | { | |
7333 | int changed_p = FALSE; | |
7334 | ||
7335 | /* Check for just loading up a constant */ | |
7336 | if (CONSTANT_P (src) && integer_register_operand (dest, mode)) | |
7337 | { | |
7338 | src = frv_ifcvt_load_value (src, insn); | |
7339 | if (!src) | |
7340 | goto fail; | |
7341 | ||
7342 | changed_p = TRUE; | |
7343 | } | |
7344 | ||
7345 | /* See if we need to fix up stores */ | |
7346 | if (GET_CODE (dest) == MEM) | |
7347 | { | |
7348 | rtx new_mem = frv_ifcvt_rewrite_mem (dest, mode, insn); | |
7349 | ||
7350 | if (!new_mem) | |
7351 | goto fail; | |
7352 | ||
7353 | else if (new_mem != dest) | |
7354 | { | |
7355 | changed_p = TRUE; | |
7356 | dest = new_mem; | |
7357 | } | |
7358 | } | |
7359 | ||
7360 | /* See if we need to fix up loads */ | |
7361 | if (GET_CODE (src) == MEM) | |
7362 | { | |
7363 | rtx new_mem = frv_ifcvt_rewrite_mem (src, mode, insn); | |
7364 | ||
7365 | if (!new_mem) | |
7366 | goto fail; | |
7367 | ||
7368 | else if (new_mem != src) | |
7369 | { | |
7370 | changed_p = TRUE; | |
7371 | src = new_mem; | |
7372 | } | |
7373 | } | |
7374 | ||
7375 | /* If either src or destination changed, redo SET. */ | |
7376 | if (changed_p) | |
7377 | COND_EXEC_CODE (pattern) = gen_rtx_SET (VOIDmode, dest, src); | |
7378 | } | |
7379 | ||
7380 | /* Rewrite a nested set cccr in terms of IF_THEN_ELSE. Also deal with | |
7381 | rewriting the CC register to be the same as the paired CC/CR register | |
7382 | for nested ifs. */ | |
7383 | else if (mode == CC_CCRmode && GET_RTX_CLASS (GET_CODE (src)) == '<') | |
7384 | { | |
7385 | int regno = REGNO (XEXP (src, 0)); | |
7386 | rtx if_else; | |
7387 | ||
7388 | if (ce_info->pass > 1 | |
7389 | && regno != (int)REGNO (frv_ifcvt.nested_cc_reg) | |
7390 | && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, regno)) | |
7391 | { | |
7392 | src = gen_rtx_fmt_ee (GET_CODE (src), | |
7393 | CC_CCRmode, | |
7394 | frv_ifcvt.nested_cc_reg, | |
7395 | XEXP (src, 1)); | |
7396 | } | |
7397 | ||
7398 | if_else = gen_rtx_IF_THEN_ELSE (CC_CCRmode, test, src, const0_rtx); | |
7399 | pattern = gen_rtx_SET (VOIDmode, dest, if_else); | |
7400 | } | |
7401 | ||
7402 | /* Remap a nested compare instruction to use the paired CC/CR reg. */ | |
7403 | else if (ce_info->pass > 1 | |
7404 | && GET_CODE (dest) == REG | |
7405 | && CC_P (REGNO (dest)) | |
7406 | && REGNO (dest) != REGNO (frv_ifcvt.nested_cc_reg) | |
7407 | && TEST_HARD_REG_BIT (frv_ifcvt.nested_cc_ok_rewrite, | |
7408 | REGNO (dest)) | |
7409 | && GET_CODE (src) == COMPARE) | |
7410 | { | |
7411 | PUT_MODE (frv_ifcvt.nested_cc_reg, GET_MODE (dest)); | |
7412 | COND_EXEC_CODE (pattern) | |
7413 | = gen_rtx_SET (VOIDmode, frv_ifcvt.nested_cc_reg, copy_rtx (src)); | |
7414 | } | |
7415 | } | |
7416 | ||
7417 | if (TARGET_DEBUG_COND_EXEC) | |
7418 | { | |
7419 | rtx orig_pattern = PATTERN (insn); | |
7420 | ||
7421 | PATTERN (insn) = pattern; | |
7422 | fprintf (stderr, | |
7423 | "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn after modification:\n", | |
7424 | ce_info->pass); | |
7425 | ||
7426 | debug_rtx (insn); | |
7427 | PATTERN (insn) = orig_pattern; | |
7428 | } | |
7429 | ||
7430 | return pattern; | |
7431 | ||
7432 | fail: | |
7433 | if (TARGET_DEBUG_COND_EXEC) | |
7434 | { | |
7435 | rtx orig_pattern = PATTERN (insn); | |
7436 | ||
7437 | PATTERN (insn) = orig_ce_pattern; | |
7438 | fprintf (stderr, | |
7439 | "\n:::::::::: frv_ifcvt_modify_insn: pass = %d, insn could not be modified:\n", | |
7440 | ce_info->pass); | |
7441 | ||
7442 | debug_rtx (insn); | |
7443 | PATTERN (insn) = orig_pattern; | |
7444 | } | |
7445 | ||
7446 | return NULL_RTX; | |
7447 | } | |
7448 | ||
7449 | \f | |
7450 | /* A C expression to perform any final machine dependent modifications in | |
7451 | converting code to conditional execution in the code described by the | |
7452 | conditional if information CE_INFO. */ | |
7453 | ||
7454 | void | |
7455 | frv_ifcvt_modify_final (ce_info) | |
7456 | ce_if_block_t *ce_info ATTRIBUTE_UNUSED; | |
7457 | { | |
7458 | rtx existing_insn; | |
7459 | rtx check_insn; | |
7460 | rtx p = frv_ifcvt.added_insns_list; | |
7461 | int i; | |
7462 | ||
7463 | /* Loop inserting the check insns. The last check insn is the first test, | |
7464 | and is the appropriate place to insert constants. */ | |
7465 | if (! p) | |
7466 | abort (); | |
7467 | ||
7468 | do | |
7469 | { | |
7470 | rtx check_and_insert_insns = XEXP (p, 0); | |
7471 | rtx old_p = p; | |
7472 | ||
7473 | check_insn = XEXP (check_and_insert_insns, 0); | |
7474 | existing_insn = XEXP (check_and_insert_insns, 1); | |
7475 | p = XEXP (p, 1); | |
7476 | ||
7477 | /* The jump bit is used to say that the new insn is to be inserted BEFORE | |
7478 | the existing insn, otherwise it is to be inserted AFTER. */ | |
7479 | if (check_and_insert_insns->jump) | |
7480 | { | |
7481 | emit_insn_before (check_insn, existing_insn); | |
7482 | check_and_insert_insns->jump = 0; | |
7483 | } | |
7484 | else | |
7485 | emit_insn_after (check_insn, existing_insn); | |
7486 | ||
7487 | free_EXPR_LIST_node (check_and_insert_insns); | |
7488 | free_EXPR_LIST_node (old_p); | |
7489 | } | |
7490 | while (p != NULL_RTX); | |
7491 | ||
7492 | /* Load up any constants needed into temp gprs */ | |
7493 | for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++) | |
7494 | { | |
7495 | rtx insn = emit_insn_before (frv_ifcvt.scratch_regs[i], existing_insn); | |
7496 | if (! frv_ifcvt.scratch_insns_bitmap) | |
7497 | frv_ifcvt.scratch_insns_bitmap = BITMAP_XMALLOC (); | |
7498 | bitmap_set_bit (frv_ifcvt.scratch_insns_bitmap, INSN_UID (insn)); | |
7499 | frv_ifcvt.scratch_regs[i] = NULL_RTX; | |
7500 | } | |
7501 | ||
7502 | frv_ifcvt.added_insns_list = NULL_RTX; | |
7503 | frv_ifcvt.cur_scratch_regs = 0; | |
7504 | } | |
7505 | ||
7506 | \f | |
7507 | /* A C expression to cancel any machine dependent modifications in converting | |
7508 | code to conditional execution in the code described by the conditional if | |
7509 | information CE_INFO. */ | |
7510 | ||
7511 | void | |
7512 | frv_ifcvt_modify_cancel (ce_info) | |
7513 | ce_if_block_t *ce_info ATTRIBUTE_UNUSED; | |
7514 | { | |
7515 | int i; | |
7516 | rtx p = frv_ifcvt.added_insns_list; | |
7517 | ||
7518 | /* Loop freeing up the EXPR_LIST's allocated. */ | |
7519 | while (p != NULL_RTX) | |
7520 | { | |
7521 | rtx check_and_jump = XEXP (p, 0); | |
7522 | rtx old_p = p; | |
7523 | ||
7524 | p = XEXP (p, 1); | |
7525 | free_EXPR_LIST_node (check_and_jump); | |
7526 | free_EXPR_LIST_node (old_p); | |
7527 | } | |
7528 | ||
7529 | /* Release any temporary gprs allocated. */ | |
7530 | for (i = 0; i < frv_ifcvt.cur_scratch_regs; i++) | |
7531 | frv_ifcvt.scratch_regs[i] = NULL_RTX; | |
7532 | ||
7533 | frv_ifcvt.added_insns_list = NULL_RTX; | |
7534 | frv_ifcvt.cur_scratch_regs = 0; | |
7535 | return; | |
7536 | } | |
7537 | \f | |
7538 | /* A C expression for the size in bytes of the trampoline, as an integer. | |
7539 | The template is: | |
7540 | ||
7541 | setlo #0, <jmp_reg> | |
7542 | setlo #0, <static_chain> | |
7543 | sethi #0, <jmp_reg> | |
7544 | sethi #0, <static_chain> | |
7545 | jmpl @(gr0,<jmp_reg>) */ | |
7546 | ||
7547 | int | |
7548 | frv_trampoline_size () | |
7549 | { | |
7550 | return 5 /* instructions */ * 4 /* instruction size */; | |
7551 | } | |
7552 | ||
7553 | \f | |
7554 | /* A C statement to initialize the variable parts of a trampoline. ADDR is an | |
7555 | RTX for the address of the trampoline; FNADDR is an RTX for the address of | |
7556 | the nested function; STATIC_CHAIN is an RTX for the static chain value that | |
7557 | should be passed to the function when it is called. | |
7558 | ||
7559 | The template is: | |
7560 | ||
7561 | setlo #0, <jmp_reg> | |
7562 | setlo #0, <static_chain> | |
7563 | sethi #0, <jmp_reg> | |
7564 | sethi #0, <static_chain> | |
7565 | jmpl @(gr0,<jmp_reg>) */ | |
7566 | ||
7567 | void | |
7568 | frv_initialize_trampoline (addr, fnaddr, static_chain) | |
7569 | rtx addr; | |
7570 | rtx fnaddr; | |
7571 | rtx static_chain; | |
7572 | { | |
7573 | rtx sc_reg = force_reg (Pmode, static_chain); | |
7574 | ||
7575 | emit_library_call (gen_rtx_SYMBOL_REF (SImode, "__trampoline_setup"), | |
7576 | FALSE, VOIDmode, 4, | |
7577 | addr, Pmode, | |
7578 | GEN_INT (frv_trampoline_size ()), SImode, | |
7579 | fnaddr, Pmode, | |
7580 | sc_reg, Pmode); | |
7581 | } | |
7582 | ||
7583 | \f | |
7584 | /* Many machines have some registers that cannot be copied directly to or from | |
7585 | memory or even from other types of registers. An example is the `MQ' | |
7586 | register, which on most machines, can only be copied to or from general | |
7587 | registers, but not memory. Some machines allow copying all registers to and | |
7588 | from memory, but require a scratch register for stores to some memory | |
7589 | locations (e.g., those with symbolic address on the RT, and those with | |
981f6289 | 7590 | certain symbolic address on the SPARC when compiling PIC). In some cases, |
36a05131 BS |
7591 | both an intermediate and a scratch register are required. |
7592 | ||
7593 | You should define these macros to indicate to the reload phase that it may | |
7594 | need to allocate at least one register for a reload in addition to the | |
7595 | register to contain the data. Specifically, if copying X to a register | |
7596 | CLASS in MODE requires an intermediate register, you should define | |
7597 | `SECONDARY_INPUT_RELOAD_CLASS' to return the largest register class all of | |
7598 | whose registers can be used as intermediate registers or scratch registers. | |
7599 | ||
7600 | If copying a register CLASS in MODE to X requires an intermediate or scratch | |
7601 | register, `SECONDARY_OUTPUT_RELOAD_CLASS' should be defined to return the | |
7602 | largest register class required. If the requirements for input and output | |
7603 | reloads are the same, the macro `SECONDARY_RELOAD_CLASS' should be used | |
7604 | instead of defining both macros identically. | |
7605 | ||
7606 | The values returned by these macros are often `GENERAL_REGS'. Return | |
7607 | `NO_REGS' if no spare register is needed; i.e., if X can be directly copied | |
7608 | to or from a register of CLASS in MODE without requiring a scratch register. | |
7609 | Do not define this macro if it would always return `NO_REGS'. | |
7610 | ||
7611 | If a scratch register is required (either with or without an intermediate | |
7612 | register), you should define patterns for `reload_inM' or `reload_outM', as | |
7613 | required.. These patterns, which will normally be implemented with a | |
7614 | `define_expand', should be similar to the `movM' patterns, except that | |
7615 | operand 2 is the scratch register. | |
7616 | ||
7617 | Define constraints for the reload register and scratch register that contain | |
7618 | a single register class. If the original reload register (whose class is | |
7619 | CLASS) can meet the constraint given in the pattern, the value returned by | |
7620 | these macros is used for the class of the scratch register. Otherwise, two | |
7621 | additional reload registers are required. Their classes are obtained from | |
7622 | the constraints in the insn pattern. | |
7623 | ||
7624 | X might be a pseudo-register or a `subreg' of a pseudo-register, which could | |
7625 | either be in a hard register or in memory. Use `true_regnum' to find out; | |
7626 | it will return -1 if the pseudo is in memory and the hard register number if | |
7627 | it is in a register. | |
7628 | ||
7629 | These macros should not be used in the case where a particular class of | |
7630 | registers can only be copied to memory and not to another class of | |
7631 | registers. In that case, secondary reload registers are not needed and | |
7632 | would not be helpful. Instead, a stack location must be used to perform the | |
43aa4e05 | 7633 | copy and the `movM' pattern should use memory as an intermediate storage. |
36a05131 BS |
7634 | This case often occurs between floating-point and general registers. */ |
7635 | ||
7636 | enum reg_class | |
7637 | frv_secondary_reload_class (class, mode, x, in_p) | |
7638 | enum reg_class class; | |
7639 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
7640 | rtx x; | |
7641 | int in_p ATTRIBUTE_UNUSED; | |
7642 | { | |
7643 | enum reg_class ret; | |
7644 | ||
7645 | switch (class) | |
7646 | { | |
7647 | default: | |
7648 | ret = NO_REGS; | |
7649 | break; | |
7650 | ||
7651 | /* Accumulators/Accumulator guard registers need to go through floating | |
7652 | point registers. */ | |
7653 | case QUAD_REGS: | |
7654 | case EVEN_REGS: | |
7655 | case GPR_REGS: | |
7656 | ret = NO_REGS; | |
7657 | if (x && GET_CODE (x) == REG) | |
7658 | { | |
7659 | int regno = REGNO (x); | |
7660 | ||
7661 | if (ACC_P (regno) || ACCG_P (regno)) | |
7662 | ret = FPR_REGS; | |
7663 | } | |
7664 | break; | |
7665 | ||
9cd10576 | 7666 | /* Nonzero constants should be loaded into an FPR through a GPR. */ |
36a05131 BS |
7667 | case QUAD_FPR_REGS: |
7668 | case FEVEN_REGS: | |
7669 | case FPR_REGS: | |
7670 | if (x && CONSTANT_P (x) && !ZERO_P (x)) | |
7671 | ret = GPR_REGS; | |
7672 | else | |
7673 | ret = NO_REGS; | |
7674 | break; | |
7675 | ||
7676 | /* All of these types need gpr registers. */ | |
7677 | case ICC_REGS: | |
7678 | case FCC_REGS: | |
7679 | case CC_REGS: | |
7680 | case ICR_REGS: | |
7681 | case FCR_REGS: | |
7682 | case CR_REGS: | |
7683 | case LCR_REG: | |
7684 | case LR_REG: | |
7685 | ret = GPR_REGS; | |
7686 | break; | |
7687 | ||
7688 | /* The accumulators need fpr registers */ | |
7689 | case ACC_REGS: | |
7690 | case EVEN_ACC_REGS: | |
7691 | case QUAD_ACC_REGS: | |
7692 | case ACCG_REGS: | |
7693 | ret = FPR_REGS; | |
7694 | break; | |
7695 | } | |
7696 | ||
7697 | return ret; | |
7698 | } | |
7699 | ||
7700 | \f | |
7701 | /* A C expression whose value is nonzero if pseudos that have been assigned to | |
7702 | registers of class CLASS would likely be spilled because registers of CLASS | |
7703 | are needed for spill registers. | |
7704 | ||
7705 | The default value of this macro returns 1 if CLASS has exactly one register | |
7706 | and zero otherwise. On most machines, this default should be used. Only | |
7707 | define this macro to some other expression if pseudo allocated by | |
7708 | `local-alloc.c' end up in memory because their hard registers were needed | |
7709 | for spill registers. If this macro returns nonzero for those classes, those | |
7710 | pseudos will only be allocated by `global.c', which knows how to reallocate | |
7711 | the pseudo to another register. If there would not be another register | |
7712 | available for reallocation, you should not change the definition of this | |
7713 | macro since the only effect of such a definition would be to slow down | |
7714 | register allocation. */ | |
7715 | ||
7716 | int | |
7717 | frv_class_likely_spilled_p (class) | |
7718 | enum reg_class class; | |
7719 | { | |
7720 | switch (class) | |
7721 | { | |
7722 | default: | |
7723 | break; | |
7724 | ||
7725 | case ICC_REGS: | |
7726 | case FCC_REGS: | |
7727 | case CC_REGS: | |
7728 | case ICR_REGS: | |
7729 | case FCR_REGS: | |
7730 | case CR_REGS: | |
7731 | case LCR_REG: | |
7732 | case LR_REG: | |
7733 | case SPR_REGS: | |
7734 | case QUAD_ACC_REGS: | |
7735 | case EVEN_ACC_REGS: | |
7736 | case ACC_REGS: | |
7737 | case ACCG_REGS: | |
7738 | return TRUE; | |
7739 | } | |
7740 | ||
7741 | return FALSE; | |
7742 | } | |
7743 | ||
7744 | \f | |
7745 | /* An expression for the alignment of a structure field FIELD if the | |
7ec022b2 | 7746 | alignment computed in the usual way is COMPUTED. GCC uses this |
36a05131 BS |
7747 | value instead of the value in `BIGGEST_ALIGNMENT' or |
7748 | `BIGGEST_FIELD_ALIGNMENT', if defined, for structure fields only. */ | |
7749 | ||
7750 | /* The definition type of the bit field data is either char, short, long or | |
7751 | long long. The maximum bit size is the number of bits of its own type. | |
7752 | ||
7753 | The bit field data is assigned to a storage unit that has an adequate size | |
7754 | for bit field data retention and is located at the smallest address. | |
7755 | ||
7756 | Consecutive bit field data are packed at consecutive bits having the same | |
7757 | storage unit, with regard to the type, beginning with the MSB and continuing | |
7758 | toward the LSB. | |
7759 | ||
7760 | If a field to be assigned lies over a bit field type boundary, its | |
7761 | assignment is completed by aligning it with a boundary suitable for the | |
7762 | type. | |
7763 | ||
7764 | When a bit field having a bit length of 0 is declared, it is forcibly | |
7765 | assigned to the next storage unit. | |
7766 | ||
7767 | e.g) | |
7768 | struct { | |
7769 | int a:2; | |
7770 | int b:6; | |
7771 | char c:4; | |
7772 | int d:10; | |
7773 | int :0; | |
7774 | int f:2; | |
7775 | } x; | |
7776 | ||
7777 | +0 +1 +2 +3 | |
7778 | &x 00000000 00000000 00000000 00000000 | |
7779 | MLM----L | |
7780 | a b | |
7781 | &x+4 00000000 00000000 00000000 00000000 | |
7782 | M--L | |
7783 | c | |
7784 | &x+8 00000000 00000000 00000000 00000000 | |
7785 | M----------L | |
7786 | d | |
7787 | &x+12 00000000 00000000 00000000 00000000 | |
7788 | ML | |
7789 | f | |
7790 | */ | |
7791 | ||
7792 | int | |
7793 | frv_adjust_field_align (field, computed) | |
7794 | tree field; | |
7795 | int computed; | |
7796 | { | |
b16c1435 EC |
7797 | |
7798 | tree type = TREE_TYPE (field); | |
7799 | ||
7800 | /* Make sure that the bitfield is not wider than the type. */ | |
7801 | if (DECL_BIT_FIELD (field) | |
25f93e18 | 7802 | && !DECL_ARTIFICIAL (field)) |
36a05131 BS |
7803 | { |
7804 | tree parent = DECL_CONTEXT (field); | |
7805 | tree prev = NULL_TREE; | |
7806 | tree cur; | |
7807 | ||
36a05131 BS |
7808 | for (cur = TYPE_FIELDS (parent); cur && cur != field; cur = TREE_CHAIN (cur)) |
7809 | { | |
7810 | if (TREE_CODE (cur) != FIELD_DECL) | |
7811 | continue; | |
7812 | ||
7813 | prev = cur; | |
7814 | } | |
7815 | ||
7816 | if (!cur) | |
7817 | abort (); | |
7818 | ||
7819 | /* If this isn't a :0 field and if the previous element is a bitfield | |
7820 | also, see if the type is different, if so, we will need to align the | |
43a88a8c | 7821 | bit-field to the next boundary */ |
36a05131 BS |
7822 | if (prev |
7823 | && ! DECL_PACKED (field) | |
7824 | && ! integer_zerop (DECL_SIZE (field)) | |
7825 | && DECL_BIT_FIELD_TYPE (field) != DECL_BIT_FIELD_TYPE (prev)) | |
7826 | { | |
7827 | int prev_align = TYPE_ALIGN (TREE_TYPE (prev)); | |
7828 | int cur_align = TYPE_ALIGN (TREE_TYPE (field)); | |
7829 | computed = (prev_align > cur_align) ? prev_align : cur_align; | |
7830 | } | |
7831 | } | |
7832 | ||
7833 | return computed; | |
7834 | } | |
7835 | ||
7836 | \f | |
7837 | /* A C expression that is nonzero if it is permissible to store a value of mode | |
7838 | MODE in hard register number REGNO (or in several registers starting with | |
7839 | that one). For a machine where all registers are equivalent, a suitable | |
7840 | definition is | |
7841 | ||
7842 | #define HARD_REGNO_MODE_OK(REGNO, MODE) 1 | |
7843 | ||
7844 | It is not necessary for this macro to check for the numbers of fixed | |
7845 | registers, because the allocation mechanism considers them to be always | |
7846 | occupied. | |
7847 | ||
7848 | On some machines, double-precision values must be kept in even/odd register | |
7849 | pairs. The way to implement that is to define this macro to reject odd | |
7850 | register numbers for such modes. | |
7851 | ||
7852 | The minimum requirement for a mode to be OK in a register is that the | |
7853 | `movMODE' instruction pattern support moves between the register and any | |
7854 | other hard register for which the mode is OK; and that moving a value into | |
7855 | the register and back out not alter it. | |
7856 | ||
7857 | Since the same instruction used to move `SImode' will work for all narrower | |
7858 | integer modes, it is not necessary on any machine for `HARD_REGNO_MODE_OK' | |
7859 | to distinguish between these modes, provided you define patterns `movhi', | |
7860 | etc., to take advantage of this. This is useful because of the interaction | |
7861 | between `HARD_REGNO_MODE_OK' and `MODES_TIEABLE_P'; it is very desirable for | |
7862 | all integer modes to be tieable. | |
7863 | ||
7864 | Many machines have special registers for floating point arithmetic. Often | |
7865 | people assume that floating point machine modes are allowed only in floating | |
7866 | point registers. This is not true. Any registers that can hold integers | |
7867 | can safely *hold* a floating point machine mode, whether or not floating | |
7868 | arithmetic can be done on it in those registers. Integer move instructions | |
7869 | can be used to move the values. | |
7870 | ||
7871 | On some machines, though, the converse is true: fixed-point machine modes | |
7872 | may not go in floating registers. This is true if the floating registers | |
7873 | normalize any value stored in them, because storing a non-floating value | |
7874 | there would garble it. In this case, `HARD_REGNO_MODE_OK' should reject | |
7875 | fixed-point machine modes in floating registers. But if the floating | |
7876 | registers do not automatically normalize, if you can store any bit pattern | |
7877 | in one and retrieve it unchanged without a trap, then any machine mode may | |
7878 | go in a floating register, so you can define this macro to say so. | |
7879 | ||
7880 | The primary significance of special floating registers is rather that they | |
7881 | are the registers acceptable in floating point arithmetic instructions. | |
7882 | However, this is of no concern to `HARD_REGNO_MODE_OK'. You handle it by | |
7883 | writing the proper constraints for those instructions. | |
7884 | ||
7885 | On some machines, the floating registers are especially slow to access, so | |
7886 | that it is better to store a value in a stack frame than in such a register | |
7887 | if floating point arithmetic is not being done. As long as the floating | |
7888 | registers are not in class `GENERAL_REGS', they will not be used unless some | |
7889 | pattern's constraint asks for one. */ | |
7890 | ||
7891 | int | |
7892 | frv_hard_regno_mode_ok (regno, mode) | |
7893 | int regno; | |
7894 | enum machine_mode mode; | |
7895 | { | |
7896 | int base; | |
7897 | int mask; | |
7898 | ||
7899 | switch (mode) | |
7900 | { | |
7901 | case CCmode: | |
7902 | case CC_UNSmode: | |
7903 | return ICC_P (regno) || GPR_P (regno); | |
7904 | ||
7905 | case CC_CCRmode: | |
7906 | return CR_P (regno) || GPR_P (regno); | |
7907 | ||
7908 | case CC_FPmode: | |
7909 | return FCC_P (regno) || GPR_P (regno); | |
7910 | ||
7911 | default: | |
7912 | break; | |
7913 | } | |
7914 | ||
7915 | /* Set BASE to the first register in REGNO's class. Set MASK to the | |
7916 | bits that must be clear in (REGNO - BASE) for the register to be | |
7917 | well-aligned. */ | |
7918 | if (INTEGRAL_MODE_P (mode) || FLOAT_MODE_P (mode) || VECTOR_MODE_P (mode)) | |
7919 | { | |
7920 | if (ACCG_P (regno)) | |
7921 | { | |
7922 | /* ACCGs store one byte. Two-byte quantities must start in | |
7923 | even-numbered registers, four-byte ones in registers whose | |
7924 | numbers are divisible by four, and so on. */ | |
7925 | base = ACCG_FIRST; | |
7926 | mask = GET_MODE_SIZE (mode) - 1; | |
7927 | } | |
7928 | else | |
7929 | { | |
b16c1435 EC |
7930 | /* The other registers store one word. */ |
7931 | if (GPR_P (regno) || regno == AP_FIRST) | |
36a05131 BS |
7932 | base = GPR_FIRST; |
7933 | ||
7934 | else if (FPR_P (regno)) | |
7935 | base = FPR_FIRST; | |
7936 | ||
7937 | else if (ACC_P (regno)) | |
7938 | base = ACC_FIRST; | |
7939 | ||
b16c1435 EC |
7940 | else if (SPR_P (regno)) |
7941 | return mode == SImode; | |
7942 | ||
7943 | /* Fill in the table. */ | |
36a05131 BS |
7944 | else |
7945 | return 0; | |
7946 | ||
7947 | /* Anything smaller than an SI is OK in any word-sized register. */ | |
7948 | if (GET_MODE_SIZE (mode) < 4) | |
7949 | return 1; | |
7950 | ||
7951 | mask = (GET_MODE_SIZE (mode) / 4) - 1; | |
7952 | } | |
7953 | return (((regno - base) & mask) == 0); | |
7954 | } | |
7955 | ||
7956 | return 0; | |
7957 | } | |
7958 | ||
7959 | \f | |
7960 | /* A C expression for the number of consecutive hard registers, starting at | |
7961 | register number REGNO, required to hold a value of mode MODE. | |
7962 | ||
7963 | On a machine where all registers are exactly one word, a suitable definition | |
7964 | of this macro is | |
7965 | ||
7966 | #define HARD_REGNO_NREGS(REGNO, MODE) \ | |
7967 | ((GET_MODE_SIZE (MODE) + UNITS_PER_WORD - 1) \ | |
7968 | / UNITS_PER_WORD)) */ | |
7969 | ||
7970 | /* On the FRV, make the CC_FP mode take 3 words in the integer registers, so | |
7971 | that we can build the appropriate instructions to properly reload the | |
7972 | values. Also, make the byte-sized accumulator guards use one guard | |
7973 | for each byte. */ | |
7974 | ||
7975 | int | |
7976 | frv_hard_regno_nregs (regno, mode) | |
7977 | int regno; | |
7978 | enum machine_mode mode; | |
7979 | { | |
7980 | if (ACCG_P (regno)) | |
7981 | return GET_MODE_SIZE (mode); | |
7982 | else | |
7983 | return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
7984 | } | |
7985 | ||
7986 | \f | |
7987 | /* A C expression for the maximum number of consecutive registers of | |
7988 | class CLASS needed to hold a value of mode MODE. | |
7989 | ||
7990 | This is closely related to the macro `HARD_REGNO_NREGS'. In fact, the value | |
7991 | of the macro `CLASS_MAX_NREGS (CLASS, MODE)' should be the maximum value of | |
7992 | `HARD_REGNO_NREGS (REGNO, MODE)' for all REGNO values in the class CLASS. | |
7993 | ||
7994 | This macro helps control the handling of multiple-word values in | |
7995 | the reload pass. | |
7996 | ||
7997 | This declaration is required. */ | |
7998 | ||
7999 | int | |
8000 | frv_class_max_nregs (class, mode) | |
8001 | enum reg_class class; | |
8002 | enum machine_mode mode; | |
8003 | { | |
8004 | if (class == ACCG_REGS) | |
8005 | /* An N-byte value requires N accumulator guards. */ | |
8006 | return GET_MODE_SIZE (mode); | |
8007 | else | |
8008 | return (GET_MODE_SIZE (mode) + UNITS_PER_WORD - 1) / UNITS_PER_WORD; | |
8009 | } | |
8010 | ||
8011 | \f | |
8012 | /* A C expression that is nonzero if X is a legitimate constant for an | |
8013 | immediate operand on the target machine. You can assume that X satisfies | |
8014 | `CONSTANT_P', so you need not check this. In fact, `1' is a suitable | |
8015 | definition for this macro on machines where anything `CONSTANT_P' is valid. */ | |
8016 | ||
8017 | int | |
8018 | frv_legitimate_constant_p (x) | |
8019 | rtx x; | |
8020 | { | |
8021 | enum machine_mode mode = GET_MODE (x); | |
8022 | ||
8023 | /* All of the integer constants are ok */ | |
8024 | if (GET_CODE (x) != CONST_DOUBLE) | |
8025 | return TRUE; | |
8026 | ||
8027 | /* double integer constants are ok */ | |
8028 | if (mode == VOIDmode || mode == DImode) | |
8029 | return TRUE; | |
8030 | ||
8031 | /* 0 is always ok */ | |
8032 | if (x == CONST0_RTX (mode)) | |
8033 | return TRUE; | |
8034 | ||
8035 | /* If floating point is just emulated, allow any constant, since it will be | |
8036 | constructed in the GPRs */ | |
8037 | if (!TARGET_HAS_FPRS) | |
8038 | return TRUE; | |
8039 | ||
8040 | if (mode == DFmode && !TARGET_DOUBLE) | |
8041 | return TRUE; | |
8042 | ||
8043 | /* Otherwise store the constant away and do a load. */ | |
8044 | return FALSE; | |
8045 | } | |
8046 | \f | |
8047 | /* A C expression for the cost of moving data from a register in class FROM to | |
8048 | one in class TO. The classes are expressed using the enumeration values | |
8049 | such as `GENERAL_REGS'. A value of 4 is the default; other values are | |
8050 | interpreted relative to that. | |
8051 | ||
8052 | It is not required that the cost always equal 2 when FROM is the same as TO; | |
8053 | on some machines it is expensive to move between registers if they are not | |
8054 | general registers. | |
8055 | ||
8056 | If reload sees an insn consisting of a single `set' between two hard | |
8057 | registers, and if `REGISTER_MOVE_COST' applied to their classes returns a | |
8058 | value of 2, reload does not check to ensure that the constraints of the insn | |
8059 | are met. Setting a cost of other than 2 will allow reload to verify that | |
8060 | the constraints are met. You should do this if the `movM' pattern's | |
8061 | constraints do not allow such copying. */ | |
8062 | ||
8063 | #define HIGH_COST 40 | |
8064 | #define MEDIUM_COST 3 | |
8065 | #define LOW_COST 1 | |
8066 | ||
8067 | int | |
8068 | frv_register_move_cost (from, to) | |
8069 | enum reg_class from; | |
8070 | enum reg_class to; | |
8071 | { | |
8072 | switch (from) | |
8073 | { | |
8074 | default: | |
8075 | break; | |
8076 | ||
8077 | case QUAD_REGS: | |
8078 | case EVEN_REGS: | |
8079 | case GPR_REGS: | |
8080 | switch (to) | |
8081 | { | |
8082 | default: | |
8083 | break; | |
8084 | ||
8085 | case QUAD_REGS: | |
8086 | case EVEN_REGS: | |
8087 | case GPR_REGS: | |
8088 | return LOW_COST; | |
8089 | ||
8090 | case FEVEN_REGS: | |
8091 | case FPR_REGS: | |
8092 | return LOW_COST; | |
8093 | ||
8094 | case LCR_REG: | |
8095 | case LR_REG: | |
8096 | case SPR_REGS: | |
8097 | return LOW_COST; | |
8098 | } | |
8099 | ||
8100 | case FEVEN_REGS: | |
8101 | case FPR_REGS: | |
8102 | switch (to) | |
8103 | { | |
8104 | default: | |
8105 | break; | |
8106 | ||
8107 | case QUAD_REGS: | |
8108 | case EVEN_REGS: | |
8109 | case GPR_REGS: | |
8110 | case ACC_REGS: | |
8111 | case EVEN_ACC_REGS: | |
8112 | case QUAD_ACC_REGS: | |
8113 | case ACCG_REGS: | |
8114 | return MEDIUM_COST; | |
8115 | ||
8116 | case FEVEN_REGS: | |
8117 | case FPR_REGS: | |
8118 | return LOW_COST; | |
8119 | } | |
8120 | ||
8121 | case LCR_REG: | |
8122 | case LR_REG: | |
8123 | case SPR_REGS: | |
8124 | switch (to) | |
8125 | { | |
8126 | default: | |
8127 | break; | |
8128 | ||
8129 | case QUAD_REGS: | |
8130 | case EVEN_REGS: | |
8131 | case GPR_REGS: | |
8132 | return MEDIUM_COST; | |
8133 | } | |
8134 | ||
8135 | case ACC_REGS: | |
8136 | case EVEN_ACC_REGS: | |
8137 | case QUAD_ACC_REGS: | |
8138 | case ACCG_REGS: | |
8139 | switch (to) | |
8140 | { | |
8141 | default: | |
8142 | break; | |
8143 | ||
8144 | case FEVEN_REGS: | |
8145 | case FPR_REGS: | |
8146 | return MEDIUM_COST; | |
8147 | ||
8148 | } | |
8149 | } | |
8150 | ||
8151 | return HIGH_COST; | |
8152 | } | |
8153 | \f | |
8154 | /* Implementation of TARGET_ASM_INTEGER. In the FRV case we need to | |
8155 | use ".picptr" to generate safe relocations for PIC code. We also | |
8156 | need a fixup entry for aligned (non-debugging) code. */ | |
8157 | ||
8158 | static bool | |
8159 | frv_assemble_integer (value, size, aligned_p) | |
8160 | rtx value; | |
8161 | unsigned int size; | |
8162 | int aligned_p; | |
8163 | { | |
8164 | if (flag_pic && size == UNITS_PER_WORD) | |
8165 | { | |
8166 | if (GET_CODE (value) == CONST | |
8167 | || GET_CODE (value) == SYMBOL_REF | |
8168 | || GET_CODE (value) == LABEL_REF) | |
8169 | { | |
8170 | if (aligned_p) | |
8171 | { | |
8172 | static int label_num = 0; | |
8173 | char buf[256]; | |
8174 | const char *p; | |
8175 | ||
8176 | ASM_GENERATE_INTERNAL_LABEL (buf, "LCP", label_num++); | |
14966b94 | 8177 | p = (* targetm.strip_name_encoding) (buf); |
36a05131 BS |
8178 | |
8179 | fprintf (asm_out_file, "%s:\n", p); | |
8180 | fprintf (asm_out_file, "%s\n", FIXUP_SECTION_ASM_OP); | |
8181 | fprintf (asm_out_file, "\t.picptr\t%s\n", p); | |
8182 | fprintf (asm_out_file, "\t.previous\n"); | |
8183 | } | |
8184 | assemble_integer_with_op ("\t.picptr\t", value); | |
8185 | return true; | |
8186 | } | |
8187 | if (!aligned_p) | |
8188 | { | |
8189 | /* We've set the unaligned SI op to NULL, so we always have to | |
8190 | handle the unaligned case here. */ | |
8191 | assemble_integer_with_op ("\t.4byte\t", value); | |
8192 | return true; | |
8193 | } | |
8194 | } | |
8195 | return default_assemble_integer (value, size, aligned_p); | |
8196 | } | |
8197 | ||
8198 | /* Function to set up the backend function structure. */ | |
8199 | ||
8200 | static struct machine_function * | |
8201 | frv_init_machine_status () | |
8202 | { | |
8203 | return ggc_alloc_cleared (sizeof (struct machine_function)); | |
8204 | } | |
ffb344c1 | 8205 | \f |
28a60850 RS |
8206 | /* Implement TARGET_SCHED_ISSUE_RATE. */ |
8207 | ||
8208 | static int | |
8209 | frv_issue_rate (void) | |
8210 | { | |
8211 | if (!TARGET_PACK) | |
8212 | return 1; | |
8213 | ||
8214 | switch (frv_cpu_type) | |
8215 | { | |
8216 | default: | |
8217 | case FRV_CPU_FR300: | |
8218 | case FRV_CPU_SIMPLE: | |
8219 | return 1; | |
8220 | ||
8221 | case FRV_CPU_FR400: | |
8222 | return 2; | |
8223 | ||
8224 | case FRV_CPU_GENERIC: | |
8225 | case FRV_CPU_FR500: | |
8226 | case FRV_CPU_TOMCAT: | |
8227 | return 4; | |
8228 | } | |
8229 | } | |
8230 | ||
8231 | ||
ffb344c1 | 8232 | /* Implement TARGET_SCHED_USE_DFA_PIPELINE_INTERFACE. */ |
36a05131 | 8233 | |
ffb344c1 RS |
8234 | static int |
8235 | frv_use_dfa_pipeline_interface (void) | |
8236 | { | |
8237 | return true; | |
8238 | } | |
36a05131 BS |
8239 | \f |
8240 | /* Update the register state information, to know about which registers are set | |
8241 | or clobbered. */ | |
8242 | ||
8243 | static void | |
8244 | frv_registers_update (x, reg_state, modified, p_num_mod, flag) | |
8245 | rtx x; | |
8246 | unsigned char reg_state[]; | |
8247 | int modified[]; | |
8248 | int *p_num_mod; | |
8249 | int flag; | |
8250 | { | |
8251 | int regno, reg_max; | |
8252 | rtx reg; | |
8253 | rtx cond; | |
8254 | const char *format; | |
8255 | int length; | |
8256 | int j; | |
8257 | ||
8258 | switch (GET_CODE (x)) | |
8259 | { | |
8260 | default: | |
8261 | break; | |
8262 | ||
8263 | /* Clobber just modifies a register, it doesn't make it live. */ | |
8264 | case CLOBBER: | |
8265 | frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod, | |
8266 | flag | REGSTATE_MODIFIED); | |
8267 | return; | |
8268 | ||
8269 | /* Pre modify updates the first argument, just references the second. */ | |
8270 | case PRE_MODIFY: | |
8271 | case SET: | |
8272 | frv_registers_update (XEXP (x, 0), reg_state, modified, p_num_mod, | |
8273 | flag | REGSTATE_MODIFIED | REGSTATE_LIVE); | |
8274 | frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod, flag); | |
8275 | return; | |
8276 | ||
8277 | /* For COND_EXEC, pass the appropriate flag to evaluate the conditional | |
8278 | statement, but just to be sure, make sure it is the type of cond_exec | |
8279 | we expect. */ | |
8280 | case COND_EXEC: | |
8281 | cond = XEXP (x, 0); | |
8282 | if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE) | |
8283 | && GET_CODE (XEXP (cond, 0)) == REG | |
8284 | && CR_P (REGNO (XEXP (cond, 0))) | |
8285 | && GET_CODE (XEXP (cond, 1)) == CONST_INT | |
8286 | && INTVAL (XEXP (cond, 1)) == 0 | |
8287 | && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0) | |
8288 | { | |
8289 | frv_registers_update (cond, reg_state, modified, p_num_mod, flag); | |
8290 | flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST) | |
8291 | | ((GET_CODE (cond) == NE) | |
8292 | ? REGSTATE_IF_TRUE | |
8293 | : REGSTATE_IF_FALSE)); | |
8294 | ||
8295 | frv_registers_update (XEXP (x, 1), reg_state, modified, p_num_mod, | |
8296 | flag); | |
8297 | return; | |
8298 | } | |
8299 | else | |
8300 | fatal_insn ("frv_registers_update", x); | |
8301 | ||
8302 | /* MEM resets the modification bits. */ | |
8303 | case MEM: | |
8304 | flag &= ~REGSTATE_MODIFIED; | |
8305 | break; | |
8306 | ||
8307 | /* See if we need to set the modified flag. */ | |
8308 | case SUBREG: | |
8309 | reg = SUBREG_REG (x); | |
8310 | if (GET_CODE (reg) == REG) | |
8311 | { | |
8312 | regno = subreg_regno (x); | |
8313 | reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
8314 | goto reg_common; | |
8315 | } | |
8316 | break; | |
8317 | ||
8318 | case REG: | |
8319 | regno = REGNO (x); | |
8320 | reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); | |
8321 | /* fall through */ | |
8322 | ||
8323 | reg_common: | |
8324 | if (flag & REGSTATE_MODIFIED) | |
8325 | { | |
8326 | flag &= REGSTATE_MASK; | |
8327 | while (regno < reg_max) | |
8328 | { | |
8329 | int rs = reg_state[regno]; | |
8330 | ||
8331 | if (flag != rs) | |
8332 | { | |
8333 | if ((rs & REGSTATE_MODIFIED) == 0) | |
8334 | { | |
8335 | modified[ *p_num_mod ] = regno; | |
8336 | (*p_num_mod)++; | |
8337 | } | |
8338 | ||
8339 | /* If the previous register state had the register as | |
8340 | modified, possibly in some conditional execution context, | |
8341 | and the current insn modifies in some other context, or | |
8342 | outside of conditional execution, just mark the variable | |
8343 | as modified. */ | |
8344 | else | |
8345 | flag &= ~(REGSTATE_IF_EITHER | REGSTATE_CC_MASK); | |
8346 | ||
8347 | reg_state[regno] = (rs | flag); | |
8348 | } | |
8349 | regno++; | |
8350 | } | |
8351 | } | |
8352 | return; | |
8353 | } | |
8354 | ||
8355 | ||
8356 | length = GET_RTX_LENGTH (GET_CODE (x)); | |
8357 | format = GET_RTX_FORMAT (GET_CODE (x)); | |
8358 | ||
8359 | for (j = 0; j < length; ++j) | |
8360 | { | |
8361 | switch (format[j]) | |
8362 | { | |
8363 | case 'e': | |
8364 | frv_registers_update (XEXP (x, j), reg_state, modified, p_num_mod, | |
8365 | flag); | |
8366 | break; | |
8367 | ||
8368 | case 'V': | |
8369 | case 'E': | |
8370 | if (XVEC (x, j) != 0) | |
8371 | { | |
8372 | int k; | |
8373 | for (k = 0; k < XVECLEN (x, j); ++k) | |
8374 | frv_registers_update (XVECEXP (x, j, k), reg_state, modified, | |
8375 | p_num_mod, flag); | |
8376 | } | |
8377 | break; | |
8378 | ||
8379 | default: | |
8380 | /* Nothing to do. */ | |
8381 | break; | |
8382 | } | |
8383 | } | |
8384 | ||
8385 | return; | |
8386 | } | |
8387 | ||
8388 | \f | |
8389 | /* Return if any registers in a hard register set were used an insn. */ | |
8390 | ||
8391 | static int | |
8392 | frv_registers_used_p (x, reg_state, flag) | |
8393 | rtx x; | |
8394 | unsigned char reg_state[]; | |
8395 | int flag; | |
8396 | { | |
8397 | int regno, reg_max; | |
8398 | rtx reg; | |
8399 | rtx cond; | |
8400 | rtx dest; | |
8401 | const char *format; | |
8402 | int result; | |
8403 | int length; | |
8404 | int j; | |
8405 | ||
8406 | switch (GET_CODE (x)) | |
8407 | { | |
8408 | default: | |
8409 | break; | |
8410 | ||
8411 | /* Skip clobber, that doesn't use the previous value */ | |
8412 | case CLOBBER: | |
8413 | return FALSE; | |
8414 | ||
8415 | /* For SET, if a conditional jump has occurred in the same insn, only | |
8416 | allow a set of a CR register if that register is not currently live. | |
8417 | This is because on the FR-V, B0/B1 instructions are always last. | |
8418 | Otherwise, don't look at the result, except within a MEM, but do look | |
8419 | at the source. */ | |
8420 | case SET: | |
8421 | dest = SET_DEST (x); | |
8422 | if (flag & REGSTATE_CONDJUMP | |
8423 | && GET_CODE (dest) == REG && CR_P (REGNO (dest)) | |
8424 | && (reg_state[ REGNO (dest) ] & REGSTATE_LIVE) != 0) | |
8425 | return TRUE; | |
8426 | ||
8427 | if (GET_CODE (dest) == MEM) | |
8428 | { | |
8429 | result = frv_registers_used_p (XEXP (dest, 0), reg_state, flag); | |
8430 | if (result) | |
8431 | return result; | |
8432 | } | |
8433 | ||
8434 | return frv_registers_used_p (SET_SRC (x), reg_state, flag); | |
8435 | ||
8436 | /* For COND_EXEC, pass the appropriate flag to evaluate the conditional | |
8437 | statement, but just to be sure, make sure it is the type of cond_exec | |
8438 | we expect. */ | |
8439 | case COND_EXEC: | |
8440 | cond = XEXP (x, 0); | |
8441 | if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE) | |
8442 | && GET_CODE (XEXP (cond, 0)) == REG | |
8443 | && CR_P (REGNO (XEXP (cond, 0))) | |
8444 | && GET_CODE (XEXP (cond, 1)) == CONST_INT | |
8445 | && INTVAL (XEXP (cond, 1)) == 0 | |
8446 | && (flag & (REGSTATE_MODIFIED | REGSTATE_IF_EITHER)) == 0) | |
8447 | { | |
8448 | result = frv_registers_used_p (cond, reg_state, flag); | |
8449 | if (result) | |
8450 | return result; | |
8451 | ||
8452 | flag |= ((REGNO (XEXP (cond, 0)) - CR_FIRST) | |
8453 | | ((GET_CODE (cond) == NE) | |
8454 | ? REGSTATE_IF_TRUE | |
8455 | : REGSTATE_IF_FALSE)); | |
8456 | ||
8457 | return frv_registers_used_p (XEXP (x, 1), reg_state, flag); | |
8458 | } | |
8459 | else | |
8460 | fatal_insn ("frv_registers_used_p", x); | |
8461 | ||
8462 | /* See if a register or subreg was modified in the same VLIW insn. */ | |
8463 | case SUBREG: | |
8464 | reg = SUBREG_REG (x); | |
8465 | if (GET_CODE (reg) == REG) | |
8466 | { | |
8467 | regno = subreg_regno (x); | |
8468 | reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
8469 | goto reg_common; | |
8470 | } | |
8471 | break; | |
8472 | ||
8473 | case REG: | |
8474 | regno = REGNO (x); | |
8475 | reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); | |
8476 | /* fall through */ | |
8477 | ||
8478 | reg_common: | |
8479 | while (regno < reg_max) | |
8480 | { | |
8481 | int rs = reg_state[regno]; | |
8482 | ||
8483 | if (rs & REGSTATE_MODIFIED) | |
8484 | { | |
8485 | int rs_if = rs & REGSTATE_IF_EITHER; | |
8486 | int flag_if = flag & REGSTATE_IF_EITHER; | |
8487 | ||
8488 | /* Simple modification, no conditional execution */ | |
8489 | if ((rs & REGSTATE_IF_EITHER) == 0) | |
8490 | return TRUE; | |
8491 | ||
8492 | /* See if the variable is only modified in a conditional | |
8493 | execution expression opposite to the conditional execution | |
8494 | expression that governs this expression (ie, true vs. false | |
8495 | for the same CC register). If this isn't two halves of the | |
8496 | same conditional expression, consider the register | |
8497 | modified. */ | |
8498 | if (((rs_if == REGSTATE_IF_TRUE && flag_if == REGSTATE_IF_FALSE) | |
8499 | || (rs_if == REGSTATE_IF_FALSE && flag_if == REGSTATE_IF_TRUE)) | |
8500 | && ((rs & REGSTATE_CC_MASK) == (flag & REGSTATE_CC_MASK))) | |
8501 | ; | |
8502 | else | |
8503 | return TRUE; | |
8504 | } | |
8505 | ||
8506 | regno++; | |
8507 | } | |
8508 | return FALSE; | |
8509 | } | |
8510 | ||
8511 | ||
8512 | length = GET_RTX_LENGTH (GET_CODE (x)); | |
8513 | format = GET_RTX_FORMAT (GET_CODE (x)); | |
8514 | ||
8515 | for (j = 0; j < length; ++j) | |
8516 | { | |
8517 | switch (format[j]) | |
8518 | { | |
8519 | case 'e': | |
8520 | result = frv_registers_used_p (XEXP (x, j), reg_state, flag); | |
8521 | if (result != 0) | |
8522 | return result; | |
8523 | break; | |
8524 | ||
8525 | case 'V': | |
8526 | case 'E': | |
8527 | if (XVEC (x, j) != 0) | |
8528 | { | |
8529 | int k; | |
8530 | for (k = 0; k < XVECLEN (x, j); ++k) | |
8531 | { | |
8532 | result = frv_registers_used_p (XVECEXP (x, j, k), reg_state, | |
8533 | flag); | |
8534 | if (result != 0) | |
8535 | return result; | |
8536 | } | |
8537 | } | |
8538 | break; | |
8539 | ||
8540 | default: | |
8541 | /* Nothing to do. */ | |
8542 | break; | |
8543 | } | |
8544 | } | |
8545 | ||
8546 | return 0; | |
8547 | } | |
8548 | ||
8549 | /* Return if any registers in a hard register set were set in an insn. */ | |
8550 | ||
8551 | static int | |
8552 | frv_registers_set_p (x, reg_state, modify_p) | |
8553 | rtx x; | |
8554 | unsigned char reg_state[]; | |
8555 | int modify_p; | |
8556 | { | |
8557 | int regno, reg_max; | |
8558 | rtx reg; | |
8559 | rtx cond; | |
8560 | const char *format; | |
8561 | int length; | |
8562 | int j; | |
8563 | ||
8564 | switch (GET_CODE (x)) | |
8565 | { | |
8566 | default: | |
8567 | break; | |
8568 | ||
8569 | case CLOBBER: | |
8570 | return frv_registers_set_p (XEXP (x, 0), reg_state, TRUE); | |
8571 | ||
8572 | case PRE_MODIFY: | |
8573 | case SET: | |
8574 | return (frv_registers_set_p (XEXP (x, 0), reg_state, TRUE) | |
8575 | || frv_registers_set_p (XEXP (x, 1), reg_state, FALSE)); | |
8576 | ||
8577 | case COND_EXEC: | |
8578 | cond = XEXP (x, 0); | |
8579 | /* just to be sure, make sure it is the type of cond_exec we | |
8580 | expect. */ | |
8581 | if ((GET_CODE (cond) == EQ || GET_CODE (cond) == NE) | |
8582 | && GET_CODE (XEXP (cond, 0)) == REG | |
8583 | && CR_P (REGNO (XEXP (cond, 0))) | |
8584 | && GET_CODE (XEXP (cond, 1)) == CONST_INT | |
8585 | && INTVAL (XEXP (cond, 1)) == 0 | |
8586 | && !modify_p) | |
8587 | return frv_registers_set_p (XEXP (x, 1), reg_state, modify_p); | |
8588 | else | |
8589 | fatal_insn ("frv_registers_set_p", x); | |
8590 | ||
8591 | /* MEM resets the modification bits. */ | |
8592 | case MEM: | |
8593 | modify_p = FALSE; | |
8594 | break; | |
8595 | ||
8596 | /* See if we need to set the modified modify_p. */ | |
8597 | case SUBREG: | |
8598 | reg = SUBREG_REG (x); | |
8599 | if (GET_CODE (reg) == REG) | |
8600 | { | |
8601 | regno = subreg_regno (x); | |
8602 | reg_max = REGNO (reg) + HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
8603 | goto reg_common; | |
8604 | } | |
8605 | break; | |
8606 | ||
8607 | case REG: | |
8608 | regno = REGNO (x); | |
8609 | reg_max = regno + HARD_REGNO_NREGS (regno, GET_MODE (x)); | |
8610 | /* fall through */ | |
8611 | ||
8612 | reg_common: | |
8613 | if (modify_p) | |
8614 | while (regno < reg_max) | |
8615 | { | |
8616 | int rs = reg_state[regno]; | |
8617 | ||
8618 | if (rs & REGSTATE_MODIFIED) | |
8619 | return TRUE; | |
8620 | regno++; | |
8621 | } | |
8622 | return FALSE; | |
8623 | } | |
8624 | ||
8625 | ||
8626 | length = GET_RTX_LENGTH (GET_CODE (x)); | |
8627 | format = GET_RTX_FORMAT (GET_CODE (x)); | |
8628 | ||
8629 | for (j = 0; j < length; ++j) | |
8630 | { | |
8631 | switch (format[j]) | |
8632 | { | |
8633 | case 'e': | |
8634 | if (frv_registers_set_p (XEXP (x, j), reg_state, modify_p)) | |
8635 | return TRUE; | |
8636 | break; | |
8637 | ||
8638 | case 'V': | |
8639 | case 'E': | |
8640 | if (XVEC (x, j) != 0) | |
8641 | { | |
8642 | int k; | |
8643 | for (k = 0; k < XVECLEN (x, j); ++k) | |
8644 | if (frv_registers_set_p (XVECEXP (x, j, k), reg_state, | |
8645 | modify_p)) | |
8646 | return TRUE; | |
8647 | } | |
8648 | break; | |
8649 | ||
8650 | default: | |
8651 | /* Nothing to do. */ | |
8652 | break; | |
8653 | } | |
8654 | } | |
8655 | ||
8656 | return FALSE; | |
8657 | } | |
8658 | ||
8659 | \f | |
36a05131 BS |
8660 | /* On the FR-V, this pass is used to rescan the insn chain, and pack |
8661 | conditional branches/calls/jumps, etc. with previous insns where it can. It | |
8662 | does not reorder the instructions. We assume the scheduler left the flow | |
8663 | information in a reasonable state. */ | |
8664 | ||
8665 | static void | |
8666 | frv_pack_insns () | |
8667 | { | |
8668 | state_t frv_state; /* frv state machine */ | |
8669 | int cur_start_vliw_p; /* current insn starts a VLIW insn */ | |
8670 | int next_start_vliw_p; /* next insn starts a VLIW insn */ | |
8671 | int cur_condjump_p; /* flag if current insn is a cond jump*/ | |
8672 | int next_condjump_p; /* flag if next insn is a cond jump */ | |
8673 | rtx insn; | |
8674 | rtx link; | |
8675 | int j; | |
8676 | int num_mod = 0; /* # of modified registers */ | |
8677 | int modified[FIRST_PSEUDO_REGISTER]; /* registers modified in current VLIW */ | |
8678 | /* register state information */ | |
8679 | unsigned char reg_state[FIRST_PSEUDO_REGISTER]; | |
8680 | ||
8681 | /* If we weren't going to pack the insns, don't bother with this pass. */ | |
28a60850 RS |
8682 | if (!optimize |
8683 | || !flag_schedule_insns_after_reload | |
8684 | || TARGET_NO_VLIW_BRANCH | |
8685 | || frv_issue_rate () == 1) | |
36a05131 BS |
8686 | return; |
8687 | ||
36a05131 BS |
8688 | /* Set up the instruction and register states. */ |
8689 | dfa_start (); | |
8690 | frv_state = (state_t) xmalloc (state_size ()); | |
fad205ff | 8691 | memset (reg_state, REGSTATE_DEAD, sizeof (reg_state)); |
36a05131 BS |
8692 | |
8693 | /* Go through the insns, and repack the insns. */ | |
8694 | state_reset (frv_state); | |
8695 | cur_start_vliw_p = FALSE; | |
8696 | next_start_vliw_p = TRUE; | |
8697 | cur_condjump_p = 0; | |
8698 | next_condjump_p = 0; | |
8699 | ||
8700 | for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn)) | |
8701 | { | |
8702 | enum rtx_code code = GET_CODE (insn); | |
8703 | enum rtx_code pattern_code; | |
8704 | ||
8705 | /* For basic block begin notes redo the live information, and skip other | |
8706 | notes. */ | |
8707 | if (code == NOTE) | |
8708 | { | |
8709 | if (NOTE_LINE_NUMBER (insn) == (int)NOTE_INSN_BASIC_BLOCK) | |
8710 | { | |
8711 | regset live; | |
8712 | ||
8713 | for (j = 0; j < FIRST_PSEUDO_REGISTER; j++) | |
8714 | reg_state[j] &= ~ REGSTATE_LIVE; | |
8715 | ||
8716 | live = NOTE_BASIC_BLOCK (insn)->global_live_at_start; | |
8717 | EXECUTE_IF_SET_IN_REG_SET(live, 0, j, | |
8718 | { | |
8719 | reg_state[j] |= REGSTATE_LIVE; | |
8720 | }); | |
8721 | } | |
8722 | ||
8723 | continue; | |
8724 | } | |
8725 | ||
8726 | /* things like labels reset everything. */ | |
8727 | if (GET_RTX_CLASS (code) != 'i') | |
8728 | { | |
8729 | next_start_vliw_p = TRUE; | |
8730 | continue; | |
8731 | } | |
8732 | ||
8733 | /* Clear the VLIW start flag on random USE and CLOBBER insns, which is | |
8734 | set on the USE insn that preceeds the return, and potentially on | |
8735 | CLOBBERs for setting multiword variables. Also skip the ADDR_VEC | |
8736 | holding the case table labels. */ | |
8737 | pattern_code = GET_CODE (PATTERN (insn)); | |
8738 | if (pattern_code == USE || pattern_code == CLOBBER | |
8739 | || pattern_code == ADDR_VEC || pattern_code == ADDR_DIFF_VEC) | |
8740 | { | |
8741 | CLEAR_VLIW_START (insn); | |
8742 | continue; | |
8743 | } | |
8744 | ||
8745 | cur_start_vliw_p = next_start_vliw_p; | |
8746 | next_start_vliw_p = FALSE; | |
8747 | ||
8748 | cur_condjump_p |= next_condjump_p; | |
8749 | next_condjump_p = 0; | |
8750 | ||
8751 | /* Unconditional branches and calls end the current VLIW insn. */ | |
8752 | if (code == CALL_INSN) | |
8753 | { | |
8754 | next_start_vliw_p = TRUE; | |
8755 | ||
8756 | /* On a TOMCAT, calls must be alone in the VLIW insns. */ | |
8757 | if (frv_cpu_type == FRV_CPU_TOMCAT) | |
8758 | cur_start_vliw_p = TRUE; | |
8759 | } | |
8760 | else if (code == JUMP_INSN) | |
8761 | { | |
8762 | if (any_condjump_p (insn)) | |
8763 | next_condjump_p = REGSTATE_CONDJUMP; | |
8764 | else | |
8765 | next_start_vliw_p = TRUE; | |
8766 | } | |
8767 | ||
8768 | /* Only allow setting a CCR register after a conditional branch. */ | |
8769 | else if (((cur_condjump_p & REGSTATE_CONDJUMP) != 0) | |
8770 | && get_attr_type (insn) != TYPE_CCR) | |
8771 | cur_start_vliw_p = TRUE; | |
8772 | ||
8773 | /* Determine if we need to start a new VLIW instruction. */ | |
8774 | if (cur_start_vliw_p | |
8775 | /* Do not check for register conflicts in a setlo instruction | |
8776 | because any output or true dependencies will be with the | |
8777 | partnering sethi instruction, with which it can be packed. | |
8778 | ||
8779 | Although output dependencies are rare they are still | |
8780 | possible. So check output dependencies in VLIW insn. */ | |
8781 | || (get_attr_type (insn) != TYPE_SETLO | |
8782 | && (frv_registers_used_p (PATTERN (insn), | |
8783 | reg_state, | |
8784 | cur_condjump_p) | |
8785 | || frv_registers_set_p (PATTERN (insn), reg_state, FALSE))) | |
8786 | || state_transition (frv_state, insn) >= 0) | |
8787 | { | |
8788 | SET_VLIW_START (insn); | |
8789 | state_reset (frv_state); | |
8790 | state_transition (frv_state, insn); | |
8791 | cur_condjump_p = 0; | |
8792 | ||
8793 | /* Update the modified registers. */ | |
8794 | for (j = 0; j < num_mod; j++) | |
8795 | reg_state[ modified[j] ] &= ~(REGSTATE_CC_MASK | |
8796 | | REGSTATE_IF_EITHER | |
8797 | | REGSTATE_MODIFIED); | |
8798 | ||
8799 | num_mod = 0; | |
8800 | } | |
8801 | else | |
8802 | CLEAR_VLIW_START (insn); | |
8803 | ||
8804 | /* Record which registers are modified. */ | |
8805 | frv_registers_update (PATTERN (insn), reg_state, modified, &num_mod, 0); | |
8806 | ||
8807 | /* Process the death notices */ | |
8808 | for (link = REG_NOTES (insn); | |
8809 | link != NULL_RTX; | |
8810 | link = XEXP (link, 1)) | |
8811 | { | |
8812 | rtx reg = XEXP (link, 0); | |
8813 | ||
8814 | if (REG_NOTE_KIND (link) == REG_DEAD && GET_CODE (reg) == REG) | |
8815 | { | |
8816 | int regno = REGNO (reg); | |
8817 | int n = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg)); | |
8818 | for (; regno < n; regno++) | |
8819 | reg_state[regno] &= ~REGSTATE_LIVE; | |
8820 | } | |
8821 | } | |
8822 | } | |
8823 | ||
fad205ff | 8824 | free (frv_state); |
36a05131 BS |
8825 | dfa_finish (); |
8826 | return; | |
8827 | } | |
8828 | ||
8829 | \f | |
8830 | #define def_builtin(name, type, code) \ | |
8831 | builtin_function ((name), (type), (code), BUILT_IN_MD, NULL, NULL) | |
8832 | ||
8833 | struct builtin_description | |
8834 | { | |
8835 | enum insn_code icode; | |
8836 | const char *name; | |
8837 | enum frv_builtins code; | |
8838 | enum rtx_code comparison; | |
8839 | unsigned int flag; | |
8840 | }; | |
8841 | ||
8842 | /* Media intrinsics that take a single, constant argument. */ | |
8843 | ||
8844 | static struct builtin_description bdesc_set[] = | |
8845 | { | |
8846 | { CODE_FOR_mhdsets, "__MHDSETS", FRV_BUILTIN_MHDSETS, 0, 0 } | |
8847 | }; | |
8848 | ||
8849 | /* Media intrinsics that take just one argument. */ | |
8850 | ||
8851 | static struct builtin_description bdesc_1arg[] = | |
8852 | { | |
8853 | { CODE_FOR_mnot, "__MNOT", FRV_BUILTIN_MNOT, 0, 0 }, | |
8854 | { CODE_FOR_munpackh, "__MUNPACKH", FRV_BUILTIN_MUNPACKH, 0, 0 }, | |
8855 | { CODE_FOR_mbtoh, "__MBTOH", FRV_BUILTIN_MBTOH, 0, 0 }, | |
8856 | { CODE_FOR_mhtob, "__MHTOB", FRV_BUILTIN_MHTOB, 0, 0 }, | |
8857 | { CODE_FOR_mabshs, "__MABSHS", FRV_BUILTIN_MABSHS, 0, 0 } | |
8858 | }; | |
8859 | ||
8860 | /* Media intrinsics that take two arguments. */ | |
8861 | ||
8862 | static struct builtin_description bdesc_2arg[] = | |
8863 | { | |
8864 | { CODE_FOR_mand, "__MAND", FRV_BUILTIN_MAND, 0, 0 }, | |
8865 | { CODE_FOR_mor, "__MOR", FRV_BUILTIN_MOR, 0, 0 }, | |
8866 | { CODE_FOR_mxor, "__MXOR", FRV_BUILTIN_MXOR, 0, 0 }, | |
8867 | { CODE_FOR_maveh, "__MAVEH", FRV_BUILTIN_MAVEH, 0, 0 }, | |
8868 | { CODE_FOR_msaths, "__MSATHS", FRV_BUILTIN_MSATHS, 0, 0 }, | |
8869 | { CODE_FOR_msathu, "__MSATHU", FRV_BUILTIN_MSATHU, 0, 0 }, | |
8870 | { CODE_FOR_maddhss, "__MADDHSS", FRV_BUILTIN_MADDHSS, 0, 0 }, | |
8871 | { CODE_FOR_maddhus, "__MADDHUS", FRV_BUILTIN_MADDHUS, 0, 0 }, | |
8872 | { CODE_FOR_msubhss, "__MSUBHSS", FRV_BUILTIN_MSUBHSS, 0, 0 }, | |
8873 | { CODE_FOR_msubhus, "__MSUBHUS", FRV_BUILTIN_MSUBHUS, 0, 0 }, | |
8874 | { CODE_FOR_mqaddhss, "__MQADDHSS", FRV_BUILTIN_MQADDHSS, 0, 0 }, | |
8875 | { CODE_FOR_mqaddhus, "__MQADDHUS", FRV_BUILTIN_MQADDHUS, 0, 0 }, | |
8876 | { CODE_FOR_mqsubhss, "__MQSUBHSS", FRV_BUILTIN_MQSUBHSS, 0, 0 }, | |
8877 | { CODE_FOR_mqsubhus, "__MQSUBHUS", FRV_BUILTIN_MQSUBHUS, 0, 0 }, | |
8878 | { CODE_FOR_mpackh, "__MPACKH", FRV_BUILTIN_MPACKH, 0, 0 }, | |
8879 | { CODE_FOR_mdpackh, "__MDPACKH", FRV_BUILTIN_MDPACKH, 0, 0 }, | |
8880 | { CODE_FOR_mcop1, "__Mcop1", FRV_BUILTIN_MCOP1, 0, 0 }, | |
8881 | { CODE_FOR_mcop2, "__Mcop2", FRV_BUILTIN_MCOP2, 0, 0 }, | |
8882 | { CODE_FOR_mwcut, "__MWCUT", FRV_BUILTIN_MWCUT, 0, 0 }, | |
8883 | { CODE_FOR_mqsaths, "__MQSATHS", FRV_BUILTIN_MQSATHS, 0, 0 } | |
8884 | }; | |
8885 | ||
8886 | /* Media intrinsics that take two arguments, the first being an ACC number. */ | |
8887 | ||
8888 | static struct builtin_description bdesc_cut[] = | |
8889 | { | |
8890 | { CODE_FOR_mcut, "__MCUT", FRV_BUILTIN_MCUT, 0, 0 }, | |
8891 | { CODE_FOR_mcutss, "__MCUTSS", FRV_BUILTIN_MCUTSS, 0, 0 }, | |
8892 | { CODE_FOR_mdcutssi, "__MDCUTSSI", FRV_BUILTIN_MDCUTSSI, 0, 0 } | |
8893 | }; | |
8894 | ||
8895 | /* Two-argument media intrinsics with an immediate second argument. */ | |
8896 | ||
8897 | static struct builtin_description bdesc_2argimm[] = | |
8898 | { | |
8899 | { CODE_FOR_mrotli, "__MROTLI", FRV_BUILTIN_MROTLI, 0, 0 }, | |
8900 | { CODE_FOR_mrotri, "__MROTRI", FRV_BUILTIN_MROTRI, 0, 0 }, | |
8901 | { CODE_FOR_msllhi, "__MSLLHI", FRV_BUILTIN_MSLLHI, 0, 0 }, | |
8902 | { CODE_FOR_msrlhi, "__MSRLHI", FRV_BUILTIN_MSRLHI, 0, 0 }, | |
8903 | { CODE_FOR_msrahi, "__MSRAHI", FRV_BUILTIN_MSRAHI, 0, 0 }, | |
8904 | { CODE_FOR_mexpdhw, "__MEXPDHW", FRV_BUILTIN_MEXPDHW, 0, 0 }, | |
8905 | { CODE_FOR_mexpdhd, "__MEXPDHD", FRV_BUILTIN_MEXPDHD, 0, 0 }, | |
8906 | { CODE_FOR_mdrotli, "__MDROTLI", FRV_BUILTIN_MDROTLI, 0, 0 }, | |
8907 | { CODE_FOR_mcplhi, "__MCPLHI", FRV_BUILTIN_MCPLHI, 0, 0 }, | |
8908 | { CODE_FOR_mcpli, "__MCPLI", FRV_BUILTIN_MCPLI, 0, 0 }, | |
8909 | { CODE_FOR_mhsetlos, "__MHSETLOS", FRV_BUILTIN_MHSETLOS, 0, 0 }, | |
8910 | { CODE_FOR_mhsetloh, "__MHSETLOH", FRV_BUILTIN_MHSETLOH, 0, 0 }, | |
8911 | { CODE_FOR_mhsethis, "__MHSETHIS", FRV_BUILTIN_MHSETHIS, 0, 0 }, | |
8912 | { CODE_FOR_mhsethih, "__MHSETHIH", FRV_BUILTIN_MHSETHIH, 0, 0 }, | |
8913 | { CODE_FOR_mhdseth, "__MHDSETH", FRV_BUILTIN_MHDSETH, 0, 0 } | |
8914 | }; | |
8915 | ||
8916 | /* Media intrinsics that take two arguments and return void, the first argument | |
8917 | being a pointer to 4 words in memory. */ | |
8918 | ||
8919 | static struct builtin_description bdesc_void2arg[] = | |
8920 | { | |
8921 | { CODE_FOR_mdunpackh, "__MDUNPACKH", FRV_BUILTIN_MDUNPACKH, 0, 0 }, | |
8922 | { CODE_FOR_mbtohe, "__MBTOHE", FRV_BUILTIN_MBTOHE, 0, 0 }, | |
8923 | }; | |
8924 | ||
8925 | /* Media intrinsics that take three arguments, the first being a const_int that | |
8926 | denotes an accumulator, and that return void. */ | |
8927 | ||
8928 | static struct builtin_description bdesc_void3arg[] = | |
8929 | { | |
8930 | { CODE_FOR_mcpxrs, "__MCPXRS", FRV_BUILTIN_MCPXRS, 0, 0 }, | |
8931 | { CODE_FOR_mcpxru, "__MCPXRU", FRV_BUILTIN_MCPXRU, 0, 0 }, | |
8932 | { CODE_FOR_mcpxis, "__MCPXIS", FRV_BUILTIN_MCPXIS, 0, 0 }, | |
8933 | { CODE_FOR_mcpxiu, "__MCPXIU", FRV_BUILTIN_MCPXIU, 0, 0 }, | |
8934 | { CODE_FOR_mmulhs, "__MMULHS", FRV_BUILTIN_MMULHS, 0, 0 }, | |
8935 | { CODE_FOR_mmulhu, "__MMULHU", FRV_BUILTIN_MMULHU, 0, 0 }, | |
8936 | { CODE_FOR_mmulxhs, "__MMULXHS", FRV_BUILTIN_MMULXHS, 0, 0 }, | |
8937 | { CODE_FOR_mmulxhu, "__MMULXHU", FRV_BUILTIN_MMULXHU, 0, 0 }, | |
8938 | { CODE_FOR_mmachs, "__MMACHS", FRV_BUILTIN_MMACHS, 0, 0 }, | |
8939 | { CODE_FOR_mmachu, "__MMACHU", FRV_BUILTIN_MMACHU, 0, 0 }, | |
8940 | { CODE_FOR_mmrdhs, "__MMRDHS", FRV_BUILTIN_MMRDHS, 0, 0 }, | |
8941 | { CODE_FOR_mmrdhu, "__MMRDHU", FRV_BUILTIN_MMRDHU, 0, 0 }, | |
8942 | { CODE_FOR_mqcpxrs, "__MQCPXRS", FRV_BUILTIN_MQCPXRS, 0, 0 }, | |
8943 | { CODE_FOR_mqcpxru, "__MQCPXRU", FRV_BUILTIN_MQCPXRU, 0, 0 }, | |
8944 | { CODE_FOR_mqcpxis, "__MQCPXIS", FRV_BUILTIN_MQCPXIS, 0, 0 }, | |
8945 | { CODE_FOR_mqcpxiu, "__MQCPXIU", FRV_BUILTIN_MQCPXIU, 0, 0 }, | |
8946 | { CODE_FOR_mqmulhs, "__MQMULHS", FRV_BUILTIN_MQMULHS, 0, 0 }, | |
8947 | { CODE_FOR_mqmulhu, "__MQMULHU", FRV_BUILTIN_MQMULHU, 0, 0 }, | |
8948 | { CODE_FOR_mqmulxhs, "__MQMULXHS", FRV_BUILTIN_MQMULXHS, 0, 0 }, | |
8949 | { CODE_FOR_mqmulxhu, "__MQMULXHU", FRV_BUILTIN_MQMULXHU, 0, 0 }, | |
8950 | { CODE_FOR_mqmachs, "__MQMACHS", FRV_BUILTIN_MQMACHS, 0, 0 }, | |
8951 | { CODE_FOR_mqmachu, "__MQMACHU", FRV_BUILTIN_MQMACHU, 0, 0 }, | |
8952 | { CODE_FOR_mqxmachs, "__MQXMACHS", FRV_BUILTIN_MQXMACHS, 0, 0 }, | |
8953 | { CODE_FOR_mqxmacxhs, "__MQXMACXHS", FRV_BUILTIN_MQXMACXHS, 0, 0 }, | |
8954 | { CODE_FOR_mqmacxhs, "__MQMACXHS", FRV_BUILTIN_MQMACXHS, 0, 0 } | |
8955 | }; | |
8956 | ||
8957 | /* Media intrinsics that take two accumulator numbers as argument and | |
8958 | return void. */ | |
8959 | ||
8960 | static struct builtin_description bdesc_voidacc[] = | |
8961 | { | |
8962 | { CODE_FOR_maddaccs, "__MADDACCS", FRV_BUILTIN_MADDACCS, 0, 0 }, | |
8963 | { CODE_FOR_msubaccs, "__MSUBACCS", FRV_BUILTIN_MSUBACCS, 0, 0 }, | |
8964 | { CODE_FOR_masaccs, "__MASACCS", FRV_BUILTIN_MASACCS, 0, 0 }, | |
8965 | { CODE_FOR_mdaddaccs, "__MDADDACCS", FRV_BUILTIN_MDADDACCS, 0, 0 }, | |
8966 | { CODE_FOR_mdsubaccs, "__MDSUBACCS", FRV_BUILTIN_MDSUBACCS, 0, 0 }, | |
8967 | { CODE_FOR_mdasaccs, "__MDASACCS", FRV_BUILTIN_MDASACCS, 0, 0 } | |
8968 | }; | |
8969 | ||
8970 | /* Initialize media builtins. */ | |
8971 | ||
14966b94 | 8972 | static void |
36a05131 BS |
8973 | frv_init_builtins () |
8974 | { | |
8975 | tree endlink = void_list_node; | |
8976 | tree accumulator = integer_type_node; | |
8977 | tree integer = integer_type_node; | |
8978 | tree voidt = void_type_node; | |
8979 | tree uhalf = short_unsigned_type_node; | |
8980 | tree sword1 = long_integer_type_node; | |
8981 | tree uword1 = long_unsigned_type_node; | |
8982 | tree sword2 = long_long_integer_type_node; | |
8983 | tree uword2 = long_long_unsigned_type_node; | |
8984 | tree uword4 = build_pointer_type (uword1); | |
8985 | ||
8986 | #define UNARY(RET, T1) \ | |
8987 | build_function_type (RET, tree_cons (NULL_TREE, T1, endlink)) | |
8988 | ||
8989 | #define BINARY(RET, T1, T2) \ | |
8990 | build_function_type (RET, tree_cons (NULL_TREE, T1, \ | |
8991 | tree_cons (NULL_TREE, T2, endlink))) | |
8992 | ||
8993 | #define TRINARY(RET, T1, T2, T3) \ | |
8994 | build_function_type (RET, tree_cons (NULL_TREE, T1, \ | |
8995 | tree_cons (NULL_TREE, T2, \ | |
8996 | tree_cons (NULL_TREE, T3, endlink)))) | |
8997 | ||
8998 | tree void_ftype_void = build_function_type (voidt, endlink); | |
8999 | ||
9000 | tree void_ftype_acc = UNARY (voidt, accumulator); | |
9001 | tree void_ftype_uw4_uw1 = BINARY (voidt, uword4, uword1); | |
9002 | tree void_ftype_uw4_uw2 = BINARY (voidt, uword4, uword2); | |
9003 | tree void_ftype_acc_uw1 = BINARY (voidt, accumulator, uword1); | |
9004 | tree void_ftype_acc_acc = BINARY (voidt, accumulator, accumulator); | |
9005 | tree void_ftype_acc_uw1_uw1 = TRINARY (voidt, accumulator, uword1, uword1); | |
9006 | tree void_ftype_acc_sw1_sw1 = TRINARY (voidt, accumulator, sword1, sword1); | |
9007 | tree void_ftype_acc_uw2_uw2 = TRINARY (voidt, accumulator, uword2, uword2); | |
9008 | tree void_ftype_acc_sw2_sw2 = TRINARY (voidt, accumulator, sword2, sword2); | |
9009 | ||
9010 | tree uw1_ftype_uw1 = UNARY (uword1, uword1); | |
9011 | tree uw1_ftype_sw1 = UNARY (uword1, sword1); | |
9012 | tree uw1_ftype_uw2 = UNARY (uword1, uword2); | |
9013 | tree uw1_ftype_acc = UNARY (uword1, accumulator); | |
9014 | tree uw1_ftype_uh_uh = BINARY (uword1, uhalf, uhalf); | |
9015 | tree uw1_ftype_uw1_uw1 = BINARY (uword1, uword1, uword1); | |
9016 | tree uw1_ftype_uw1_int = BINARY (uword1, uword1, integer); | |
9017 | tree uw1_ftype_acc_uw1 = BINARY (uword1, accumulator, uword1); | |
9018 | tree uw1_ftype_acc_sw1 = BINARY (uword1, accumulator, sword1); | |
9019 | tree uw1_ftype_uw2_uw1 = BINARY (uword1, uword2, uword1); | |
9020 | tree uw1_ftype_uw2_int = BINARY (uword1, uword2, integer); | |
9021 | ||
9022 | tree sw1_ftype_int = UNARY (sword1, integer); | |
9023 | tree sw1_ftype_sw1_sw1 = BINARY (sword1, sword1, sword1); | |
9024 | tree sw1_ftype_sw1_int = BINARY (sword1, sword1, integer); | |
9025 | ||
9026 | tree uw2_ftype_uw1 = UNARY (uword2, uword1); | |
9027 | tree uw2_ftype_uw1_int = BINARY (uword2, uword1, integer); | |
9028 | tree uw2_ftype_uw2_uw2 = BINARY (uword2, uword2, uword2); | |
9029 | tree uw2_ftype_uw2_int = BINARY (uword2, uword2, integer); | |
9030 | tree uw2_ftype_acc_int = BINARY (uword2, accumulator, integer); | |
9031 | ||
9032 | tree sw2_ftype_sw2_sw2 = BINARY (sword2, sword2, sword2); | |
9033 | ||
9034 | def_builtin ("__MAND", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAND); | |
9035 | def_builtin ("__MOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MOR); | |
9036 | def_builtin ("__MXOR", uw1_ftype_uw1_uw1, FRV_BUILTIN_MXOR); | |
9037 | def_builtin ("__MNOT", uw1_ftype_uw1, FRV_BUILTIN_MNOT); | |
9038 | def_builtin ("__MROTLI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTLI); | |
9039 | def_builtin ("__MROTRI", uw1_ftype_uw1_int, FRV_BUILTIN_MROTRI); | |
9040 | def_builtin ("__MWCUT", uw1_ftype_uw2_uw1, FRV_BUILTIN_MWCUT); | |
9041 | def_builtin ("__MAVEH", uw1_ftype_uw1_uw1, FRV_BUILTIN_MAVEH); | |
9042 | def_builtin ("__MSLLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSLLHI); | |
9043 | def_builtin ("__MSRLHI", uw1_ftype_uw1_int, FRV_BUILTIN_MSRLHI); | |
9044 | def_builtin ("__MSRAHI", sw1_ftype_sw1_int, FRV_BUILTIN_MSRAHI); | |
9045 | def_builtin ("__MSATHS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSATHS); | |
9046 | def_builtin ("__MSATHU", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSATHU); | |
9047 | def_builtin ("__MADDHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MADDHSS); | |
9048 | def_builtin ("__MADDHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MADDHUS); | |
9049 | def_builtin ("__MSUBHSS", sw1_ftype_sw1_sw1, FRV_BUILTIN_MSUBHSS); | |
9050 | def_builtin ("__MSUBHUS", uw1_ftype_uw1_uw1, FRV_BUILTIN_MSUBHUS); | |
9051 | def_builtin ("__MMULHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULHS); | |
9052 | def_builtin ("__MMULHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULHU); | |
9053 | def_builtin ("__MMULXHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMULXHS); | |
9054 | def_builtin ("__MMULXHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMULXHU); | |
9055 | def_builtin ("__MMACHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMACHS); | |
9056 | def_builtin ("__MMACHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMACHU); | |
9057 | def_builtin ("__MMRDHS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MMRDHS); | |
9058 | def_builtin ("__MMRDHU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MMRDHU); | |
9059 | def_builtin ("__MQADDHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQADDHSS); | |
9060 | def_builtin ("__MQADDHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQADDHUS); | |
9061 | def_builtin ("__MQSUBHSS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSUBHSS); | |
9062 | def_builtin ("__MQSUBHUS", uw2_ftype_uw2_uw2, FRV_BUILTIN_MQSUBHUS); | |
9063 | def_builtin ("__MQMULHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULHS); | |
9064 | def_builtin ("__MQMULHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULHU); | |
9065 | def_builtin ("__MQMULXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMULXHS); | |
9066 | def_builtin ("__MQMULXHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMULXHU); | |
9067 | def_builtin ("__MQMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACHS); | |
9068 | def_builtin ("__MQMACHU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQMACHU); | |
9069 | def_builtin ("__MCPXRS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXRS); | |
9070 | def_builtin ("__MCPXRU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXRU); | |
9071 | def_builtin ("__MCPXIS", void_ftype_acc_sw1_sw1, FRV_BUILTIN_MCPXIS); | |
9072 | def_builtin ("__MCPXIU", void_ftype_acc_uw1_uw1, FRV_BUILTIN_MCPXIU); | |
9073 | def_builtin ("__MQCPXRS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXRS); | |
9074 | def_builtin ("__MQCPXRU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXRU); | |
9075 | def_builtin ("__MQCPXIS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQCPXIS); | |
9076 | def_builtin ("__MQCPXIU", void_ftype_acc_uw2_uw2, FRV_BUILTIN_MQCPXIU); | |
9077 | def_builtin ("__MCUT", uw1_ftype_acc_uw1, FRV_BUILTIN_MCUT); | |
9078 | def_builtin ("__MCUTSS", uw1_ftype_acc_sw1, FRV_BUILTIN_MCUTSS); | |
9079 | def_builtin ("__MEXPDHW", uw1_ftype_uw1_int, FRV_BUILTIN_MEXPDHW); | |
9080 | def_builtin ("__MEXPDHD", uw2_ftype_uw1_int, FRV_BUILTIN_MEXPDHD); | |
9081 | def_builtin ("__MPACKH", uw1_ftype_uh_uh, FRV_BUILTIN_MPACKH); | |
9082 | def_builtin ("__MUNPACKH", uw2_ftype_uw1, FRV_BUILTIN_MUNPACKH); | |
9083 | def_builtin ("__MDPACKH", uw2_ftype_uw2_uw2, FRV_BUILTIN_MDPACKH); | |
b16c1435 | 9084 | def_builtin ("__MDUNPACKH", void_ftype_uw4_uw2, FRV_BUILTIN_MDUNPACKH); |
36a05131 BS |
9085 | def_builtin ("__MBTOH", uw2_ftype_uw1, FRV_BUILTIN_MBTOH); |
9086 | def_builtin ("__MHTOB", uw1_ftype_uw2, FRV_BUILTIN_MHTOB); | |
9087 | def_builtin ("__MBTOHE", void_ftype_uw4_uw1, FRV_BUILTIN_MBTOHE); | |
9088 | def_builtin ("__MCLRACC", void_ftype_acc, FRV_BUILTIN_MCLRACC); | |
9089 | def_builtin ("__MCLRACCA", void_ftype_void, FRV_BUILTIN_MCLRACCA); | |
9090 | def_builtin ("__MRDACC", uw1_ftype_acc, FRV_BUILTIN_MRDACC); | |
9091 | def_builtin ("__MRDACCG", uw1_ftype_acc, FRV_BUILTIN_MRDACCG); | |
9092 | def_builtin ("__MWTACC", void_ftype_acc_uw1, FRV_BUILTIN_MWTACC); | |
9093 | def_builtin ("__MWTACCG", void_ftype_acc_uw1, FRV_BUILTIN_MWTACCG); | |
9094 | def_builtin ("__Mcop1", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP1); | |
9095 | def_builtin ("__Mcop2", uw1_ftype_uw1_uw1, FRV_BUILTIN_MCOP2); | |
9096 | def_builtin ("__MTRAP", void_ftype_void, FRV_BUILTIN_MTRAP); | |
9097 | def_builtin ("__MQXMACHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACHS); | |
9098 | def_builtin ("__MQXMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQXMACXHS); | |
9099 | def_builtin ("__MQMACXHS", void_ftype_acc_sw2_sw2, FRV_BUILTIN_MQMACXHS); | |
9100 | def_builtin ("__MADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MADDACCS); | |
9101 | def_builtin ("__MSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MSUBACCS); | |
9102 | def_builtin ("__MASACCS", void_ftype_acc_acc, FRV_BUILTIN_MASACCS); | |
9103 | def_builtin ("__MDADDACCS", void_ftype_acc_acc, FRV_BUILTIN_MDADDACCS); | |
9104 | def_builtin ("__MDSUBACCS", void_ftype_acc_acc, FRV_BUILTIN_MDSUBACCS); | |
9105 | def_builtin ("__MDASACCS", void_ftype_acc_acc, FRV_BUILTIN_MDASACCS); | |
9106 | def_builtin ("__MABSHS", uw1_ftype_sw1, FRV_BUILTIN_MABSHS); | |
9107 | def_builtin ("__MDROTLI", uw2_ftype_uw2_int, FRV_BUILTIN_MDROTLI); | |
9108 | def_builtin ("__MCPLHI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLHI); | |
9109 | def_builtin ("__MCPLI", uw1_ftype_uw2_int, FRV_BUILTIN_MCPLI); | |
9110 | def_builtin ("__MDCUTSSI", uw2_ftype_acc_int, FRV_BUILTIN_MDCUTSSI); | |
9111 | def_builtin ("__MQSATHS", sw2_ftype_sw2_sw2, FRV_BUILTIN_MQSATHS); | |
9112 | def_builtin ("__MHSETLOS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETLOS); | |
9113 | def_builtin ("__MHSETHIS", sw1_ftype_sw1_int, FRV_BUILTIN_MHSETHIS); | |
9114 | def_builtin ("__MHDSETS", sw1_ftype_int, FRV_BUILTIN_MHDSETS); | |
9115 | def_builtin ("__MHSETLOH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETLOH); | |
9116 | def_builtin ("__MHSETHIH", uw1_ftype_uw1_int, FRV_BUILTIN_MHSETHIH); | |
9117 | def_builtin ("__MHDSETH", uw1_ftype_uw1_int, FRV_BUILTIN_MHDSETH); | |
9118 | ||
9119 | #undef UNARY | |
9120 | #undef BINARY | |
9121 | #undef TRINARY | |
9122 | } | |
9123 | ||
c15c90bb ZW |
9124 | /* Set the names for various arithmetic operations according to the |
9125 | FRV ABI. */ | |
9126 | static void | |
9127 | frv_init_libfuncs (void) | |
9128 | { | |
9129 | set_optab_libfunc (smod_optab, SImode, "__modi"); | |
9130 | set_optab_libfunc (umod_optab, SImode, "__umodi"); | |
9131 | ||
9132 | set_optab_libfunc (add_optab, DImode, "__addll"); | |
9133 | set_optab_libfunc (sub_optab, DImode, "__subll"); | |
9134 | set_optab_libfunc (smul_optab, DImode, "__mulll"); | |
9135 | set_optab_libfunc (sdiv_optab, DImode, "__divll"); | |
9136 | set_optab_libfunc (smod_optab, DImode, "__modll"); | |
9137 | set_optab_libfunc (umod_optab, DImode, "__umodll"); | |
9138 | set_optab_libfunc (and_optab, DImode, "__andll"); | |
9139 | set_optab_libfunc (ior_optab, DImode, "__orll"); | |
9140 | set_optab_libfunc (xor_optab, DImode, "__xorll"); | |
9141 | set_optab_libfunc (one_cmpl_optab, DImode, "__notll"); | |
9142 | ||
9143 | set_optab_libfunc (add_optab, SFmode, "__addf"); | |
9144 | set_optab_libfunc (sub_optab, SFmode, "__subf"); | |
9145 | set_optab_libfunc (smul_optab, SFmode, "__mulf"); | |
9146 | set_optab_libfunc (sdiv_optab, SFmode, "__divf"); | |
9147 | ||
9148 | set_optab_libfunc (add_optab, DFmode, "__addd"); | |
9149 | set_optab_libfunc (sub_optab, DFmode, "__subd"); | |
9150 | set_optab_libfunc (smul_optab, DFmode, "__muld"); | |
9151 | set_optab_libfunc (sdiv_optab, DFmode, "__divd"); | |
9152 | ||
85363ca0 ZW |
9153 | set_conv_libfunc (sext_optab, DFmode, SFmode, "__ftod"); |
9154 | set_conv_libfunc (trunc_optab, SFmode, DFmode, "__dtof"); | |
9155 | ||
9156 | set_conv_libfunc (sfix_optab, SImode, SFmode, "__ftoi"); | |
9157 | set_conv_libfunc (sfix_optab, DImode, SFmode, "__ftoll"); | |
9158 | set_conv_libfunc (sfix_optab, SImode, DFmode, "__dtoi"); | |
9159 | set_conv_libfunc (sfix_optab, DImode, DFmode, "__dtoll"); | |
9160 | ||
9161 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__ftoui"); | |
9162 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__ftoull"); | |
9163 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__dtoui"); | |
9164 | set_conv_libfunc (ufix_optab, SImode, SFmode, "__dtoull"); | |
9165 | ||
9166 | set_conv_libfunc (sfloat_optab, SFmode, SImode, "__itof"); | |
9167 | set_conv_libfunc (sfloat_optab, SFmode, DImode, "__lltof"); | |
9168 | set_conv_libfunc (sfloat_optab, DFmode, SImode, "__itod"); | |
9169 | set_conv_libfunc (sfloat_optab, DFmode, DImode, "__lltod"); | |
c15c90bb ZW |
9170 | } |
9171 | ||
36a05131 BS |
9172 | /* Convert an integer constant to an accumulator register. ICODE is the |
9173 | code of the target instruction, OPNUM is the number of the | |
9174 | accumulator operand and OPVAL is the constant integer. Try both | |
9175 | ACC and ACCG registers; only report an error if neither fit the | |
9176 | instruction. */ | |
9177 | ||
9178 | static rtx | |
9179 | frv_int_to_acc (icode, opnum, opval) | |
9180 | enum insn_code icode; | |
9181 | int opnum; | |
9182 | rtx opval; | |
9183 | { | |
9184 | rtx reg; | |
9185 | ||
9186 | if (GET_CODE (opval) != CONST_INT) | |
9187 | { | |
9188 | error ("accumulator is not a constant integer"); | |
9189 | return NULL_RTX; | |
9190 | } | |
9191 | if (! IN_RANGE_P (INTVAL (opval), 0, NUM_ACCS - 1)) | |
9192 | { | |
9193 | error ("accumulator number is out of bounds"); | |
9194 | return NULL_RTX; | |
9195 | } | |
9196 | ||
9197 | reg = gen_rtx_REG (insn_data[icode].operand[opnum].mode, | |
9198 | ACC_FIRST + INTVAL (opval)); | |
9199 | if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode)) | |
9200 | REGNO (reg) = ACCG_FIRST + INTVAL (opval); | |
9201 | ||
9202 | if (! (*insn_data[icode].operand[opnum].predicate) (reg, VOIDmode)) | |
9203 | { | |
9204 | error ("inappropriate accumulator for `%s'", insn_data[icode].name); | |
9205 | return NULL_RTX; | |
9206 | } | |
9207 | return reg; | |
9208 | } | |
9209 | ||
9210 | /* If an ACC rtx has mode MODE, return the mode that the matching ACCG | |
9211 | should have. */ | |
9212 | ||
9213 | static enum machine_mode | |
9214 | frv_matching_accg_mode (mode) | |
9215 | enum machine_mode mode; | |
9216 | { | |
9217 | switch (mode) | |
9218 | { | |
9219 | case V4SImode: | |
9220 | return V4QImode; | |
9221 | ||
9222 | case DImode: | |
9223 | return HImode; | |
9224 | ||
9225 | case SImode: | |
9226 | return QImode; | |
9227 | ||
9228 | default: | |
9229 | abort (); | |
9230 | } | |
9231 | } | |
9232 | ||
9233 | /* Return the accumulator guard that should be paired with accumulator | |
9234 | register ACC. The mode of the returned register is in the same | |
9235 | class as ACC, but is four times smaller. */ | |
9236 | ||
9237 | rtx | |
9238 | frv_matching_accg_for_acc (acc) | |
9239 | rtx acc; | |
9240 | { | |
9241 | return gen_rtx_REG (frv_matching_accg_mode (GET_MODE (acc)), | |
9242 | REGNO (acc) - ACC_FIRST + ACCG_FIRST); | |
9243 | } | |
9244 | ||
9245 | /* Read a value from the head of the tree list pointed to by ARGLISTPTR. | |
9246 | Return the value as an rtx and replace *ARGLISTPTR with the tail of the | |
9247 | list. */ | |
9248 | ||
9249 | static rtx | |
9250 | frv_read_argument (arglistptr) | |
9251 | tree *arglistptr; | |
9252 | { | |
9253 | tree next = TREE_VALUE (*arglistptr); | |
9254 | *arglistptr = TREE_CHAIN (*arglistptr); | |
9255 | return expand_expr (next, NULL_RTX, VOIDmode, 0); | |
9256 | } | |
9257 | ||
9258 | /* Return true if OPVAL can be used for operand OPNUM of instruction ICODE. | |
9259 | The instruction should require a constant operand of some sort. The | |
9260 | function prints an error if OPVAL is not valid. */ | |
9261 | ||
9262 | static int | |
9263 | frv_check_constant_argument (icode, opnum, opval) | |
9264 | enum insn_code icode; | |
9265 | int opnum; | |
9266 | rtx opval; | |
9267 | { | |
9268 | if (GET_CODE (opval) != CONST_INT) | |
9269 | { | |
9270 | error ("`%s' expects a constant argument", insn_data[icode].name); | |
9271 | return FALSE; | |
9272 | } | |
9273 | if (! (*insn_data[icode].operand[opnum].predicate) (opval, VOIDmode)) | |
9274 | { | |
9275 | error ("constant argument out of range for `%s'", insn_data[icode].name); | |
9276 | return FALSE; | |
9277 | } | |
9278 | return TRUE; | |
9279 | } | |
9280 | ||
9281 | /* Return a legitimate rtx for instruction ICODE's return value. Use TARGET | |
9282 | if it's not null, has the right mode, and satisfies operand 0's | |
9283 | predicate. */ | |
9284 | ||
9285 | static rtx | |
9286 | frv_legitimize_target (icode, target) | |
9287 | enum insn_code icode; | |
9288 | rtx target; | |
9289 | { | |
9290 | enum machine_mode mode = insn_data[icode].operand[0].mode; | |
9291 | ||
9292 | if (! target | |
9293 | || GET_MODE (target) != mode | |
9294 | || ! (*insn_data[icode].operand[0].predicate) (target, mode)) | |
9295 | return gen_reg_rtx (mode); | |
9296 | else | |
9297 | return target; | |
9298 | } | |
9299 | ||
9300 | /* Given that ARG is being passed as operand OPNUM to instruction ICODE, | |
9301 | check whether ARG satisfies the operand's contraints. If it doesn't, | |
9302 | copy ARG to a temporary register and return that. Otherwise return ARG | |
9303 | itself. */ | |
9304 | ||
9305 | static rtx | |
9306 | frv_legitimize_argument (icode, opnum, arg) | |
9307 | enum insn_code icode; | |
9308 | int opnum; | |
9309 | rtx arg; | |
9310 | { | |
9311 | enum machine_mode mode = insn_data[icode].operand[opnum].mode; | |
9312 | ||
9313 | if ((*insn_data[icode].operand[opnum].predicate) (arg, mode)) | |
9314 | return arg; | |
9315 | else | |
9316 | return copy_to_mode_reg (mode, arg); | |
9317 | } | |
9318 | ||
9319 | /* Expand builtins that take a single, constant argument. At the moment, | |
9320 | only MHDSETS falls into this category. */ | |
9321 | ||
9322 | static rtx | |
9323 | frv_expand_set_builtin (icode, arglist, target) | |
9324 | enum insn_code icode; | |
9325 | tree arglist; | |
9326 | rtx target; | |
9327 | { | |
9328 | rtx pat; | |
9329 | rtx op0 = frv_read_argument (&arglist); | |
9330 | ||
9331 | if (! frv_check_constant_argument (icode, 1, op0)) | |
9332 | return NULL_RTX; | |
9333 | ||
9334 | target = frv_legitimize_target (icode, target); | |
9335 | pat = GEN_FCN (icode) (target, op0); | |
9336 | if (! pat) | |
9337 | return NULL_RTX; | |
9338 | ||
9339 | emit_insn (pat); | |
9340 | return target; | |
9341 | } | |
9342 | ||
9343 | /* Expand builtins that take one operand. */ | |
9344 | ||
9345 | static rtx | |
9346 | frv_expand_unop_builtin (icode, arglist, target) | |
9347 | enum insn_code icode; | |
9348 | tree arglist; | |
9349 | rtx target; | |
9350 | { | |
9351 | rtx pat; | |
9352 | rtx op0 = frv_read_argument (&arglist); | |
9353 | ||
9354 | target = frv_legitimize_target (icode, target); | |
9355 | op0 = frv_legitimize_argument (icode, 1, op0); | |
9356 | pat = GEN_FCN (icode) (target, op0); | |
9357 | if (! pat) | |
9358 | return NULL_RTX; | |
9359 | ||
9360 | emit_insn (pat); | |
9361 | return target; | |
9362 | } | |
9363 | ||
9364 | /* Expand builtins that take two operands. */ | |
9365 | ||
9366 | static rtx | |
9367 | frv_expand_binop_builtin (icode, arglist, target) | |
9368 | enum insn_code icode; | |
9369 | tree arglist; | |
9370 | rtx target; | |
9371 | { | |
9372 | rtx pat; | |
9373 | rtx op0 = frv_read_argument (&arglist); | |
9374 | rtx op1 = frv_read_argument (&arglist); | |
9375 | ||
9376 | target = frv_legitimize_target (icode, target); | |
9377 | op0 = frv_legitimize_argument (icode, 1, op0); | |
9378 | op1 = frv_legitimize_argument (icode, 2, op1); | |
9379 | pat = GEN_FCN (icode) (target, op0, op1); | |
9380 | if (! pat) | |
9381 | return NULL_RTX; | |
9382 | ||
9383 | emit_insn (pat); | |
9384 | return target; | |
9385 | } | |
9386 | ||
9387 | /* Expand cut-style builtins, which take two operands and an implicit ACCG | |
9388 | one. */ | |
9389 | ||
9390 | static rtx | |
9391 | frv_expand_cut_builtin (icode, arglist, target) | |
9392 | enum insn_code icode; | |
9393 | tree arglist; | |
9394 | rtx target; | |
9395 | { | |
9396 | rtx pat; | |
9397 | rtx op0 = frv_read_argument (&arglist); | |
9398 | rtx op1 = frv_read_argument (&arglist); | |
9399 | rtx op2; | |
9400 | ||
9401 | target = frv_legitimize_target (icode, target); | |
9402 | op0 = frv_int_to_acc (icode, 1, op0); | |
9403 | if (! op0) | |
9404 | return NULL_RTX; | |
9405 | ||
9406 | if (icode == CODE_FOR_mdcutssi || GET_CODE (op1) == CONST_INT) | |
9407 | { | |
9408 | if (! frv_check_constant_argument (icode, 2, op1)) | |
9409 | return NULL_RTX; | |
9410 | } | |
9411 | else | |
9412 | op1 = frv_legitimize_argument (icode, 2, op1); | |
9413 | ||
9414 | op2 = frv_matching_accg_for_acc (op0); | |
9415 | pat = GEN_FCN (icode) (target, op0, op1, op2); | |
9416 | if (! pat) | |
9417 | return NULL_RTX; | |
9418 | ||
9419 | emit_insn (pat); | |
9420 | return target; | |
9421 | } | |
9422 | ||
9423 | /* Expand builtins that take two operands and the second is immediate. */ | |
9424 | ||
9425 | static rtx | |
9426 | frv_expand_binopimm_builtin (icode, arglist, target) | |
9427 | enum insn_code icode; | |
9428 | tree arglist; | |
9429 | rtx target; | |
9430 | { | |
9431 | rtx pat; | |
9432 | rtx op0 = frv_read_argument (&arglist); | |
9433 | rtx op1 = frv_read_argument (&arglist); | |
9434 | ||
9435 | if (! frv_check_constant_argument (icode, 2, op1)) | |
9436 | return NULL_RTX; | |
9437 | ||
9438 | target = frv_legitimize_target (icode, target); | |
9439 | op0 = frv_legitimize_argument (icode, 1, op0); | |
9440 | pat = GEN_FCN (icode) (target, op0, op1); | |
9441 | if (! pat) | |
9442 | return NULL_RTX; | |
9443 | ||
9444 | emit_insn (pat); | |
9445 | return target; | |
9446 | } | |
9447 | ||
9448 | /* Expand builtins that take two operands, the first operand being a pointer to | |
9449 | ints and return void. */ | |
9450 | ||
9451 | static rtx | |
9452 | frv_expand_voidbinop_builtin (icode, arglist) | |
9453 | enum insn_code icode; | |
9454 | tree arglist; | |
9455 | { | |
9456 | rtx pat; | |
9457 | rtx op0 = frv_read_argument (&arglist); | |
9458 | rtx op1 = frv_read_argument (&arglist); | |
9459 | enum machine_mode mode0 = insn_data[icode].operand[0].mode; | |
9460 | rtx addr; | |
9461 | ||
9462 | if (GET_CODE (op0) != MEM) | |
9463 | { | |
9464 | rtx reg = op0; | |
9465 | ||
9466 | if (! offsettable_address_p (0, mode0, op0)) | |
9467 | { | |
9468 | reg = gen_reg_rtx (Pmode); | |
9469 | emit_insn (gen_rtx_SET (VOIDmode, reg, op0)); | |
9470 | } | |
9471 | ||
9472 | op0 = gen_rtx_MEM (SImode, reg); | |
9473 | } | |
9474 | ||
9475 | addr = XEXP (op0, 0); | |
9476 | if (! offsettable_address_p (0, mode0, addr)) | |
9477 | addr = copy_to_mode_reg (Pmode, op0); | |
9478 | ||
9479 | op0 = change_address (op0, V4SImode, addr); | |
9480 | op1 = frv_legitimize_argument (icode, 1, op1); | |
9481 | pat = GEN_FCN (icode) (op0, op1); | |
9482 | if (! pat) | |
9483 | return 0; | |
9484 | ||
9485 | emit_insn (pat); | |
9486 | return 0; | |
9487 | } | |
9488 | ||
9489 | /* Expand builtins that take three operands and return void. The first | |
9490 | argument must be a constant that describes a pair or quad accumulators. A | |
9491 | fourth argument is created that is the accumulator guard register that | |
9492 | corresponds to the accumulator. */ | |
9493 | ||
9494 | static rtx | |
9495 | frv_expand_voidtriop_builtin (icode, arglist) | |
9496 | enum insn_code icode; | |
9497 | tree arglist; | |
9498 | { | |
9499 | rtx pat; | |
9500 | rtx op0 = frv_read_argument (&arglist); | |
9501 | rtx op1 = frv_read_argument (&arglist); | |
9502 | rtx op2 = frv_read_argument (&arglist); | |
9503 | rtx op3; | |
9504 | ||
9505 | op0 = frv_int_to_acc (icode, 0, op0); | |
9506 | if (! op0) | |
9507 | return NULL_RTX; | |
9508 | ||
9509 | op1 = frv_legitimize_argument (icode, 1, op1); | |
9510 | op2 = frv_legitimize_argument (icode, 2, op2); | |
9511 | op3 = frv_matching_accg_for_acc (op0); | |
9512 | pat = GEN_FCN (icode) (op0, op1, op2, op3); | |
9513 | if (! pat) | |
9514 | return NULL_RTX; | |
9515 | ||
9516 | emit_insn (pat); | |
9517 | return NULL_RTX; | |
9518 | } | |
9519 | ||
9520 | /* Expand builtins that perform accumulator-to-accumulator operations. | |
9521 | These builtins take two accumulator numbers as argument and return | |
9522 | void. */ | |
9523 | ||
9524 | static rtx | |
9525 | frv_expand_voidaccop_builtin (icode, arglist) | |
9526 | enum insn_code icode; | |
9527 | tree arglist; | |
9528 | { | |
9529 | rtx pat; | |
9530 | rtx op0 = frv_read_argument (&arglist); | |
9531 | rtx op1 = frv_read_argument (&arglist); | |
9532 | rtx op2; | |
9533 | rtx op3; | |
9534 | ||
9535 | op0 = frv_int_to_acc (icode, 0, op0); | |
9536 | if (! op0) | |
9537 | return NULL_RTX; | |
9538 | ||
9539 | op1 = frv_int_to_acc (icode, 1, op1); | |
9540 | if (! op1) | |
9541 | return NULL_RTX; | |
9542 | ||
9543 | op2 = frv_matching_accg_for_acc (op0); | |
9544 | op3 = frv_matching_accg_for_acc (op1); | |
9545 | pat = GEN_FCN (icode) (op0, op1, op2, op3); | |
9546 | if (! pat) | |
9547 | return NULL_RTX; | |
9548 | ||
9549 | emit_insn (pat); | |
9550 | return NULL_RTX; | |
9551 | } | |
9552 | ||
9553 | /* Expand the MCLRACC builtin. This builtin takes a single accumulator | |
9554 | number as argument. */ | |
9555 | ||
9556 | static rtx | |
9557 | frv_expand_mclracc_builtin (arglist) | |
9558 | tree arglist; | |
9559 | { | |
9560 | enum insn_code icode = CODE_FOR_mclracc; | |
9561 | rtx pat; | |
9562 | rtx op0 = frv_read_argument (&arglist); | |
9563 | ||
9564 | op0 = frv_int_to_acc (icode, 0, op0); | |
9565 | if (! op0) | |
9566 | return NULL_RTX; | |
9567 | ||
9568 | pat = GEN_FCN (icode) (op0); | |
9569 | if (pat) | |
9570 | emit_insn (pat); | |
9571 | ||
9572 | return NULL_RTX; | |
9573 | } | |
9574 | ||
9575 | /* Expand builtins that take no arguments. */ | |
9576 | ||
9577 | static rtx | |
9578 | frv_expand_noargs_builtin (icode) | |
9579 | enum insn_code icode; | |
9580 | { | |
9581 | rtx pat = GEN_FCN (icode) (GEN_INT (0)); | |
9582 | if (pat) | |
9583 | emit_insn (pat); | |
9584 | ||
9585 | return NULL_RTX; | |
9586 | } | |
9587 | ||
9588 | /* Expand MRDACC and MRDACCG. These builtins take a single accumulator | |
9589 | number or accumulator guard number as argument and return an SI integer. */ | |
9590 | ||
9591 | static rtx | |
9592 | frv_expand_mrdacc_builtin (icode, arglist) | |
9593 | enum insn_code icode; | |
9594 | tree arglist; | |
9595 | { | |
9596 | rtx pat; | |
9597 | rtx target = gen_reg_rtx (SImode); | |
9598 | rtx op0 = frv_read_argument (&arglist); | |
9599 | ||
9600 | op0 = frv_int_to_acc (icode, 1, op0); | |
9601 | if (! op0) | |
9602 | return NULL_RTX; | |
9603 | ||
9604 | pat = GEN_FCN (icode) (target, op0); | |
9605 | if (! pat) | |
9606 | return NULL_RTX; | |
9607 | ||
9608 | emit_insn (pat); | |
9609 | return target; | |
9610 | } | |
9611 | ||
9612 | /* Expand MWTACC and MWTACCG. These builtins take an accumulator or | |
9613 | accumulator guard as their first argument and an SImode value as their | |
9614 | second. */ | |
9615 | ||
9616 | static rtx | |
9617 | frv_expand_mwtacc_builtin (icode, arglist) | |
9618 | enum insn_code icode; | |
9619 | tree arglist; | |
9620 | { | |
9621 | rtx pat; | |
9622 | rtx op0 = frv_read_argument (&arglist); | |
9623 | rtx op1 = frv_read_argument (&arglist); | |
9624 | ||
9625 | op0 = frv_int_to_acc (icode, 0, op0); | |
9626 | if (! op0) | |
9627 | return NULL_RTX; | |
9628 | ||
9629 | op1 = frv_legitimize_argument (icode, 1, op1); | |
9630 | pat = GEN_FCN (icode) (op0, op1); | |
9631 | if (pat) | |
9632 | emit_insn (pat); | |
9633 | ||
9634 | return NULL_RTX; | |
9635 | } | |
9636 | ||
9637 | /* Expand builtins. */ | |
9638 | ||
14966b94 | 9639 | static rtx |
36a05131 BS |
9640 | frv_expand_builtin (exp, target, subtarget, mode, ignore) |
9641 | tree exp; | |
9642 | rtx target; | |
9643 | rtx subtarget ATTRIBUTE_UNUSED; | |
9644 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
9645 | int ignore ATTRIBUTE_UNUSED; | |
9646 | { | |
9647 | tree arglist = TREE_OPERAND (exp, 1); | |
9648 | tree fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0); | |
9649 | unsigned fcode = (unsigned)DECL_FUNCTION_CODE (fndecl); | |
9650 | unsigned i; | |
9651 | struct builtin_description *d; | |
9652 | ||
9653 | if (! TARGET_MEDIA) | |
9654 | { | |
9655 | error ("media functions are not available unless -mmedia is used"); | |
9656 | return NULL_RTX; | |
9657 | } | |
9658 | ||
9659 | switch (fcode) | |
9660 | { | |
9661 | case FRV_BUILTIN_MCOP1: | |
9662 | case FRV_BUILTIN_MCOP2: | |
9663 | case FRV_BUILTIN_MDUNPACKH: | |
9664 | case FRV_BUILTIN_MBTOHE: | |
9665 | if (! TARGET_MEDIA_REV1) | |
9666 | { | |
9667 | error ("this media function is only available on the fr500"); | |
9668 | return NULL_RTX; | |
9669 | } | |
9670 | break; | |
9671 | ||
9672 | case FRV_BUILTIN_MQXMACHS: | |
9673 | case FRV_BUILTIN_MQXMACXHS: | |
9674 | case FRV_BUILTIN_MQMACXHS: | |
9675 | case FRV_BUILTIN_MADDACCS: | |
9676 | case FRV_BUILTIN_MSUBACCS: | |
9677 | case FRV_BUILTIN_MASACCS: | |
9678 | case FRV_BUILTIN_MDADDACCS: | |
9679 | case FRV_BUILTIN_MDSUBACCS: | |
9680 | case FRV_BUILTIN_MDASACCS: | |
9681 | case FRV_BUILTIN_MABSHS: | |
9682 | case FRV_BUILTIN_MDROTLI: | |
9683 | case FRV_BUILTIN_MCPLHI: | |
9684 | case FRV_BUILTIN_MCPLI: | |
9685 | case FRV_BUILTIN_MDCUTSSI: | |
9686 | case FRV_BUILTIN_MQSATHS: | |
9687 | case FRV_BUILTIN_MHSETLOS: | |
9688 | case FRV_BUILTIN_MHSETLOH: | |
9689 | case FRV_BUILTIN_MHSETHIS: | |
9690 | case FRV_BUILTIN_MHSETHIH: | |
9691 | case FRV_BUILTIN_MHDSETS: | |
9692 | case FRV_BUILTIN_MHDSETH: | |
9693 | if (! TARGET_MEDIA_REV2) | |
9694 | { | |
9695 | error ("this media function is only available on the fr400"); | |
9696 | return NULL_RTX; | |
9697 | } | |
9698 | break; | |
9699 | ||
9700 | default: | |
9701 | break; | |
9702 | } | |
9703 | ||
9704 | /* Expand unique builtins. */ | |
9705 | ||
9706 | switch (fcode) | |
9707 | { | |
9708 | case FRV_BUILTIN_MTRAP: | |
9709 | return frv_expand_noargs_builtin (CODE_FOR_mtrap); | |
9710 | ||
9711 | case FRV_BUILTIN_MCLRACC: | |
9712 | return frv_expand_mclracc_builtin (arglist); | |
9713 | ||
9714 | case FRV_BUILTIN_MCLRACCA: | |
9715 | if (TARGET_ACC_8) | |
9716 | return frv_expand_noargs_builtin (CODE_FOR_mclracca8); | |
9717 | else | |
9718 | return frv_expand_noargs_builtin (CODE_FOR_mclracca4); | |
9719 | ||
9720 | case FRV_BUILTIN_MRDACC: | |
9721 | return frv_expand_mrdacc_builtin (CODE_FOR_mrdacc, arglist); | |
9722 | ||
9723 | case FRV_BUILTIN_MRDACCG: | |
9724 | return frv_expand_mrdacc_builtin (CODE_FOR_mrdaccg, arglist); | |
9725 | ||
9726 | case FRV_BUILTIN_MWTACC: | |
9727 | return frv_expand_mwtacc_builtin (CODE_FOR_mwtacc, arglist); | |
9728 | ||
9729 | case FRV_BUILTIN_MWTACCG: | |
9730 | return frv_expand_mwtacc_builtin (CODE_FOR_mwtaccg, arglist); | |
9731 | ||
9732 | default: | |
9733 | break; | |
9734 | } | |
9735 | ||
9736 | /* Expand groups of builtins. */ | |
9737 | ||
e97a46ce | 9738 | for (i = 0, d = bdesc_set; i < ARRAY_SIZE (bdesc_set); i++, d++) |
36a05131 BS |
9739 | if (d->code == fcode) |
9740 | return frv_expand_set_builtin (d->icode, arglist, target); | |
9741 | ||
e97a46ce | 9742 | for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++) |
36a05131 BS |
9743 | if (d->code == fcode) |
9744 | return frv_expand_unop_builtin (d->icode, arglist, target); | |
9745 | ||
e97a46ce | 9746 | for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++) |
36a05131 BS |
9747 | if (d->code == fcode) |
9748 | return frv_expand_binop_builtin (d->icode, arglist, target); | |
9749 | ||
e97a46ce | 9750 | for (i = 0, d = bdesc_cut; i < ARRAY_SIZE (bdesc_cut); i++, d++) |
36a05131 BS |
9751 | if (d->code == fcode) |
9752 | return frv_expand_cut_builtin (d->icode, arglist, target); | |
9753 | ||
e97a46ce KG |
9754 | for (i = 0, d = bdesc_2argimm; i < ARRAY_SIZE (bdesc_2argimm); i++, d++) |
9755 | if (d->code == fcode) | |
9756 | return frv_expand_binopimm_builtin (d->icode, arglist, target); | |
36a05131 | 9757 | |
e97a46ce KG |
9758 | for (i = 0, d = bdesc_void2arg; i < ARRAY_SIZE (bdesc_void2arg); i++, d++) |
9759 | if (d->code == fcode) | |
9760 | return frv_expand_voidbinop_builtin (d->icode, arglist); | |
36a05131 | 9761 | |
e97a46ce KG |
9762 | for (i = 0, d = bdesc_void3arg; i < ARRAY_SIZE (bdesc_void3arg); i++, d++) |
9763 | if (d->code == fcode) | |
9764 | return frv_expand_voidtriop_builtin (d->icode, arglist); | |
9765 | ||
9766 | for (i = 0, d = bdesc_voidacc; i < ARRAY_SIZE (bdesc_voidacc); i++, d++) | |
9767 | if (d->code == fcode) | |
9768 | return frv_expand_voidaccop_builtin (d->icode, arglist); | |
36a05131 | 9769 | |
36a05131 BS |
9770 | return 0; |
9771 | } | |
14966b94 | 9772 | |
b3fbfc07 KG |
9773 | static bool |
9774 | frv_in_small_data_p (decl) | |
9775 | tree decl; | |
9776 | { | |
0f6e5d45 RH |
9777 | HOST_WIDE_INT size; |
9778 | tree section_name; | |
9779 | ||
9780 | /* Don't apply the -G flag to internal compiler structures. We | |
9781 | should leave such structures in the main data section, partly | |
9782 | for efficiency and partly because the size of some of them | |
9783 | (such as C++ typeinfos) is not known until later. */ | |
9784 | if (TREE_CODE (decl) != VAR_DECL || DECL_ARTIFICIAL (decl)) | |
9785 | return false; | |
9786 | ||
9787 | size = int_size_in_bytes (TREE_TYPE (decl)); | |
307b599c | 9788 | if (size > 0 && (unsigned HOST_WIDE_INT) size <= g_switch_value) |
0f6e5d45 RH |
9789 | return true; |
9790 | ||
9791 | /* If we already know which section the decl should be in, see if | |
9792 | it's a small data section. */ | |
9793 | section_name = DECL_SECTION_NAME (decl); | |
9794 | if (section_name) | |
9795 | { | |
9796 | if (TREE_CODE (section_name) != STRING_CST) | |
9797 | abort (); | |
9798 | if (frv_string_begins_with (section_name, ".sdata")) | |
9799 | return true; | |
9800 | if (frv_string_begins_with (section_name, ".sbss")) | |
9801 | return true; | |
9802 | } | |
b3fbfc07 | 9803 | |
0f6e5d45 | 9804 | return false; |
b3fbfc07 | 9805 | } |
3c50106f RH |
9806 | \f |
9807 | static bool | |
9808 | frv_rtx_costs (x, code, outer_code, total) | |
9809 | rtx x; | |
6f562bc6 | 9810 | int code, outer_code ATTRIBUTE_UNUSED; |
3c50106f RH |
9811 | int *total; |
9812 | { | |
9813 | switch (code) | |
9814 | { | |
9815 | case CONST_INT: | |
9816 | /* Make 12 bit integers really cheap. */ | |
9817 | if (IN_RANGE_P (INTVAL (x), -2048, 2047)) | |
9818 | { | |
9819 | *total = 0; | |
9820 | return true; | |
9821 | } | |
9822 | /* FALLTHRU */ | |
9823 | ||
9824 | case CONST: | |
9825 | case LABEL_REF: | |
9826 | case SYMBOL_REF: | |
9827 | case CONST_DOUBLE: | |
9828 | *total = COSTS_N_INSNS (2); | |
9829 | return true; | |
9830 | ||
9831 | case PLUS: | |
9832 | case MINUS: | |
9833 | case AND: | |
9834 | case IOR: | |
9835 | case XOR: | |
9836 | case ASHIFT: | |
9837 | case ASHIFTRT: | |
9838 | case LSHIFTRT: | |
9839 | case NOT: | |
9840 | case NEG: | |
9841 | case COMPARE: | |
9842 | if (GET_MODE (x) == SImode) | |
9843 | *total = COSTS_N_INSNS (1); | |
9844 | else if (GET_MODE (x) == DImode) | |
9845 | *total = COSTS_N_INSNS (2); | |
9846 | else | |
9847 | *total = COSTS_N_INSNS (3); | |
9848 | return true; | |
9849 | ||
9850 | case MULT: | |
9851 | if (GET_MODE (x) == SImode) | |
9852 | *total = COSTS_N_INSNS (2); | |
9853 | else | |
9854 | *total = COSTS_N_INSNS (6); /* guess */ | |
9855 | return true; | |
9856 | ||
9857 | case DIV: | |
9858 | case UDIV: | |
9859 | case MOD: | |
9860 | case UMOD: | |
9861 | *total = COSTS_N_INSNS (18); | |
9862 | return true; | |
9863 | ||
9864 | default: | |
9865 | return false; | |
9866 | } | |
9867 | } | |
90a63880 RH |
9868 | \f |
9869 | static void | |
9870 | frv_asm_out_constructor (symbol, priority) | |
9871 | rtx symbol; | |
9872 | int priority ATTRIBUTE_UNUSED; | |
9873 | { | |
9874 | ctors_section (); | |
9875 | assemble_align (POINTER_SIZE); | |
9876 | assemble_integer_with_op ("\t.picptr\t", symbol); | |
9877 | } | |
9878 | ||
9879 | static void | |
9880 | frv_asm_out_destructor (symbol, priority) | |
9881 | rtx symbol; | |
9882 | int priority ATTRIBUTE_UNUSED; | |
9883 | { | |
9884 | dtors_section (); | |
9885 | assemble_align (POINTER_SIZE); | |
9886 | assemble_integer_with_op ("\t.picptr\t", symbol); | |
9887 | } |