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