]>
Commit | Line | Data |
---|---|---|
29a404f9 | 1 | /* Subroutines for insn-output.c for Matsushita MN10300 series |
058f71f0 | 2 | Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002 |
6e31cc90 | 3 | Free Software Foundation, Inc. |
29a404f9 | 4 | Contributed by Jeff Law (law@cygnus.com). |
5 | ||
6 | This file is part of GNU CC. | |
7 | ||
8 | GNU CC is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU CC is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU CC; see the file COPYING. If not, write to | |
20 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
29a404f9 | 23 | #include "config.h" |
7014838c | 24 | #include "system.h" |
805e22b2 | 25 | #include "coretypes.h" |
26 | #include "tm.h" | |
29a404f9 | 27 | #include "rtl.h" |
4faf81b8 | 28 | #include "tree.h" |
29a404f9 | 29 | #include "regs.h" |
30 | #include "hard-reg-set.h" | |
31 | #include "real.h" | |
32 | #include "insn-config.h" | |
33 | #include "conditions.h" | |
29a404f9 | 34 | #include "output.h" |
35 | #include "insn-attr.h" | |
36 | #include "flags.h" | |
37 | #include "recog.h" | |
38 | #include "expr.h" | |
d8fc4d0b | 39 | #include "optabs.h" |
4faf81b8 | 40 | #include "function.h" |
29a404f9 | 41 | #include "obstack.h" |
59086782 | 42 | #include "toplev.h" |
43 | #include "tm_p.h" | |
a767736d | 44 | #include "target.h" |
45 | #include "target-def.h" | |
29a404f9 | 46 | |
8ecf154e | 47 | /* The size of the callee register save area. Right now we save everything |
48 | on entry since it costs us nothing in code size. It does cost us from a | |
49 | speed standpoint, so we want to optimize this sooner or later. */ | |
3bcd7b00 | 50 | #define REG_SAVE_BYTES (4 * regs_ever_live[2] \ |
51 | + 4 * regs_ever_live[3] \ | |
911517ac | 52 | + 4 * regs_ever_live[6] \ |
53 | + 4 * regs_ever_live[7] \ | |
54 | + 16 * (regs_ever_live[14] || regs_ever_live[15] \ | |
55 | || regs_ever_live[16] || regs_ever_live[17])) | |
a767736d | 56 | \f |
57 | /* Initialize the GCC target structure. */ | |
58356836 | 58 | #undef TARGET_ASM_ALIGNED_HI_OP |
59 | #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t" | |
8ecf154e | 60 | |
57e4bbfb | 61 | struct gcc_target targetm = TARGET_INITIALIZER; |
a767736d | 62 | \f |
29a404f9 | 63 | void |
64 | asm_file_start (file) | |
65 | FILE *file; | |
66 | { | |
67 | fprintf (file, "#\tGCC For the Matsushita MN10300\n"); | |
68 | if (optimize) | |
69 | fprintf (file, "# -O%d\n", optimize); | |
70 | else | |
71 | fprintf (file, "\n\n"); | |
911517ac | 72 | |
73 | if (TARGET_AM33) | |
74 | fprintf (file, "\t.am33\n"); | |
29a404f9 | 75 | output_file_directive (file, main_input_filename); |
76 | } | |
77 | \f | |
78 | ||
29a404f9 | 79 | /* Print operand X using operand code CODE to assembly language output file |
80 | FILE. */ | |
81 | ||
82 | void | |
83 | print_operand (file, x, code) | |
84 | FILE *file; | |
85 | rtx x; | |
86 | int code; | |
87 | { | |
88 | switch (code) | |
89 | { | |
90 | case 'b': | |
91 | case 'B': | |
92 | /* These are normal and reversed branches. */ | |
93 | switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x))) | |
94 | { | |
95 | case NE: | |
96 | fprintf (file, "ne"); | |
97 | break; | |
98 | case EQ: | |
99 | fprintf (file, "eq"); | |
100 | break; | |
101 | case GE: | |
102 | fprintf (file, "ge"); | |
103 | break; | |
104 | case GT: | |
105 | fprintf (file, "gt"); | |
106 | break; | |
107 | case LE: | |
108 | fprintf (file, "le"); | |
109 | break; | |
110 | case LT: | |
111 | fprintf (file, "lt"); | |
112 | break; | |
113 | case GEU: | |
114 | fprintf (file, "cc"); | |
115 | break; | |
116 | case GTU: | |
117 | fprintf (file, "hi"); | |
118 | break; | |
119 | case LEU: | |
120 | fprintf (file, "ls"); | |
121 | break; | |
122 | case LTU: | |
123 | fprintf (file, "cs"); | |
124 | break; | |
125 | default: | |
126 | abort (); | |
127 | } | |
128 | break; | |
129 | case 'C': | |
130 | /* This is used for the operand to a call instruction; | |
131 | if it's a REG, enclose it in parens, else output | |
132 | the operand normally. */ | |
133 | if (GET_CODE (x) == REG) | |
134 | { | |
135 | fputc ('(', file); | |
136 | print_operand (file, x, 0); | |
137 | fputc (')', file); | |
138 | } | |
139 | else | |
140 | print_operand (file, x, 0); | |
141 | break; | |
142 | ||
6ce19398 | 143 | /* These are the least significant word in a 64bit value. */ |
144 | case 'L': | |
145 | switch (GET_CODE (x)) | |
146 | { | |
147 | case MEM: | |
148 | fputc ('(', file); | |
149 | output_address (XEXP (x, 0)); | |
150 | fputc (')', file); | |
151 | break; | |
152 | ||
153 | case REG: | |
154 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
155 | break; | |
156 | ||
157 | case SUBREG: | |
701e46d0 | 158 | fprintf (file, "%s", reg_names[subreg_regno (x)]); |
6ce19398 | 159 | break; |
160 | ||
161 | case CONST_DOUBLE: | |
162 | { | |
163 | long val[2]; | |
164 | REAL_VALUE_TYPE rv; | |
165 | ||
166 | switch (GET_MODE (x)) | |
167 | { | |
168 | case DFmode: | |
169 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
170 | REAL_VALUE_TO_TARGET_DOUBLE (rv, val); | |
ad3c0f03 | 171 | fprintf (file, "0x%lx", val[0]); |
6ce19398 | 172 | break;; |
173 | case SFmode: | |
174 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
175 | REAL_VALUE_TO_TARGET_SINGLE (rv, val[0]); | |
ad3c0f03 | 176 | fprintf (file, "0x%lx", val[0]); |
6ce19398 | 177 | break;; |
178 | case VOIDmode: | |
179 | case DImode: | |
180 | print_operand_address (file, | |
181 | GEN_INT (CONST_DOUBLE_LOW (x))); | |
182 | break; | |
59086782 | 183 | default: |
184 | break; | |
6ce19398 | 185 | } |
186 | break; | |
187 | } | |
188 | ||
189 | case CONST_INT: | |
964d057c | 190 | { |
191 | rtx low, high; | |
192 | split_double (x, &low, &high); | |
193 | fprintf (file, "%ld", (long)INTVAL (low)); | |
194 | break; | |
195 | } | |
6ce19398 | 196 | |
197 | default: | |
198 | abort (); | |
199 | } | |
200 | break; | |
201 | ||
202 | /* Similarly, but for the most significant word. */ | |
203 | case 'H': | |
204 | switch (GET_CODE (x)) | |
205 | { | |
206 | case MEM: | |
207 | fputc ('(', file); | |
eafc6604 | 208 | x = adjust_address (x, SImode, 4); |
6ce19398 | 209 | output_address (XEXP (x, 0)); |
210 | fputc (')', file); | |
211 | break; | |
212 | ||
213 | case REG: | |
214 | fprintf (file, "%s", reg_names[REGNO (x) + 1]); | |
215 | break; | |
216 | ||
217 | case SUBREG: | |
701e46d0 | 218 | fprintf (file, "%s", reg_names[subreg_regno (x) + 1]); |
6ce19398 | 219 | break; |
220 | ||
221 | case CONST_DOUBLE: | |
222 | { | |
223 | long val[2]; | |
224 | REAL_VALUE_TYPE rv; | |
225 | ||
226 | switch (GET_MODE (x)) | |
227 | { | |
228 | case DFmode: | |
229 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
230 | REAL_VALUE_TO_TARGET_DOUBLE (rv, val); | |
ad3c0f03 | 231 | fprintf (file, "0x%lx", val[1]); |
6ce19398 | 232 | break;; |
233 | case SFmode: | |
234 | abort (); | |
235 | case VOIDmode: | |
236 | case DImode: | |
237 | print_operand_address (file, | |
238 | GEN_INT (CONST_DOUBLE_HIGH (x))); | |
239 | break; | |
59086782 | 240 | default: |
241 | break; | |
6ce19398 | 242 | } |
243 | break; | |
244 | } | |
245 | ||
246 | case CONST_INT: | |
964d057c | 247 | { |
248 | rtx low, high; | |
249 | split_double (x, &low, &high); | |
250 | fprintf (file, "%ld", (long)INTVAL (high)); | |
251 | break; | |
252 | } | |
253 | ||
6ce19398 | 254 | default: |
255 | abort (); | |
256 | } | |
257 | break; | |
258 | ||
259 | case 'A': | |
260 | fputc ('(', file); | |
261 | if (GET_CODE (XEXP (x, 0)) == REG) | |
7014838c | 262 | output_address (gen_rtx_PLUS (SImode, XEXP (x, 0), GEN_INT (0))); |
6ce19398 | 263 | else |
264 | output_address (XEXP (x, 0)); | |
265 | fputc (')', file); | |
266 | break; | |
267 | ||
167fa942 | 268 | case 'N': |
058f71f0 | 269 | if (INTVAL (x) < -128 || INTVAL (x) > 255) |
270 | abort (); | |
271 | fprintf (file, "%d", (int)((~INTVAL (x)) & 0xff)); | |
272 | break; | |
273 | ||
274 | case 'U': | |
275 | if (INTVAL (x) < -128 || INTVAL (x) > 255) | |
276 | abort (); | |
277 | fprintf (file, "%d", (int)(INTVAL (x) & 0xff)); | |
167fa942 | 278 | break; |
279 | ||
63e678f2 | 280 | /* For shift counts. The hardware ignores the upper bits of |
281 | any immediate, but the assembler will flag an out of range | |
282 | shift count as an error. So we mask off the high bits | |
283 | of the immediate here. */ | |
284 | case 'S': | |
285 | if (GET_CODE (x) == CONST_INT) | |
286 | { | |
058f71f0 | 287 | fprintf (file, "%d", (int)(INTVAL (x) & 0x1f)); |
63e678f2 | 288 | break; |
289 | } | |
290 | /* FALL THROUGH */ | |
291 | ||
29a404f9 | 292 | default: |
293 | switch (GET_CODE (x)) | |
294 | { | |
295 | case MEM: | |
296 | fputc ('(', file); | |
297 | output_address (XEXP (x, 0)); | |
298 | fputc (')', file); | |
299 | break; | |
300 | ||
6ce19398 | 301 | case PLUS: |
302 | output_address (x); | |
303 | break; | |
304 | ||
29a404f9 | 305 | case REG: |
306 | fprintf (file, "%s", reg_names[REGNO (x)]); | |
307 | break; | |
308 | ||
309 | case SUBREG: | |
701e46d0 | 310 | fprintf (file, "%s", reg_names[subreg_regno (x)]); |
29a404f9 | 311 | break; |
312 | ||
6ce19398 | 313 | /* This will only be single precision.... */ |
314 | case CONST_DOUBLE: | |
315 | { | |
316 | unsigned long val; | |
317 | REAL_VALUE_TYPE rv; | |
318 | ||
319 | REAL_VALUE_FROM_CONST_DOUBLE (rv, x); | |
320 | REAL_VALUE_TO_TARGET_SINGLE (rv, val); | |
ad3c0f03 | 321 | fprintf (file, "0x%lx", val); |
6ce19398 | 322 | break; |
323 | } | |
324 | ||
29a404f9 | 325 | case CONST_INT: |
326 | case SYMBOL_REF: | |
327 | case CONST: | |
328 | case LABEL_REF: | |
329 | case CODE_LABEL: | |
330 | print_operand_address (file, x); | |
331 | break; | |
332 | default: | |
333 | abort (); | |
334 | } | |
335 | break; | |
336 | } | |
337 | } | |
338 | ||
339 | /* Output assembly language output for the address ADDR to FILE. */ | |
340 | ||
341 | void | |
342 | print_operand_address (file, addr) | |
343 | FILE *file; | |
344 | rtx addr; | |
345 | { | |
346 | switch (GET_CODE (addr)) | |
347 | { | |
911517ac | 348 | case POST_INC: |
349 | print_operand_address (file, XEXP (addr, 0)); | |
350 | fputc ('+', file); | |
351 | break; | |
29a404f9 | 352 | case REG: |
49fd1b62 | 353 | print_operand (file, addr, 0); |
29a404f9 | 354 | break; |
355 | case PLUS: | |
356 | { | |
357 | rtx base, index; | |
358 | if (REG_P (XEXP (addr, 0)) | |
359 | && REG_OK_FOR_BASE_P (XEXP (addr, 0))) | |
360 | base = XEXP (addr, 0), index = XEXP (addr, 1); | |
361 | else if (REG_P (XEXP (addr, 1)) | |
362 | && REG_OK_FOR_BASE_P (XEXP (addr, 1))) | |
363 | base = XEXP (addr, 1), index = XEXP (addr, 0); | |
364 | else | |
365 | abort (); | |
366 | print_operand (file, index, 0); | |
367 | fputc (',', file); | |
368 | print_operand (file, base, 0);; | |
369 | break; | |
370 | } | |
371 | case SYMBOL_REF: | |
372 | output_addr_const (file, addr); | |
373 | break; | |
374 | default: | |
375 | output_addr_const (file, addr); | |
376 | break; | |
377 | } | |
378 | } | |
379 | ||
4caa3669 | 380 | /* Print a set of registers in the format required by "movm" and "ret". |
381 | Register K is saved if bit K of MASK is set. The data and address | |
382 | registers can be stored individually, but the extended registers cannot. | |
383 | We assume that the mask alread takes that into account. For instance, | |
384 | bits 14 to 17 must have the same value. */ | |
385 | ||
386 | void | |
387 | mn10300_print_reg_list (file, mask) | |
388 | FILE *file; | |
389 | int mask; | |
390 | { | |
391 | int need_comma; | |
392 | int i; | |
393 | ||
394 | need_comma = 0; | |
395 | fputc ('[', file); | |
396 | ||
397 | for (i = 0; i < FIRST_EXTENDED_REGNUM; i++) | |
398 | if ((mask & (1 << i)) != 0) | |
399 | { | |
400 | if (need_comma) | |
401 | fputc (',', file); | |
402 | fputs (reg_names [i], file); | |
403 | need_comma = 1; | |
404 | } | |
405 | ||
406 | if ((mask & 0x3c000) != 0) | |
407 | { | |
408 | if ((mask & 0x3c000) != 0x3c000) | |
409 | abort(); | |
410 | if (need_comma) | |
411 | fputc (',', file); | |
412 | fputs ("exreg1", file); | |
413 | need_comma = 1; | |
414 | } | |
415 | ||
416 | fputc (']', file); | |
417 | } | |
418 | ||
6ce19398 | 419 | int |
420 | can_use_return_insn () | |
421 | { | |
36ed4406 | 422 | /* size includes the fixed stack space needed for function calls. */ |
423 | int size = get_frame_size () + current_function_outgoing_args_size; | |
424 | ||
425 | /* And space for the return pointer. */ | |
426 | size += current_function_outgoing_args_size ? 4 : 0; | |
6ce19398 | 427 | |
428 | return (reload_completed | |
429 | && size == 0 | |
430 | && !regs_ever_live[2] | |
431 | && !regs_ever_live[3] | |
432 | && !regs_ever_live[6] | |
433 | && !regs_ever_live[7] | |
911517ac | 434 | && !regs_ever_live[14] |
435 | && !regs_ever_live[15] | |
436 | && !regs_ever_live[16] | |
437 | && !regs_ever_live[17] | |
6ce19398 | 438 | && !frame_pointer_needed); |
439 | } | |
440 | ||
4caa3669 | 441 | /* Returns the set of live, callee-saved registers as a bitmask. The |
442 | callee-saved extended registers cannot be stored individually, so | |
443 | all of them will be included in the mask if any one of them is used. */ | |
444 | ||
445 | int | |
446 | mn10300_get_live_callee_saved_regs () | |
447 | { | |
448 | int mask; | |
449 | int i; | |
450 | ||
451 | mask = 0; | |
452 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
453 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
454 | mask |= (1 << i); | |
455 | if ((mask & 0x3c000) != 0) | |
456 | mask |= 0x3c000; | |
457 | ||
458 | return mask; | |
459 | } | |
460 | ||
461 | /* Generate an instruction that pushes several registers onto the stack. | |
462 | Register K will be saved if bit K in MASK is set. The function does | |
463 | nothing if MASK is zero. | |
464 | ||
465 | To be compatible with the "movm" instruction, the lowest-numbered | |
466 | register must be stored in the lowest slot. If MASK is the set | |
467 | { R1,...,RN }, where R1...RN are ordered least first, the generated | |
468 | instruction will have the form: | |
469 | ||
470 | (parallel | |
471 | (set (reg:SI 9) (plus:SI (reg:SI 9) (const_int -N*4))) | |
472 | (set (mem:SI (plus:SI (reg:SI 9) | |
473 | (const_int -1*4))) | |
474 | (reg:SI RN)) | |
475 | ... | |
476 | (set (mem:SI (plus:SI (reg:SI 9) | |
477 | (const_int -N*4))) | |
478 | (reg:SI R1))) */ | |
479 | ||
480 | void | |
481 | mn10300_gen_multiple_store (mask) | |
482 | int mask; | |
483 | { | |
484 | if (mask != 0) | |
485 | { | |
486 | int i; | |
487 | int count; | |
488 | rtx par; | |
489 | int pari; | |
490 | ||
491 | /* Count how many registers need to be saved. */ | |
492 | count = 0; | |
493 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
494 | if ((mask & (1 << i)) != 0) | |
495 | count += 1; | |
496 | ||
497 | /* We need one PARALLEL element to update the stack pointer and | |
498 | an additional element for each register that is stored. */ | |
499 | par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1)); | |
500 | ||
501 | /* Create the instruction that updates the stack pointer. */ | |
502 | XVECEXP (par, 0, 0) | |
503 | = gen_rtx_SET (SImode, | |
504 | stack_pointer_rtx, | |
505 | gen_rtx_PLUS (SImode, | |
506 | stack_pointer_rtx, | |
507 | GEN_INT (-count * 4))); | |
508 | ||
509 | /* Create each store. */ | |
510 | pari = 1; | |
511 | for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--) | |
512 | if ((mask & (1 << i)) != 0) | |
513 | { | |
514 | rtx address = gen_rtx_PLUS (SImode, | |
515 | stack_pointer_rtx, | |
516 | GEN_INT (-pari * 4)); | |
517 | XVECEXP(par, 0, pari) | |
518 | = gen_rtx_SET (VOIDmode, | |
519 | gen_rtx_MEM (SImode, address), | |
520 | gen_rtx_REG (SImode, i)); | |
521 | pari += 1; | |
522 | } | |
523 | ||
524 | par = emit_insn (par); | |
525 | RTX_FRAME_RELATED_P (par) = 1; | |
526 | } | |
527 | } | |
528 | ||
29a404f9 | 529 | void |
530 | expand_prologue () | |
531 | { | |
e3f95b40 | 532 | HOST_WIDE_INT size; |
f1899bff | 533 | |
f1899bff | 534 | /* SIZE includes the fixed stack space needed for function calls. */ |
36ed4406 | 535 | size = get_frame_size () + current_function_outgoing_args_size; |
536 | size += (current_function_outgoing_args_size ? 4 : 0); | |
29a404f9 | 537 | |
4caa3669 | 538 | /* If we use any of the callee-saved registers, save them now. */ |
539 | mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs ()); | |
48cb86e3 | 540 | |
541 | /* Now put the frame pointer into the frame pointer register. */ | |
29a404f9 | 542 | if (frame_pointer_needed) |
014546df | 543 | emit_move_insn (frame_pointer_rtx, stack_pointer_rtx); |
29a404f9 | 544 | |
48cb86e3 | 545 | /* Allocate stack for this frame. */ |
29a404f9 | 546 | if (size) |
547 | emit_insn (gen_addsi3 (stack_pointer_rtx, | |
548 | stack_pointer_rtx, | |
549 | GEN_INT (-size))); | |
550 | } | |
551 | ||
552 | void | |
553 | expand_epilogue () | |
554 | { | |
e3f95b40 | 555 | HOST_WIDE_INT size; |
f1899bff | 556 | |
f1899bff | 557 | /* SIZE includes the fixed stack space needed for function calls. */ |
36ed4406 | 558 | size = get_frame_size () + current_function_outgoing_args_size; |
559 | size += (current_function_outgoing_args_size ? 4 : 0); | |
29a404f9 | 560 | |
461cabcc | 561 | /* Maybe cut back the stack, except for the register save area. |
562 | ||
563 | If the frame pointer exists, then use the frame pointer to | |
564 | cut back the stack. | |
565 | ||
566 | If the stack size + register save area is more than 255 bytes, | |
567 | then the stack must be cut back here since the size + register | |
568 | save size is too big for a ret/retf instruction. | |
569 | ||
570 | Else leave it alone, it will be cut back as part of the | |
571 | ret/retf instruction, or there wasn't any stack to begin with. | |
572 | ||
573 | Under no circumstanes should the register save area be | |
574 | deallocated here, that would leave a window where an interrupt | |
575 | could occur and trash the register save area. */ | |
29a404f9 | 576 | if (frame_pointer_needed) |
577 | { | |
29a404f9 | 578 | emit_move_insn (stack_pointer_rtx, frame_pointer_rtx); |
b21218d6 | 579 | size = 0; |
580 | } | |
55daf463 | 581 | else if (size + REG_SAVE_BYTES > 255) |
b21218d6 | 582 | { |
583 | emit_insn (gen_addsi3 (stack_pointer_rtx, | |
584 | stack_pointer_rtx, | |
585 | GEN_INT (size))); | |
586 | size = 0; | |
29a404f9 | 587 | } |
29a404f9 | 588 | |
55daf463 | 589 | /* Adjust the stack and restore callee-saved registers, if any. */ |
590 | if (size || regs_ever_live[2] || regs_ever_live[3] | |
48cb86e3 | 591 | || regs_ever_live[6] || regs_ever_live[7] |
911517ac | 592 | || regs_ever_live[14] || regs_ever_live[15] |
593 | || regs_ever_live[16] || regs_ever_live[17] | |
48cb86e3 | 594 | || frame_pointer_needed) |
55daf463 | 595 | emit_jump_insn (gen_return_internal_regs |
596 | (GEN_INT (size + REG_SAVE_BYTES))); | |
48cb86e3 | 597 | else |
55daf463 | 598 | emit_jump_insn (gen_return_internal ()); |
29a404f9 | 599 | } |
600 | ||
601 | /* Update the condition code from the insn. */ | |
602 | ||
603 | void | |
604 | notice_update_cc (body, insn) | |
605 | rtx body; | |
606 | rtx insn; | |
607 | { | |
29a404f9 | 608 | switch (get_attr_cc (insn)) |
609 | { | |
610 | case CC_NONE: | |
611 | /* Insn does not affect CC at all. */ | |
612 | break; | |
613 | ||
614 | case CC_NONE_0HIT: | |
615 | /* Insn does not change CC, but the 0'th operand has been changed. */ | |
616 | if (cc_status.value1 != 0 | |
ed420a25 | 617 | && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1)) |
29a404f9 | 618 | cc_status.value1 = 0; |
619 | break; | |
620 | ||
14058057 | 621 | case CC_SET_ZN: |
ed420a25 | 622 | /* Insn sets the Z,N flags of CC to recog_data.operand[0]. |
14058057 | 623 | V,C are unusable. */ |
29a404f9 | 624 | CC_STATUS_INIT; |
14058057 | 625 | cc_status.flags |= CC_NO_CARRY | CC_OVERFLOW_UNUSABLE; |
ed420a25 | 626 | cc_status.value1 = recog_data.operand[0]; |
29a404f9 | 627 | break; |
628 | ||
14058057 | 629 | case CC_SET_ZNV: |
ed420a25 | 630 | /* Insn sets the Z,N,V flags of CC to recog_data.operand[0]. |
14058057 | 631 | C is unusable. */ |
45e3d109 | 632 | CC_STATUS_INIT; |
14058057 | 633 | cc_status.flags |= CC_NO_CARRY; |
ed420a25 | 634 | cc_status.value1 = recog_data.operand[0]; |
45e3d109 | 635 | break; |
636 | ||
29a404f9 | 637 | case CC_COMPARE: |
638 | /* The insn is a compare instruction. */ | |
639 | CC_STATUS_INIT; | |
640 | cc_status.value1 = SET_SRC (body); | |
641 | break; | |
642 | ||
952e42d8 | 643 | case CC_INVERT: |
644 | /* The insn is a compare instruction. */ | |
645 | CC_STATUS_INIT; | |
646 | cc_status.value1 = SET_SRC (body); | |
647 | cc_status.flags |= CC_INVERTED; | |
648 | break; | |
649 | ||
29a404f9 | 650 | case CC_CLOBBER: |
651 | /* Insn doesn't leave CC in a usable state. */ | |
652 | CC_STATUS_INIT; | |
653 | break; | |
45e3d109 | 654 | |
655 | default: | |
656 | abort (); | |
29a404f9 | 657 | } |
29a404f9 | 658 | } |
659 | ||
a2f10574 | 660 | /* Recognize the PARALLEL rtx generated by mn10300_gen_multiple_store(). |
4caa3669 | 661 | This function is for MATCH_PARALLEL and so assumes OP is known to be |
662 | parallel. If OP is a multiple store, return a mask indicating which | |
663 | registers it saves. Return 0 otherwise. */ | |
664 | ||
665 | int | |
666 | store_multiple_operation (op, mode) | |
667 | rtx op; | |
668 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
669 | { | |
670 | int count; | |
671 | int mask; | |
672 | int i; | |
673 | unsigned int last; | |
674 | rtx elt; | |
675 | ||
676 | count = XVECLEN (op, 0); | |
677 | if (count < 2) | |
678 | return 0; | |
679 | ||
680 | /* Check that first instruction has the form (set (sp) (plus A B)) */ | |
681 | elt = XVECEXP (op, 0, 0); | |
682 | if (GET_CODE (elt) != SET | |
683 | || GET_CODE (SET_DEST (elt)) != REG | |
684 | || REGNO (SET_DEST (elt)) != STACK_POINTER_REGNUM | |
685 | || GET_CODE (SET_SRC (elt)) != PLUS) | |
686 | return 0; | |
687 | ||
688 | /* Check that A is the stack pointer and B is the expected stack size. | |
689 | For OP to match, each subsequent instruction should push a word onto | |
690 | the stack. We therefore expect the first instruction to create | |
691 | COUNT-1 stack slots. */ | |
692 | elt = SET_SRC (elt); | |
693 | if (GET_CODE (XEXP (elt, 0)) != REG | |
694 | || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM | |
695 | || GET_CODE (XEXP (elt, 1)) != CONST_INT | |
696 | || INTVAL (XEXP (elt, 1)) != -(count - 1) * 4) | |
697 | return 0; | |
698 | ||
699 | /* Now go through the rest of the vector elements. They must be | |
700 | ordered so that the first instruction stores the highest-numbered | |
701 | register to the highest stack slot and that subsequent instructions | |
702 | store a lower-numbered register to the slot below. | |
703 | ||
704 | LAST keeps track of the smallest-numbered register stored so far. | |
705 | MASK is the set of stored registers. */ | |
706 | last = FIRST_PSEUDO_REGISTER; | |
707 | mask = 0; | |
708 | for (i = 1; i < count; i++) | |
709 | { | |
710 | /* Check that element i is a (set (mem M) R) and that R is valid. */ | |
711 | elt = XVECEXP (op, 0, i); | |
712 | if (GET_CODE (elt) != SET | |
713 | || GET_CODE (SET_DEST (elt)) != MEM | |
714 | || GET_CODE (SET_SRC (elt)) != REG | |
715 | || REGNO (SET_SRC (elt)) >= last) | |
716 | return 0; | |
717 | ||
718 | /* R was OK, so provisionally add it to MASK. We return 0 in any | |
719 | case if the rest of the instruction has a flaw. */ | |
720 | last = REGNO (SET_SRC (elt)); | |
721 | mask |= (1 << last); | |
722 | ||
723 | /* Check that M has the form (plus (sp) (const_int -I*4)) */ | |
724 | elt = XEXP (SET_DEST (elt), 0); | |
725 | if (GET_CODE (elt) != PLUS | |
726 | || GET_CODE (XEXP (elt, 0)) != REG | |
727 | || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM | |
728 | || GET_CODE (XEXP (elt, 1)) != CONST_INT | |
729 | || INTVAL (XEXP (elt, 1)) != -i * 4) | |
730 | return 0; | |
731 | } | |
732 | ||
733 | /* All or none of the callee-saved extended registers must be in the set. */ | |
734 | if ((mask & 0x3c000) != 0 | |
735 | && (mask & 0x3c000) != 0x3c000) | |
736 | return 0; | |
737 | ||
738 | return mask; | |
739 | } | |
740 | ||
29a404f9 | 741 | /* Return true if OP is a valid call operand. */ |
742 | ||
743 | int | |
744 | call_address_operand (op, mode) | |
745 | rtx op; | |
59086782 | 746 | enum machine_mode mode ATTRIBUTE_UNUSED; |
29a404f9 | 747 | { |
748 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG); | |
749 | } | |
750 | ||
751 | /* What (if any) secondary registers are needed to move IN with mode | |
dc3d02df | 752 | MODE into a register in register class CLASS. |
29a404f9 | 753 | |
754 | We might be able to simplify this. */ | |
755 | enum reg_class | |
756 | secondary_reload_class (class, mode, in) | |
757 | enum reg_class class; | |
758 | enum machine_mode mode; | |
759 | rtx in; | |
760 | { | |
29a404f9 | 761 | /* Memory loads less than a full word wide can't have an |
762 | address or stack pointer destination. They must use | |
763 | a data register as an intermediate register. */ | |
79ea832f | 764 | if ((GET_CODE (in) == MEM |
765 | || (GET_CODE (in) == REG | |
766 | && REGNO (in) >= FIRST_PSEUDO_REGISTER) | |
767 | || (GET_CODE (in) == SUBREG | |
768 | && GET_CODE (SUBREG_REG (in)) == REG | |
769 | && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER)) | |
29a404f9 | 770 | && (mode == QImode || mode == HImode) |
79ea832f | 771 | && (class == ADDRESS_REGS || class == SP_REGS |
b0ba03a6 | 772 | || class == SP_OR_ADDRESS_REGS)) |
8ecf154e | 773 | { |
911517ac | 774 | if (TARGET_AM33) |
775 | return DATA_OR_EXTENDED_REGS; | |
8ecf154e | 776 | return DATA_REGS; |
777 | } | |
29a404f9 | 778 | |
779 | /* We can't directly load sp + const_int into a data register; | |
780 | we must use an address register as an intermediate. */ | |
48cb86e3 | 781 | if (class != SP_REGS |
782 | && class != ADDRESS_REGS | |
783 | && class != SP_OR_ADDRESS_REGS | |
911517ac | 784 | && class != SP_OR_EXTENDED_REGS |
785 | && class != ADDRESS_OR_EXTENDED_REGS | |
786 | && class != SP_OR_ADDRESS_OR_EXTENDED_REGS | |
29a404f9 | 787 | && (in == stack_pointer_rtx |
788 | || (GET_CODE (in) == PLUS | |
48cb86e3 | 789 | && (XEXP (in, 0) == stack_pointer_rtx |
790 | || XEXP (in, 1) == stack_pointer_rtx)))) | |
29a404f9 | 791 | return ADDRESS_REGS; |
792 | ||
19de5de1 | 793 | if (GET_CODE (in) == PLUS |
794 | && (XEXP (in, 0) == stack_pointer_rtx | |
795 | || XEXP (in, 1) == stack_pointer_rtx)) | |
8ecf154e | 796 | { |
911517ac | 797 | if (TARGET_AM33) |
798 | return DATA_OR_EXTENDED_REGS; | |
8ecf154e | 799 | return DATA_REGS; |
800 | } | |
19de5de1 | 801 | |
48cb86e3 | 802 | /* Otherwise assume no secondary reloads are needed. */ |
803 | return NO_REGS; | |
804 | } | |
805 | ||
806 | int | |
807 | initial_offset (from, to) | |
808 | int from, to; | |
809 | { | |
f1899bff | 810 | /* The difference between the argument pointer and the frame pointer |
811 | is the size of the callee register save area. */ | |
48cb86e3 | 812 | if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM) |
29a404f9 | 813 | { |
48cb86e3 | 814 | if (regs_ever_live[2] || regs_ever_live[3] |
815 | || regs_ever_live[6] || regs_ever_live[7] | |
911517ac | 816 | || regs_ever_live[14] || regs_ever_live[15] |
817 | || regs_ever_live[16] || regs_ever_live[17] | |
48cb86e3 | 818 | || frame_pointer_needed) |
8ecf154e | 819 | return REG_SAVE_BYTES; |
48cb86e3 | 820 | else |
bb4959a8 | 821 | return 0; |
29a404f9 | 822 | } |
823 | ||
f1899bff | 824 | /* The difference between the argument pointer and the stack pointer is |
825 | the sum of the size of this function's frame, the callee register save | |
826 | area, and the fixed stack space needed for function calls (if any). */ | |
48cb86e3 | 827 | if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM) |
828 | { | |
829 | if (regs_ever_live[2] || regs_ever_live[3] | |
830 | || regs_ever_live[6] || regs_ever_live[7] | |
911517ac | 831 | || regs_ever_live[14] || regs_ever_live[15] |
832 | || regs_ever_live[16] || regs_ever_live[17] | |
48cb86e3 | 833 | || frame_pointer_needed) |
8ecf154e | 834 | return (get_frame_size () + REG_SAVE_BYTES |
36ed4406 | 835 | + (current_function_outgoing_args_size |
836 | ? current_function_outgoing_args_size + 4 : 0)); | |
48cb86e3 | 837 | else |
36ed4406 | 838 | return (get_frame_size () |
839 | + (current_function_outgoing_args_size | |
840 | ? current_function_outgoing_args_size + 4 : 0)); | |
48cb86e3 | 841 | } |
29a404f9 | 842 | |
f1899bff | 843 | /* The difference between the frame pointer and stack pointer is the sum |
844 | of the size of this function's frame and the fixed stack space needed | |
845 | for function calls (if any). */ | |
48cb86e3 | 846 | if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM) |
36ed4406 | 847 | return (get_frame_size () |
848 | + (current_function_outgoing_args_size | |
849 | ? current_function_outgoing_args_size + 4 : 0)); | |
48cb86e3 | 850 | |
851 | abort (); | |
29a404f9 | 852 | } |
bb4959a8 | 853 | |
854 | /* Flush the argument registers to the stack for a stdarg function; | |
855 | return the new argument pointer. */ | |
856 | rtx | |
55f54832 | 857 | mn10300_builtin_saveregs () |
bb4959a8 | 858 | { |
ed554036 | 859 | rtx offset, mem; |
bb4959a8 | 860 | tree fntype = TREE_TYPE (current_function_decl); |
861 | int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0 | |
862 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
863 | != void_type_node))) | |
864 | ? UNITS_PER_WORD : 0); | |
ed554036 | 865 | int set = get_varargs_alias_set (); |
bb4959a8 | 866 | |
867 | if (argadj) | |
868 | offset = plus_constant (current_function_arg_offset_rtx, argadj); | |
869 | else | |
870 | offset = current_function_arg_offset_rtx; | |
871 | ||
ed554036 | 872 | mem = gen_rtx_MEM (SImode, current_function_internal_arg_pointer); |
ab6ab77e | 873 | set_mem_alias_set (mem, set); |
ed554036 | 874 | emit_move_insn (mem, gen_rtx_REG (SImode, 0)); |
875 | ||
876 | mem = gen_rtx_MEM (SImode, | |
877 | plus_constant (current_function_internal_arg_pointer, 4)); | |
ab6ab77e | 878 | set_mem_alias_set (mem, set); |
ed554036 | 879 | emit_move_insn (mem, gen_rtx_REG (SImode, 1)); |
880 | ||
bb4959a8 | 881 | return copy_to_reg (expand_binop (Pmode, add_optab, |
882 | current_function_internal_arg_pointer, | |
883 | offset, 0, 0, OPTAB_LIB_WIDEN)); | |
884 | } | |
885 | ||
ed554036 | 886 | void |
7df226a2 | 887 | mn10300_va_start (valist, nextarg) |
ed554036 | 888 | tree valist; |
889 | rtx nextarg; | |
890 | { | |
7ccc713a | 891 | nextarg = expand_builtin_saveregs (); |
7df226a2 | 892 | std_expand_builtin_va_start (valist, nextarg); |
ed554036 | 893 | } |
894 | ||
895 | rtx | |
896 | mn10300_va_arg (valist, type) | |
897 | tree valist, type; | |
898 | { | |
899 | HOST_WIDE_INT align, rsize; | |
900 | tree t, ptr, pptr; | |
901 | ||
902 | /* Compute the rounded size of the type. */ | |
903 | align = PARM_BOUNDARY / BITS_PER_UNIT; | |
904 | rsize = (((int_size_in_bytes (type) + align - 1) / align) * align); | |
905 | ||
906 | t = build (POSTINCREMENT_EXPR, TREE_TYPE (valist), valist, | |
907 | build_int_2 ((rsize > 8 ? 4 : rsize), 0)); | |
908 | TREE_SIDE_EFFECTS (t) = 1; | |
909 | ||
910 | ptr = build_pointer_type (type); | |
911 | ||
912 | /* "Large" types are passed by reference. */ | |
913 | if (rsize > 8) | |
914 | { | |
915 | pptr = build_pointer_type (ptr); | |
916 | t = build1 (NOP_EXPR, pptr, t); | |
917 | TREE_SIDE_EFFECTS (t) = 1; | |
918 | ||
919 | t = build1 (INDIRECT_REF, ptr, t); | |
920 | TREE_SIDE_EFFECTS (t) = 1; | |
921 | } | |
922 | else | |
923 | { | |
924 | t = build1 (NOP_EXPR, ptr, t); | |
925 | TREE_SIDE_EFFECTS (t) = 1; | |
926 | } | |
927 | ||
928 | /* Calculate! */ | |
929 | return expand_expr (t, NULL_RTX, Pmode, EXPAND_NORMAL); | |
930 | } | |
931 | ||
bb4959a8 | 932 | /* Return an RTX to represent where a value with mode MODE will be returned |
933 | from a function. If the result is 0, the argument is pushed. */ | |
934 | ||
935 | rtx | |
936 | function_arg (cum, mode, type, named) | |
937 | CUMULATIVE_ARGS *cum; | |
938 | enum machine_mode mode; | |
939 | tree type; | |
59086782 | 940 | int named ATTRIBUTE_UNUSED; |
bb4959a8 | 941 | { |
942 | rtx result = 0; | |
943 | int size, align; | |
944 | ||
945 | /* We only support using 2 data registers as argument registers. */ | |
946 | int nregs = 2; | |
947 | ||
948 | /* Figure out the size of the object to be passed. */ | |
949 | if (mode == BLKmode) | |
950 | size = int_size_in_bytes (type); | |
951 | else | |
952 | size = GET_MODE_SIZE (mode); | |
953 | ||
954 | /* Figure out the alignment of the object to be passed. */ | |
955 | align = size; | |
956 | ||
957 | cum->nbytes = (cum->nbytes + 3) & ~3; | |
958 | ||
959 | /* Don't pass this arg via a register if all the argument registers | |
960 | are used up. */ | |
961 | if (cum->nbytes > nregs * UNITS_PER_WORD) | |
962 | return 0; | |
963 | ||
964 | /* Don't pass this arg via a register if it would be split between | |
965 | registers and memory. */ | |
966 | if (type == NULL_TREE | |
967 | && cum->nbytes + size > nregs * UNITS_PER_WORD) | |
968 | return 0; | |
969 | ||
970 | switch (cum->nbytes / UNITS_PER_WORD) | |
971 | { | |
972 | case 0: | |
7014838c | 973 | result = gen_rtx_REG (mode, 0); |
bb4959a8 | 974 | break; |
975 | case 1: | |
7014838c | 976 | result = gen_rtx_REG (mode, 1); |
bb4959a8 | 977 | break; |
978 | default: | |
979 | result = 0; | |
980 | } | |
981 | ||
982 | return result; | |
983 | } | |
984 | ||
985 | /* Return the number of registers to use for an argument passed partially | |
986 | in registers and partially in memory. */ | |
987 | ||
988 | int | |
989 | function_arg_partial_nregs (cum, mode, type, named) | |
990 | CUMULATIVE_ARGS *cum; | |
991 | enum machine_mode mode; | |
992 | tree type; | |
59086782 | 993 | int named ATTRIBUTE_UNUSED; |
bb4959a8 | 994 | { |
995 | int size, align; | |
996 | ||
997 | /* We only support using 2 data registers as argument registers. */ | |
998 | int nregs = 2; | |
999 | ||
1000 | /* Figure out the size of the object to be passed. */ | |
1001 | if (mode == BLKmode) | |
1002 | size = int_size_in_bytes (type); | |
1003 | else | |
1004 | size = GET_MODE_SIZE (mode); | |
1005 | ||
1006 | /* Figure out the alignment of the object to be passed. */ | |
1007 | align = size; | |
1008 | ||
1009 | cum->nbytes = (cum->nbytes + 3) & ~3; | |
1010 | ||
1011 | /* Don't pass this arg via a register if all the argument registers | |
1012 | are used up. */ | |
1013 | if (cum->nbytes > nregs * UNITS_PER_WORD) | |
1014 | return 0; | |
1015 | ||
1016 | if (cum->nbytes + size <= nregs * UNITS_PER_WORD) | |
1017 | return 0; | |
1018 | ||
1019 | /* Don't pass this arg via a register if it would be split between | |
1020 | registers and memory. */ | |
1021 | if (type == NULL_TREE | |
1022 | && cum->nbytes + size > nregs * UNITS_PER_WORD) | |
1023 | return 0; | |
1024 | ||
1025 | return (nregs * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD; | |
1026 | } | |
1027 | ||
1028 | /* Output a tst insn. */ | |
feb9af9f | 1029 | const char * |
bb4959a8 | 1030 | output_tst (operand, insn) |
1031 | rtx operand, insn; | |
1032 | { | |
bb4959a8 | 1033 | rtx temp; |
1034 | int past_call = 0; | |
1035 | ||
1036 | /* We can save a byte if we can find a register which has the value | |
1037 | zero in it. */ | |
1038 | temp = PREV_INSN (insn); | |
6e90c6cd | 1039 | while (optimize && temp) |
bb4959a8 | 1040 | { |
1041 | rtx set; | |
1042 | ||
1043 | /* We allow the search to go through call insns. We record | |
1044 | the fact that we've past a CALL_INSN and reject matches which | |
1045 | use call clobbered registers. */ | |
1046 | if (GET_CODE (temp) == CODE_LABEL | |
1047 | || GET_CODE (temp) == JUMP_INSN | |
1048 | || GET_CODE (temp) == BARRIER) | |
1049 | break; | |
1050 | ||
1051 | if (GET_CODE (temp) == CALL_INSN) | |
1052 | past_call = 1; | |
1053 | ||
1054 | if (GET_CODE (temp) == NOTE) | |
1055 | { | |
1056 | temp = PREV_INSN (temp); | |
1057 | continue; | |
1058 | } | |
1059 | ||
1060 | /* It must be an insn, see if it is a simple set. */ | |
1061 | set = single_set (temp); | |
1062 | if (!set) | |
1063 | { | |
1064 | temp = PREV_INSN (temp); | |
1065 | continue; | |
1066 | } | |
1067 | ||
1068 | /* Are we setting a data register to zero (this does not win for | |
1069 | address registers)? | |
1070 | ||
1071 | If it's a call clobbered register, have we past a call? | |
1072 | ||
1073 | Make sure the register we find isn't the same as ourself; | |
8ecf154e | 1074 | the mn10300 can't encode that. |
1075 | ||
1076 | ??? reg_set_between_p return nonzero anytime we pass a CALL_INSN | |
1077 | so the code to detect calls here isn't doing anything useful. */ | |
bb4959a8 | 1078 | if (REG_P (SET_DEST (set)) |
1079 | && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set))) | |
1080 | && !reg_set_between_p (SET_DEST (set), temp, insn) | |
6e90c6cd | 1081 | && (REGNO_REG_CLASS (REGNO (SET_DEST (set))) |
1082 | == REGNO_REG_CLASS (REGNO (operand))) | |
911517ac | 1083 | && REGNO_REG_CLASS (REGNO (SET_DEST (set))) != EXTENDED_REGS |
1084 | && REGNO (SET_DEST (set)) != REGNO (operand) | |
1085 | && (!past_call | |
1086 | || !call_used_regs[REGNO (SET_DEST (set))])) | |
1087 | { | |
1088 | rtx xoperands[2]; | |
1089 | xoperands[0] = operand; | |
1090 | xoperands[1] = SET_DEST (set); | |
1091 | ||
1092 | output_asm_insn ("cmp %1,%0", xoperands); | |
1093 | return ""; | |
1094 | } | |
1095 | ||
1096 | if (REGNO_REG_CLASS (REGNO (operand)) == EXTENDED_REGS | |
1097 | && REG_P (SET_DEST (set)) | |
1098 | && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set))) | |
1099 | && !reg_set_between_p (SET_DEST (set), temp, insn) | |
1100 | && (REGNO_REG_CLASS (REGNO (SET_DEST (set))) | |
1101 | != REGNO_REG_CLASS (REGNO (operand))) | |
1102 | && REGNO_REG_CLASS (REGNO (SET_DEST (set))) == EXTENDED_REGS | |
bb4959a8 | 1103 | && REGNO (SET_DEST (set)) != REGNO (operand) |
1104 | && (!past_call | |
1105 | || !call_used_regs[REGNO (SET_DEST (set))])) | |
1106 | { | |
1107 | rtx xoperands[2]; | |
1108 | xoperands[0] = operand; | |
1109 | xoperands[1] = SET_DEST (set); | |
1110 | ||
1111 | output_asm_insn ("cmp %1,%0", xoperands); | |
1112 | return ""; | |
1113 | } | |
1114 | temp = PREV_INSN (temp); | |
1115 | } | |
1116 | return "cmp 0,%0"; | |
1117 | } | |
36ed4406 | 1118 | |
1119 | int | |
1120 | impossible_plus_operand (op, mode) | |
1121 | rtx op; | |
59086782 | 1122 | enum machine_mode mode ATTRIBUTE_UNUSED; |
36ed4406 | 1123 | { |
36ed4406 | 1124 | if (GET_CODE (op) != PLUS) |
1125 | return 0; | |
1126 | ||
19de5de1 | 1127 | if (XEXP (op, 0) == stack_pointer_rtx |
1128 | || XEXP (op, 1) == stack_pointer_rtx) | |
36ed4406 | 1129 | return 1; |
1130 | ||
36ed4406 | 1131 | return 0; |
1132 | } | |
c4cd8f6a | 1133 | |
9d3b5b5e | 1134 | /* Return 1 if X is a CONST_INT that is only 8 bits wide. This is used |
1135 | for the btst insn which may examine memory or a register (the memory | |
1136 | variant only allows an unsigned 8 bit integer). */ | |
1137 | int | |
1138 | const_8bit_operand (op, mode) | |
1139 | register rtx op; | |
59086782 | 1140 | enum machine_mode mode ATTRIBUTE_UNUSED; |
9d3b5b5e | 1141 | { |
1142 | return (GET_CODE (op) == CONST_INT | |
1143 | && INTVAL (op) >= 0 | |
1144 | && INTVAL (op) < 256); | |
1145 | } | |
1146 | ||
1147 | /* Similarly, but when using a zero_extract pattern for a btst where | |
1148 | the source operand might end up in memory. */ | |
1149 | int | |
1150 | mask_ok_for_mem_btst (len, bit) | |
1151 | int len; | |
1152 | int bit; | |
1153 | { | |
805e22b2 | 1154 | unsigned int mask = 0; |
9d3b5b5e | 1155 | |
1156 | while (len > 0) | |
1157 | { | |
1158 | mask |= (1 << bit); | |
1159 | bit++; | |
1160 | len--; | |
1161 | } | |
1162 | ||
1163 | /* MASK must bit into an 8bit value. */ | |
1164 | return (((mask & 0xff) == mask) | |
1165 | || ((mask & 0xff00) == mask) | |
1166 | || ((mask & 0xff0000) == mask) | |
1167 | || ((mask & 0xff000000) == mask)); | |
1168 | } | |
1169 | ||
c4cd8f6a | 1170 | /* Return 1 if X contains a symbolic expression. We know these |
1171 | expressions will have one of a few well defined forms, so | |
1172 | we need only check those forms. */ | |
1173 | int | |
1174 | symbolic_operand (op, mode) | |
1175 | register rtx op; | |
59086782 | 1176 | enum machine_mode mode ATTRIBUTE_UNUSED; |
c4cd8f6a | 1177 | { |
1178 | switch (GET_CODE (op)) | |
1179 | { | |
1180 | case SYMBOL_REF: | |
1181 | case LABEL_REF: | |
1182 | return 1; | |
1183 | case CONST: | |
1184 | op = XEXP (op, 0); | |
1185 | return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
1186 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
1187 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
1188 | default: | |
1189 | return 0; | |
1190 | } | |
1191 | } | |
1192 | ||
1193 | /* Try machine dependent ways of modifying an illegitimate address | |
1194 | to be legitimate. If we find one, return the new valid address. | |
1195 | This macro is used in only one place: `memory_address' in explow.c. | |
1196 | ||
1197 | OLDX is the address as it was before break_out_memory_refs was called. | |
1198 | In some cases it is useful to look at this to decide what needs to be done. | |
1199 | ||
1200 | MODE and WIN are passed so that this macro can use | |
1201 | GO_IF_LEGITIMATE_ADDRESS. | |
1202 | ||
1203 | Normally it is always safe for this macro to do nothing. It exists to | |
1204 | recognize opportunities to optimize the output. | |
1205 | ||
1206 | But on a few ports with segmented architectures and indexed addressing | |
1207 | (mn10300, hppa) it is used to rewrite certain problematical addresses. */ | |
1208 | rtx | |
1209 | legitimize_address (x, oldx, mode) | |
1210 | rtx x; | |
59086782 | 1211 | rtx oldx ATTRIBUTE_UNUSED; |
1212 | enum machine_mode mode ATTRIBUTE_UNUSED; | |
c4cd8f6a | 1213 | { |
1214 | /* Uh-oh. We might have an address for x[n-100000]. This needs | |
1215 | special handling to avoid creating an indexed memory address | |
1216 | with x-100000 as the base. */ | |
1217 | if (GET_CODE (x) == PLUS | |
1218 | && symbolic_operand (XEXP (x, 1), VOIDmode)) | |
1219 | { | |
1220 | /* Ugly. We modify things here so that the address offset specified | |
1221 | by the index expression is computed first, then added to x to form | |
1222 | the entire address. */ | |
1223 | ||
59086782 | 1224 | rtx regx1, regy1, regy2, y; |
c4cd8f6a | 1225 | |
1226 | /* Strip off any CONST. */ | |
1227 | y = XEXP (x, 1); | |
1228 | if (GET_CODE (y) == CONST) | |
1229 | y = XEXP (y, 0); | |
1230 | ||
c927a8ab | 1231 | if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS) |
1232 | { | |
1233 | regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0)); | |
1234 | regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0)); | |
1235 | regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0)); | |
1236 | regx1 = force_reg (Pmode, | |
1237 | gen_rtx (GET_CODE (y), Pmode, regx1, regy2)); | |
7014838c | 1238 | return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1)); |
c927a8ab | 1239 | } |
c4cd8f6a | 1240 | } |
11b4605c | 1241 | return x; |
c4cd8f6a | 1242 | } |
e2aead91 | 1243 | |
1244 | int | |
1245 | mn10300_address_cost (x, unsig) | |
1246 | rtx x; | |
1247 | int *unsig; | |
1248 | { | |
1249 | int _s = 0; | |
1250 | if (unsig == 0) | |
1251 | unsig = &_s; | |
1252 | ||
1253 | switch (GET_CODE (x)) | |
1254 | { | |
1255 | case REG: | |
1256 | switch (REGNO_REG_CLASS (REGNO (x))) | |
1257 | { | |
1258 | case SP_REGS: | |
1259 | *unsig = 1; | |
1260 | return 0; | |
1261 | ||
1262 | case ADDRESS_REGS: | |
1263 | return 1; | |
1264 | ||
1265 | case DATA_REGS: | |
1266 | case EXTENDED_REGS: | |
1267 | return 3; | |
1268 | ||
1269 | case NO_REGS: | |
1270 | return 5; | |
1271 | ||
1272 | default: | |
1273 | abort (); | |
1274 | } | |
1275 | ||
1276 | case PLUS: | |
1277 | case MINUS: | |
cbe23f2f | 1278 | case ASHIFT: |
1279 | case AND: | |
e2aead91 | 1280 | case IOR: |
1281 | return (mn10300_address_cost (XEXP (x, 0), unsig) | |
1282 | + mn10300_address_cost (XEXP (x, 1), unsig)); | |
1283 | ||
1284 | case EXPR_LIST: | |
1285 | case SUBREG: | |
1286 | case MEM: | |
1287 | return ADDRESS_COST (XEXP (x, 0)); | |
1288 | ||
1289 | case ZERO_EXTEND: | |
1290 | *unsig = 1; | |
1291 | return mn10300_address_cost (XEXP (x, 0), unsig); | |
1292 | ||
1293 | case CONST_INT: | |
1294 | if (INTVAL (x) == 0) | |
1295 | return 0; | |
1296 | if (INTVAL (x) + (*unsig ? 0 : 0x80) < 0x100) | |
1297 | return 1; | |
1298 | if (INTVAL (x) + (*unsig ? 0 : 0x8000) < 0x10000) | |
1299 | return 3; | |
1300 | if (INTVAL (x) + (*unsig ? 0 : 0x800000) < 0x1000000) | |
1301 | return 5; | |
1302 | return 7; | |
1303 | ||
1304 | case CONST: | |
1305 | case SYMBOL_REF: | |
cbe23f2f | 1306 | case LABEL_REF: |
e2aead91 | 1307 | return 8; |
1308 | ||
1309 | case ADDRESSOF: | |
1310 | switch (GET_CODE (XEXP (x, 0))) | |
1311 | { | |
1312 | case MEM: | |
1313 | return ADDRESS_COST (XEXP (x, 0)); | |
1314 | ||
1315 | case REG: | |
1316 | return 1; | |
1317 | ||
1318 | default: | |
1319 | abort (); | |
1320 | } | |
1321 | ||
1322 | default: | |
1323 | abort (); | |
1324 | ||
1325 | } | |
1326 | } |