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