]>
Commit | Line | Data |
---|---|---|
ab835497 RK |
1 | /* Subroutines for insn-output.c for Sun SPARC. |
2 | Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc. | |
3 | Contributed by Michael Tiemann (tiemann@cygnus.com) | |
4 | ||
5 | This file is part of GNU CC. | |
6 | ||
7 | GNU CC is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GNU CC is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU CC; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include "config.h" | |
210aa14a | 23 | #include "tree.h" |
ab835497 RK |
24 | #include "rtl.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 "expr.h" | |
35 | #include "recog.h" | |
36 | ||
37 | /* Global variables for machine-dependent things. */ | |
38 | ||
39 | /* Save the operands last given to a compare for use when we | |
40 | generate a scc or bcc insn. */ | |
41 | ||
42 | rtx sparc_compare_op0, sparc_compare_op1; | |
43 | ||
44 | /* We may need an epilogue if we spill too many registers. | |
45 | If this is non-zero, then we branch here for the epilogue. */ | |
46 | static rtx leaf_label; | |
47 | ||
48 | #ifdef LEAF_REGISTERS | |
49 | ||
50 | /* Vector to say how input registers are mapped to output | |
51 | registers. FRAME_POINTER_REGNUM cannot be remapped by | |
52 | this function to eliminate it. You must use -fomit-frame-pointer | |
53 | to get that. */ | |
54 | char leaf_reg_remap[] = | |
55 | { 0, 1, 2, 3, 4, 5, 6, 7, | |
56 | -1, -1, -1, -1, -1, -1, 14, -1, | |
57 | -1, -1, -1, -1, -1, -1, -1, -1, | |
58 | 8, 9, 10, 11, 12, 13, -1, 15, | |
59 | ||
60 | 32, 33, 34, 35, 36, 37, 38, 39, | |
61 | 40, 41, 42, 43, 44, 45, 46, 47, | |
62 | 48, 49, 50, 51, 52, 53, 54, 55, | |
63 | 56, 57, 58, 59, 60, 61, 62, 63}; | |
64 | ||
65 | char leaf_reg_backmap[] = | |
66 | { 0, 1, 2, 3, 4, 5, 6, 7, | |
67 | 24, 25, 26, 27, 28, 29, 14, 31, | |
68 | -1, -1, -1, -1, -1, -1, -1, -1, | |
69 | -1, -1, -1, -1, -1, -1, -1, -1, | |
70 | ||
71 | 32, 33, 34, 35, 36, 37, 38, 39, | |
72 | 40, 41, 42, 43, 44, 45, 46, 47, | |
73 | 48, 49, 50, 51, 52, 53, 54, 55, | |
74 | 56, 57, 58, 59, 60, 61, 62, 63}; | |
75 | #endif | |
76 | ||
77 | /* Global variables set by FUNCTION_PROLOGUE. */ | |
78 | /* Size of frame. Need to know this to emit return insns from | |
79 | leaf procedures. */ | |
80 | int apparent_fsize; | |
81 | int actual_fsize; | |
82 | ||
83 | /* Name of where we pretend to think the frame pointer points. | |
84 | Normally, this is "%fp", but if we are in a leaf procedure, | |
85 | this is "%sp+something". */ | |
86 | char *frame_base_name; | |
87 | ||
88 | static rtx find_addr_reg (); | |
89 | ||
90 | /* Return non-zero only if OP is a register of mode MODE, | |
91 | or const0_rtx. */ | |
92 | int | |
93 | reg_or_0_operand (op, mode) | |
94 | rtx op; | |
95 | enum machine_mode mode; | |
96 | { | |
97 | if (op == const0_rtx || register_operand (op, mode)) | |
98 | return 1; | |
99 | if (GET_CODE (op) == CONST_DOUBLE | |
100 | && CONST_DOUBLE_HIGH (op) == 0 | |
101 | && CONST_DOUBLE_LOW (op) == 0) | |
102 | return 1; | |
103 | return 0; | |
104 | } | |
105 | ||
106 | /* Nonzero if OP can appear as the dest of a RESTORE insn. */ | |
107 | int | |
108 | restore_operand (op, mode) | |
109 | rtx op; | |
110 | enum machine_mode mode; | |
111 | { | |
112 | return (GET_CODE (op) == REG && GET_MODE (op) == mode | |
113 | && (REGNO (op) < 8 || (REGNO (op) >= 24 && REGNO (op) < 32))); | |
114 | } | |
115 | ||
116 | /* PC-relative call insn on SPARC is independent of `memory_operand'. */ | |
117 | ||
118 | int | |
119 | call_operand (op, mode) | |
120 | rtx op; | |
121 | enum machine_mode mode; | |
122 | { | |
123 | if (GET_CODE (op) != MEM) | |
124 | abort (); | |
125 | op = XEXP (op, 0); | |
126 | return (REG_P (op) || CONSTANT_P (op)); | |
127 | } | |
128 | ||
129 | int | |
130 | call_operand_address (op, mode) | |
131 | rtx op; | |
132 | enum machine_mode mode; | |
133 | { | |
134 | return (REG_P (op) || CONSTANT_P (op)); | |
135 | } | |
136 | ||
137 | /* Returns 1 if OP is either a symbol reference or a sum of a symbol | |
138 | reference and a constant. */ | |
139 | ||
140 | int | |
141 | symbolic_operand (op, mode) | |
142 | register rtx op; | |
143 | enum machine_mode mode; | |
144 | { | |
145 | switch (GET_CODE (op)) | |
146 | { | |
147 | case SYMBOL_REF: | |
148 | case LABEL_REF: | |
149 | return 1; | |
150 | ||
151 | case CONST: | |
152 | op = XEXP (op, 0); | |
153 | return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF | |
154 | || GET_CODE (XEXP (op, 0)) == LABEL_REF) | |
155 | && GET_CODE (XEXP (op, 1)) == CONST_INT); | |
156 | ||
228b4037 | 157 | /* ??? This clause seems to be irrelevant. */ |
ab835497 RK |
158 | case CONST_DOUBLE: |
159 | return GET_MODE (op) == mode; | |
160 | ||
161 | default: | |
162 | return 0; | |
163 | } | |
164 | } | |
165 | ||
166 | /* Return truth value of statement that OP is a symbolic memory | |
167 | operand of mode MODE. */ | |
168 | ||
169 | int | |
170 | symbolic_memory_operand (op, mode) | |
171 | rtx op; | |
172 | enum machine_mode mode; | |
173 | { | |
174 | if (GET_CODE (op) == SUBREG) | |
175 | op = SUBREG_REG (op); | |
176 | if (GET_CODE (op) != MEM) | |
177 | return 0; | |
178 | op = XEXP (op, 0); | |
179 | return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == CONST | |
180 | || GET_CODE (op) == HIGH || GET_CODE (op) == LABEL_REF); | |
181 | } | |
182 | ||
183 | /* Return 1 if the operand is either a register or a memory operand that is | |
184 | not symbolic. */ | |
185 | ||
186 | int | |
187 | reg_or_nonsymb_mem_operand (op, mode) | |
188 | register rtx op; | |
189 | enum machine_mode mode; | |
190 | { | |
191 | if (register_operand (op, mode)) | |
192 | return 1; | |
193 | ||
194 | if (memory_operand (op, mode) && ! symbolic_memory_operand (op, mode)) | |
195 | return 1; | |
196 | ||
197 | return 0; | |
198 | } | |
199 | ||
200 | int | |
201 | sparc_operand (op, mode) | |
202 | rtx op; | |
203 | enum machine_mode mode; | |
204 | { | |
205 | if (register_operand (op, mode)) | |
206 | return 1; | |
207 | if (GET_CODE (op) == CONST_INT) | |
208 | return SMALL_INT (op); | |
209 | if (GET_MODE (op) != mode) | |
210 | return 0; | |
211 | if (GET_CODE (op) == SUBREG) | |
212 | op = SUBREG_REG (op); | |
213 | if (GET_CODE (op) != MEM) | |
214 | return 0; | |
215 | ||
216 | op = XEXP (op, 0); | |
217 | if (GET_CODE (op) == LO_SUM) | |
218 | return (GET_CODE (XEXP (op, 0)) == REG | |
219 | && symbolic_operand (XEXP (op, 1), Pmode)); | |
220 | return memory_address_p (mode, op); | |
221 | } | |
222 | ||
223 | int | |
224 | move_operand (op, mode) | |
225 | rtx op; | |
226 | enum machine_mode mode; | |
227 | { | |
228 | if (mode == DImode && arith_double_operand (op, mode)) | |
229 | return 1; | |
230 | if (register_operand (op, mode)) | |
231 | return 1; | |
232 | if (GET_CODE (op) == CONST_INT) | |
233 | return (SMALL_INT (op) || (INTVAL (op) & 0x3ff) == 0); | |
234 | ||
235 | if (GET_MODE (op) != mode) | |
236 | return 0; | |
237 | if (GET_CODE (op) == SUBREG) | |
238 | op = SUBREG_REG (op); | |
239 | if (GET_CODE (op) != MEM) | |
240 | return 0; | |
241 | op = XEXP (op, 0); | |
242 | if (GET_CODE (op) == LO_SUM) | |
243 | return (register_operand (XEXP (op, 0), Pmode) | |
244 | && CONSTANT_P (XEXP (op, 1))); | |
245 | return memory_address_p (mode, op); | |
246 | } | |
247 | ||
248 | int | |
249 | move_pic_label (op, mode) | |
250 | rtx op; | |
251 | enum machine_mode mode; | |
252 | { | |
253 | /* Special case for PIC. */ | |
254 | if (flag_pic && GET_CODE (op) == LABEL_REF) | |
255 | return 1; | |
256 | return 0; | |
257 | } | |
258 | \f | |
259 | /* The rtx for the global offset table which is a special form | |
260 | that *is* a position independent symbolic constant. */ | |
261 | rtx pic_pc_rtx; | |
262 | ||
263 | /* Ensure that we are not using patterns that are not OK with PIC. */ | |
264 | ||
265 | int | |
266 | check_pic (i) | |
267 | int i; | |
268 | { | |
269 | switch (flag_pic) | |
270 | { | |
271 | case 1: | |
272 | if (GET_CODE (recog_operand[i]) == SYMBOL_REF | |
273 | || (GET_CODE (recog_operand[i]) == CONST | |
274 | && ! rtx_equal_p (pic_pc_rtx, recog_operand[i]))) | |
275 | abort (); | |
276 | case 2: | |
277 | default: | |
278 | return 1; | |
279 | } | |
280 | } | |
281 | ||
282 | /* Return true if X is an address which needs a temporary register when | |
283 | reloaded while generating PIC code. */ | |
284 | ||
285 | int | |
286 | pic_address_needs_scratch (x) | |
287 | rtx x; | |
288 | { | |
289 | /* An address which is a symbolic plus a non SMALL_INT needs a temp reg. */ | |
290 | if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS | |
291 | && GET_CODE (XEXP (XEXP (x, 0), 0)) == SYMBOL_REF | |
292 | && GET_CODE (XEXP (XEXP (x, 0), 1)) == CONST_INT | |
293 | && ! SMALL_INT (XEXP (XEXP (x, 0), 1))) | |
294 | return 1; | |
295 | ||
296 | return 0; | |
297 | } | |
298 | ||
299 | int | |
300 | memop (op, mode) | |
301 | rtx op; | |
302 | enum machine_mode mode; | |
303 | { | |
304 | if (GET_CODE (op) == MEM) | |
305 | return (mode == VOIDmode || mode == GET_MODE (op)); | |
306 | return 0; | |
307 | } | |
308 | ||
309 | /* Return truth value of whether OP is EQ or NE. */ | |
310 | ||
311 | int | |
312 | eq_or_neq (op, mode) | |
313 | rtx op; | |
314 | enum machine_mode mode; | |
315 | { | |
316 | return (GET_CODE (op) == EQ || GET_CODE (op) == NE); | |
317 | } | |
318 | ||
319 | /* Return 1 if this is a comparison operator, but not an EQ, NE, GEU, | |
320 | or LTU for non-floating-point. We handle those specially. */ | |
321 | ||
322 | int | |
323 | normal_comp_operator (op, mode) | |
324 | rtx op; | |
325 | enum machine_mode mode; | |
326 | { | |
327 | enum rtx_code code = GET_CODE (op); | |
328 | ||
329 | if (GET_RTX_CLASS (code) != '<') | |
330 | return 0; | |
331 | ||
4d449554 JW |
332 | if (GET_MODE (XEXP (op, 0)) == CCFPmode |
333 | || GET_MODE (XEXP (op, 0)) == CCFPEmode) | |
ab835497 RK |
334 | return 1; |
335 | ||
336 | return (code != NE && code != EQ && code != GEU && code != LTU); | |
337 | } | |
338 | ||
339 | /* Return 1 if this is a comparison operator. This allows the use of | |
340 | MATCH_OPERATOR to recognize all the branch insns. */ | |
341 | ||
342 | int | |
343 | noov_compare_op (op, mode) | |
344 | register rtx op; | |
345 | enum machine_mode mode; | |
346 | { | |
347 | enum rtx_code code = GET_CODE (op); | |
348 | ||
349 | if (GET_RTX_CLASS (code) != '<') | |
350 | return 0; | |
351 | ||
352 | if (GET_MODE (XEXP (op, 0)) == CC_NOOVmode) | |
353 | /* These are the only branches which work with CC_NOOVmode. */ | |
354 | return (code == EQ || code == NE || code == GE || code == LT); | |
355 | return 1; | |
356 | } | |
357 | ||
358 | /* Return 1 if this is a SIGN_EXTEND or ZERO_EXTEND operation. */ | |
359 | ||
360 | int | |
361 | extend_op (op, mode) | |
362 | rtx op; | |
363 | enum machine_mode mode; | |
364 | { | |
365 | return GET_CODE (op) == SIGN_EXTEND || GET_CODE (op) == ZERO_EXTEND; | |
366 | } | |
367 | ||
368 | /* Return nonzero if OP is an operator of mode MODE which can set | |
369 | the condition codes explicitly. We do not include PLUS and MINUS | |
370 | because these require CC_NOOVmode, which we handle explicitly. */ | |
371 | ||
372 | int | |
373 | cc_arithop (op, mode) | |
374 | rtx op; | |
375 | enum machine_mode mode; | |
376 | { | |
377 | if (GET_CODE (op) == AND | |
378 | || GET_CODE (op) == IOR | |
379 | || GET_CODE (op) == XOR) | |
380 | return 1; | |
381 | ||
382 | return 0; | |
383 | } | |
384 | ||
385 | /* Return nonzero if OP is an operator of mode MODE which can bitwise | |
386 | complement its second operand and set the condition codes explicitly. */ | |
387 | ||
388 | int | |
389 | cc_arithopn (op, mode) | |
390 | rtx op; | |
391 | enum machine_mode mode; | |
392 | { | |
393 | /* XOR is not here because combine canonicalizes (xor (not ...) ...) | |
394 | and (xor ... (not ...)) to (not (xor ...)). */ | |
395 | return (GET_CODE (op) == AND | |
396 | || GET_CODE (op) == IOR); | |
397 | } | |
398 | \f | |
228b4037 JW |
399 | /* Return true if OP is a register, or is a CONST_INT that can fit in a 13 |
400 | bit immediate field. This is an acceptable SImode operand for most 3 | |
401 | address instructions. */ | |
ab835497 RK |
402 | |
403 | int | |
404 | arith_operand (op, mode) | |
405 | rtx op; | |
406 | enum machine_mode mode; | |
407 | { | |
408 | return (register_operand (op, mode) | |
409 | || (GET_CODE (op) == CONST_INT && SMALL_INT (op))); | |
410 | } | |
411 | ||
228b4037 JW |
412 | /* Return true if OP is a register, or is a CONST_INT or CONST_DOUBLE that |
413 | can fit in a 13 bit immediate field. This is an acceptable DImode operand | |
414 | for most 3 address instructions. */ | |
ab835497 RK |
415 | |
416 | int | |
417 | arith_double_operand (op, mode) | |
418 | rtx op; | |
419 | enum machine_mode mode; | |
420 | { | |
421 | return (register_operand (op, mode) | |
422 | || (GET_CODE (op) == CONST_DOUBLE | |
423 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
424 | && (unsigned) (CONST_DOUBLE_LOW (op) + 0x1000) < 0x2000 | |
425 | && ((CONST_DOUBLE_HIGH (op) == -1 | |
426 | && (CONST_DOUBLE_LOW (op) & 0x1000) == 0x1000) | |
427 | || (CONST_DOUBLE_HIGH (op) == 0 | |
428 | && (CONST_DOUBLE_LOW (op) & 0x1000) == 0))) | |
429 | || (GET_CODE (op) == CONST_INT | |
430 | && (GET_MODE (op) == mode || GET_MODE (op) == VOIDmode) | |
431 | && (unsigned) (INTVAL (op) + 0x1000) < 0x2000)); | |
432 | } | |
433 | ||
434 | /* Return truth value of whether OP is a integer which fits the | |
228b4037 JW |
435 | range constraining immediate operands in most three-address insns, |
436 | which have a 13 bit immediate field. */ | |
ab835497 RK |
437 | |
438 | int | |
439 | small_int (op, mode) | |
440 | rtx op; | |
441 | enum machine_mode mode; | |
442 | { | |
443 | return (GET_CODE (op) == CONST_INT && SMALL_INT (op)); | |
444 | } | |
445 | ||
446 | /* Return truth value of statement that OP is a call-clobbered register. */ | |
447 | int | |
448 | clobbered_register (op, mode) | |
449 | rtx op; | |
450 | enum machine_mode mode; | |
451 | { | |
452 | return (GET_CODE (op) == REG && call_used_regs[REGNO (op)]); | |
453 | } | |
454 | \f | |
455 | /* X and Y are two things to compare using CODE. Emit the compare insn and | |
456 | return the rtx for register 0 in the proper mode. */ | |
457 | ||
458 | rtx | |
459 | gen_compare_reg (code, x, y) | |
460 | enum rtx_code code; | |
461 | rtx x, y; | |
462 | { | |
679655e6 | 463 | enum machine_mode mode = SELECT_CC_MODE (code, x, y); |
ab835497 RK |
464 | rtx cc_reg = gen_rtx (REG, mode, 0); |
465 | ||
466 | emit_insn (gen_rtx (SET, VOIDmode, cc_reg, | |
467 | gen_rtx (COMPARE, mode, x, y))); | |
468 | ||
469 | return cc_reg; | |
470 | } | |
471 | \f | |
472 | /* Return nonzero if a return peephole merging return with | |
473 | setting of output register is ok. */ | |
474 | int | |
475 | leaf_return_peephole_ok () | |
476 | { | |
477 | return (actual_fsize == 0); | |
478 | } | |
479 | ||
480 | /* Return nonzero if TRIAL can go into the function epilogue's | |
481 | delay slot. SLOT is the slot we are trying to fill. */ | |
482 | ||
483 | int | |
484 | eligible_for_epilogue_delay (trial, slot) | |
485 | rtx trial; | |
486 | int slot; | |
487 | { | |
ab835497 RK |
488 | rtx pat, src; |
489 | ||
490 | if (slot >= 1) | |
491 | return 0; | |
492 | if (GET_CODE (trial) != INSN | |
493 | || GET_CODE (PATTERN (trial)) != SET) | |
494 | return 0; | |
495 | if (get_attr_length (trial) != 1) | |
496 | return 0; | |
497 | ||
915f619f JW |
498 | /* In the case of a true leaf function, anything can go into the delay slot. |
499 | A delay slot only exists however if the frame size is zero, otherwise | |
500 | we will put an insn to adjust the stack after the return. */ | |
ab835497 RK |
501 | if (leaf_function) |
502 | { | |
503 | if (leaf_return_peephole_ok ()) | |
7c56249d | 504 | return (get_attr_in_uncond_branch_delay (trial) == IN_BRANCH_DELAY_TRUE); |
ab835497 RK |
505 | return 0; |
506 | } | |
507 | ||
508 | /* Otherwise, only operations which can be done in tandem with | |
509 | a `restore' insn can go into the delay slot. */ | |
510 | pat = PATTERN (trial); | |
511 | if (GET_CODE (SET_DEST (pat)) != REG | |
512 | || REGNO (SET_DEST (pat)) == 0 | |
915f619f JW |
513 | || REGNO (SET_DEST (pat)) >= 32 |
514 | || REGNO (SET_DEST (pat)) < 24) | |
ab835497 | 515 | return 0; |
915f619f | 516 | |
ab835497 RK |
517 | src = SET_SRC (pat); |
518 | if (arith_operand (src, GET_MODE (src))) | |
519 | return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (SImode); | |
520 | if (arith_double_operand (src, GET_MODE (src))) | |
521 | return GET_MODE_SIZE (GET_MODE (src)) <= GET_MODE_SIZE (DImode); | |
522 | if (GET_CODE (src) == PLUS) | |
523 | { | |
524 | if (register_operand (XEXP (src, 0), SImode) | |
525 | && arith_operand (XEXP (src, 1), SImode)) | |
526 | return 1; | |
527 | if (register_operand (XEXP (src, 1), SImode) | |
528 | && arith_operand (XEXP (src, 0), SImode)) | |
529 | return 1; | |
530 | if (register_operand (XEXP (src, 0), DImode) | |
531 | && arith_double_operand (XEXP (src, 1), DImode)) | |
532 | return 1; | |
533 | if (register_operand (XEXP (src, 1), DImode) | |
534 | && arith_double_operand (XEXP (src, 0), DImode)) | |
535 | return 1; | |
536 | } | |
537 | if (GET_CODE (src) == MINUS | |
538 | && register_operand (XEXP (src, 0), SImode) | |
539 | && small_int (XEXP (src, 1), VOIDmode)) | |
540 | return 1; | |
541 | if (GET_CODE (src) == MINUS | |
542 | && register_operand (XEXP (src, 0), DImode) | |
543 | && !register_operand (XEXP (src, 1), DImode) | |
544 | && arith_double_operand (XEXP (src, 1), DImode)) | |
545 | return 1; | |
546 | return 0; | |
547 | } | |
548 | ||
549 | int | |
550 | short_branch (uid1, uid2) | |
551 | int uid1, uid2; | |
552 | { | |
553 | unsigned int delta = insn_addresses[uid1] - insn_addresses[uid2]; | |
554 | if (delta + 1024 < 2048) | |
555 | return 1; | |
556 | /* warning ("long branch, distance %d", delta); */ | |
557 | return 0; | |
558 | } | |
559 | ||
560 | /* Return non-zero if REG is not used after INSN. | |
561 | We assume REG is a reload reg, and therefore does | |
562 | not live past labels or calls or jumps. */ | |
563 | int | |
564 | reg_unused_after (reg, insn) | |
565 | rtx reg; | |
566 | rtx insn; | |
567 | { | |
568 | enum rtx_code code, prev_code = UNKNOWN; | |
569 | ||
570 | while (insn = NEXT_INSN (insn)) | |
571 | { | |
572 | if (prev_code == CALL_INSN && call_used_regs[REGNO (reg)]) | |
573 | return 1; | |
574 | ||
575 | code = GET_CODE (insn); | |
576 | if (GET_CODE (insn) == CODE_LABEL) | |
577 | return 1; | |
578 | ||
579 | if (GET_RTX_CLASS (code) == 'i') | |
580 | { | |
581 | rtx set = single_set (insn); | |
582 | int in_src = set && reg_overlap_mentioned_p (reg, SET_SRC (set)); | |
583 | if (set && in_src) | |
584 | return 0; | |
585 | if (set && reg_overlap_mentioned_p (reg, SET_DEST (set))) | |
586 | return 1; | |
587 | if (set == 0 && reg_overlap_mentioned_p (reg, PATTERN (insn))) | |
588 | return 0; | |
589 | } | |
590 | prev_code = code; | |
591 | } | |
592 | return 1; | |
593 | } | |
594 | \f | |
595 | /* Legitimize PIC addresses. If the address is already position-independent, | |
596 | we return ORIG. Newly generated position-independent addresses go into a | |
597 | reg. This is REG if non zero, otherwise we allocate register(s) as | |
598 | necessary. If this is called during reload, and we need a second temp | |
599 | register, then we use SCRATCH, which is provided via the | |
600 | SECONDARY_INPUT_RELOAD_CLASS mechanism. */ | |
601 | ||
602 | rtx | |
603 | legitimize_pic_address (orig, mode, reg, scratch) | |
604 | rtx orig; | |
605 | enum machine_mode mode; | |
606 | rtx reg, scratch; | |
607 | { | |
608 | if (GET_CODE (orig) == SYMBOL_REF) | |
609 | { | |
610 | rtx pic_ref, address; | |
611 | rtx insn; | |
612 | ||
613 | if (reg == 0) | |
614 | { | |
01c0e9dc | 615 | if (reload_in_progress || reload_completed) |
ab835497 RK |
616 | abort (); |
617 | else | |
618 | reg = gen_reg_rtx (Pmode); | |
619 | } | |
620 | ||
621 | if (flag_pic == 2) | |
622 | { | |
623 | /* If not during reload, allocate another temp reg here for loading | |
624 | in the address, so that these instructions can be optimized | |
625 | properly. */ | |
01c0e9dc JW |
626 | rtx temp_reg = ((reload_in_progress || reload_completed) |
627 | ? reg : gen_reg_rtx (Pmode)); | |
ab835497 | 628 | |
b4ac57ab RS |
629 | /* Must put the SYMBOL_REF inside an UNSPEC here so that cse |
630 | won't get confused into thinking that these two instructions | |
631 | are loading in the true address of the symbol. If in the | |
632 | future a PIC rtx exists, that should be used instead. */ | |
ab835497 | 633 | emit_insn (gen_rtx (SET, VOIDmode, temp_reg, |
b4ac57ab RS |
634 | gen_rtx (HIGH, Pmode, |
635 | gen_rtx (UNSPEC, Pmode, | |
636 | gen_rtvec (1, orig), | |
637 | 0)))); | |
ab835497 | 638 | emit_insn (gen_rtx (SET, VOIDmode, temp_reg, |
b4ac57ab RS |
639 | gen_rtx (LO_SUM, Pmode, temp_reg, |
640 | gen_rtx (UNSPEC, Pmode, | |
641 | gen_rtvec (1, orig), | |
642 | 0)))); | |
ab835497 RK |
643 | address = temp_reg; |
644 | } | |
645 | else | |
646 | address = orig; | |
647 | ||
648 | pic_ref = gen_rtx (MEM, Pmode, | |
649 | gen_rtx (PLUS, Pmode, | |
650 | pic_offset_table_rtx, address)); | |
651 | current_function_uses_pic_offset_table = 1; | |
652 | RTX_UNCHANGING_P (pic_ref) = 1; | |
653 | insn = emit_move_insn (reg, pic_ref); | |
654 | /* Put a REG_EQUAL note on this insn, so that it can be optimized | |
655 | by loop. */ | |
656 | REG_NOTES (insn) = gen_rtx (EXPR_LIST, REG_EQUAL, orig, | |
657 | REG_NOTES (insn)); | |
658 | return reg; | |
659 | } | |
660 | else if (GET_CODE (orig) == CONST) | |
661 | { | |
662 | rtx base, offset; | |
663 | ||
664 | if (GET_CODE (XEXP (orig, 0)) == PLUS | |
665 | && XEXP (XEXP (orig, 0), 0) == pic_offset_table_rtx) | |
666 | return orig; | |
667 | ||
668 | if (reg == 0) | |
669 | { | |
01c0e9dc | 670 | if (reload_in_progress || reload_completed) |
ab835497 RK |
671 | abort (); |
672 | else | |
673 | reg = gen_reg_rtx (Pmode); | |
674 | } | |
675 | ||
676 | if (GET_CODE (XEXP (orig, 0)) == PLUS) | |
677 | { | |
678 | base = legitimize_pic_address (XEXP (XEXP (orig, 0), 0), Pmode, | |
679 | reg, 0); | |
680 | offset = legitimize_pic_address (XEXP (XEXP (orig, 0), 1), Pmode, | |
681 | base == reg ? 0 : reg, 0); | |
682 | } | |
683 | else | |
684 | abort (); | |
685 | ||
686 | if (GET_CODE (offset) == CONST_INT) | |
687 | { | |
688 | if (SMALL_INT (offset)) | |
689 | return plus_constant_for_output (base, INTVAL (offset)); | |
01c0e9dc | 690 | else if (! reload_in_progress && ! reload_completed) |
ab835497 RK |
691 | offset = force_reg (Pmode, offset); |
692 | /* We can't create any new registers during reload, so use the | |
693 | SCRATCH reg provided by the reload_insi pattern. */ | |
694 | else if (scratch) | |
695 | { | |
696 | emit_move_insn (scratch, offset); | |
697 | offset = scratch; | |
698 | } | |
699 | else | |
700 | /* If we reach here, then the SECONDARY_INPUT_RELOAD_CLASS | |
701 | macro needs to be adjusted so that a scratch reg is provided | |
702 | for this address. */ | |
703 | abort (); | |
704 | } | |
705 | return gen_rtx (PLUS, Pmode, base, offset); | |
706 | } | |
707 | else if (GET_CODE (orig) == LABEL_REF) | |
708 | current_function_uses_pic_offset_table = 1; | |
709 | ||
710 | return orig; | |
711 | } | |
712 | ||
713 | /* Set up PIC-specific rtl. This should not cause any insns | |
714 | to be emitted. */ | |
715 | ||
716 | void | |
717 | initialize_pic () | |
718 | { | |
719 | } | |
720 | ||
721 | /* Emit special PIC prologues and epilogues. */ | |
722 | ||
723 | void | |
724 | finalize_pic () | |
725 | { | |
726 | /* The table we use to reference PIC data. */ | |
727 | rtx global_offset_table; | |
728 | /* Labels to get the PC in the prologue of this function. */ | |
729 | rtx l1, l2; | |
730 | rtx seq; | |
731 | int orig_flag_pic = flag_pic; | |
732 | ||
733 | if (current_function_uses_pic_offset_table == 0) | |
734 | return; | |
735 | ||
736 | if (! flag_pic) | |
737 | abort (); | |
738 | ||
739 | flag_pic = 0; | |
740 | l1 = gen_label_rtx (); | |
741 | l2 = gen_label_rtx (); | |
742 | ||
743 | start_sequence (); | |
744 | ||
745 | emit_label (l1); | |
746 | /* Note that we pun calls and jumps here! */ | |
747 | emit_jump_insn (gen_rtx (PARALLEL, VOIDmode, | |
748 | gen_rtvec (2, | |
749 | gen_rtx (SET, VOIDmode, pc_rtx, gen_rtx (LABEL_REF, VOIDmode, l2)), | |
750 | gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, 15), gen_rtx (LABEL_REF, VOIDmode, l2))))); | |
751 | emit_label (l2); | |
752 | ||
753 | /* Initialize every time through, since we can't easily | |
754 | know this to be permanent. */ | |
c4eb2bd7 | 755 | global_offset_table = gen_rtx (SYMBOL_REF, Pmode, "_GLOBAL_OFFSET_TABLE_"); |
ab835497 RK |
756 | pic_pc_rtx = gen_rtx (CONST, Pmode, |
757 | gen_rtx (MINUS, Pmode, | |
758 | global_offset_table, | |
759 | gen_rtx (CONST, Pmode, | |
760 | gen_rtx (MINUS, Pmode, | |
761 | gen_rtx (LABEL_REF, VOIDmode, l1), | |
762 | pc_rtx)))); | |
763 | ||
764 | emit_insn (gen_rtx (SET, VOIDmode, pic_offset_table_rtx, | |
765 | gen_rtx (HIGH, Pmode, pic_pc_rtx))); | |
766 | emit_insn (gen_rtx (SET, VOIDmode, | |
767 | pic_offset_table_rtx, | |
768 | gen_rtx (LO_SUM, Pmode, | |
769 | pic_offset_table_rtx, pic_pc_rtx))); | |
770 | emit_insn (gen_rtx (SET, VOIDmode, | |
771 | pic_offset_table_rtx, | |
772 | gen_rtx (PLUS, Pmode, | |
773 | pic_offset_table_rtx, gen_rtx (REG, Pmode, 15)))); | |
774 | /* emit_insn (gen_rtx (ASM_INPUT, VOIDmode, "!#PROLOGUE# 1")); */ | |
775 | LABEL_PRESERVE_P (l1) = 1; | |
776 | LABEL_PRESERVE_P (l2) = 1; | |
777 | flag_pic = orig_flag_pic; | |
778 | ||
779 | seq = gen_sequence (); | |
780 | end_sequence (); | |
781 | emit_insn_after (seq, get_insns ()); | |
782 | ||
783 | /* Need to emit this whether or not we obey regdecls, | |
784 | since setjmp/longjmp can cause life info to screw up. */ | |
785 | emit_insn (gen_rtx (USE, VOIDmode, pic_offset_table_rtx)); | |
786 | } | |
787 | \f | |
788 | /* For the SPARC, REG and REG+CONST is cost 0, REG+REG is cost 1, | |
789 | and addresses involving symbolic constants are cost 2. | |
790 | ||
791 | We make REG+REG slightly more expensive because it might keep | |
792 | a register live for longer than we might like. | |
793 | ||
794 | PIC addresses are very expensive. | |
795 | ||
796 | It is no coincidence that this has the same structure | |
797 | as GO_IF_LEGITIMATE_ADDRESS. */ | |
798 | int | |
799 | sparc_address_cost (X) | |
800 | rtx X; | |
801 | { | |
802 | #if 0 | |
803 | /* Handled before calling here. */ | |
804 | if (GET_CODE (X) == REG) | |
805 | { return 1; } | |
806 | #endif | |
807 | if (GET_CODE (X) == PLUS) | |
808 | { | |
809 | if (GET_CODE (XEXP (X, 0)) == REG | |
810 | && GET_CODE (XEXP (X, 1)) == REG) | |
811 | return 2; | |
812 | return 1; | |
813 | } | |
814 | else if (GET_CODE (X) == LO_SUM) | |
815 | return 1; | |
816 | else if (GET_CODE (X) == HIGH) | |
817 | return 2; | |
818 | return 4; | |
819 | } | |
820 | \f | |
821 | /* Emit insns to move operands[1] into operands[0]. | |
822 | ||
823 | Return 1 if we have written out everything that needs to be done to | |
824 | do the move. Otherwise, return 0 and the caller will emit the move | |
825 | normally. | |
826 | ||
827 | SCRATCH_REG if non zero can be used as a scratch register for the move | |
828 | operation. It is provided by a SECONDARY_RELOAD_* macro if needed. */ | |
829 | ||
830 | int | |
831 | emit_move_sequence (operands, mode, scratch_reg) | |
832 | rtx *operands; | |
833 | enum machine_mode mode; | |
834 | rtx scratch_reg; | |
835 | { | |
836 | register rtx operand0 = operands[0]; | |
837 | register rtx operand1 = operands[1]; | |
838 | ||
839 | /* Handle most common case first: storing into a register. */ | |
840 | if (register_operand (operand0, mode)) | |
841 | { | |
842 | if (register_operand (operand1, mode) | |
843 | || (GET_CODE (operand1) == CONST_INT && SMALL_INT (operand1)) | |
844 | || (GET_CODE (operand1) == CONST_DOUBLE | |
845 | && arith_double_operand (operand1, DImode)) | |
846 | || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) != DImode) | |
847 | /* Only `general_operands' can come here, so MEM is ok. */ | |
848 | || GET_CODE (operand1) == MEM) | |
849 | { | |
850 | /* Run this case quickly. */ | |
851 | emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1)); | |
852 | return 1; | |
853 | } | |
854 | } | |
855 | else if (GET_CODE (operand0) == MEM) | |
856 | { | |
857 | if (register_operand (operand1, mode) || operand1 == const0_rtx) | |
858 | { | |
859 | /* Run this case quickly. */ | |
860 | emit_insn (gen_rtx (SET, VOIDmode, operand0, operand1)); | |
861 | return 1; | |
862 | } | |
863 | if (! reload_in_progress) | |
864 | { | |
865 | operands[0] = validize_mem (operand0); | |
866 | operands[1] = operand1 = force_reg (mode, operand1); | |
867 | } | |
868 | } | |
869 | ||
870 | /* Simplify the source if we need to. Must handle DImode HIGH operators | |
871 | here because such a move needs a clobber added. */ | |
872 | if ((GET_CODE (operand1) != HIGH && immediate_operand (operand1, mode)) | |
873 | || (GET_CODE (operand1) == HIGH && GET_MODE (operand1) == DImode)) | |
874 | { | |
875 | if (flag_pic && symbolic_operand (operand1, mode)) | |
876 | { | |
877 | rtx temp_reg = reload_in_progress ? operand0 : 0; | |
878 | ||
879 | operands[1] = legitimize_pic_address (operand1, mode, temp_reg, | |
880 | scratch_reg); | |
881 | } | |
882 | else if (GET_CODE (operand1) == CONST_INT | |
883 | ? (! SMALL_INT (operand1) | |
884 | && (INTVAL (operand1) & 0x3ff) != 0) | |
885 | : (GET_CODE (operand1) == CONST_DOUBLE | |
886 | ? ! arith_double_operand (operand1, DImode) | |
887 | : 1)) | |
888 | { | |
889 | /* For DImode values, temp must be operand0 because of the way | |
890 | HI and LO_SUM work. The LO_SUM operator only copies half of | |
891 | the LSW from the dest of the HI operator. If the LO_SUM dest is | |
892 | not the same as the HI dest, then the MSW of the LO_SUM dest will | |
893 | never be set. | |
894 | ||
895 | ??? The real problem here is that the ...(HI:DImode pattern emits | |
896 | multiple instructions, and the ...(LO_SUM:DImode pattern emits | |
897 | one instruction. This fails, because the compiler assumes that | |
898 | LO_SUM copies all bits of the first operand to its dest. Better | |
899 | would be to have the HI pattern emit one instruction and the | |
900 | LO_SUM pattern multiple instructions. Even better would be | |
901 | to use four rtl insns. */ | |
902 | rtx temp = ((reload_in_progress || mode == DImode) | |
903 | ? operand0 : gen_reg_rtx (mode)); | |
904 | ||
905 | emit_insn (gen_rtx (SET, VOIDmode, temp, | |
906 | gen_rtx (HIGH, mode, operand1))); | |
907 | operands[1] = gen_rtx (LO_SUM, mode, temp, operand1); | |
908 | } | |
909 | } | |
910 | ||
911 | if (GET_CODE (operand1) == LABEL_REF && flag_pic) | |
912 | { | |
913 | /* The procedure for doing this involves using a call instruction to | |
914 | get the pc into o7. We need to indicate this explicitly because | |
915 | the tablejump pattern assumes that it can use this value also. */ | |
916 | emit_insn (gen_rtx (PARALLEL, VOIDmode, | |
917 | gen_rtvec (2, | |
918 | gen_rtx (SET, VOIDmode, operand0, | |
919 | operand1), | |
920 | gen_rtx (SET, VOIDmode, | |
921 | gen_rtx (REG, mode, 15), | |
922 | pc_rtx)))); | |
923 | return 1; | |
924 | } | |
925 | ||
926 | /* Now have insn-emit do whatever it normally does. */ | |
927 | return 0; | |
928 | } | |
929 | \f | |
930 | /* Return the best assembler insn template | |
931 | for moving operands[1] into operands[0] as a fullword. */ | |
932 | ||
933 | char * | |
934 | singlemove_string (operands) | |
935 | rtx *operands; | |
936 | { | |
937 | if (GET_CODE (operands[0]) == MEM) | |
938 | { | |
939 | if (GET_CODE (operands[1]) != MEM) | |
940 | return "st %r1,%0"; | |
941 | else | |
942 | abort (); | |
943 | } | |
2b9a9aea | 944 | else if (GET_CODE (operands[1]) == MEM) |
ab835497 | 945 | return "ld %1,%0"; |
2b9a9aea JW |
946 | else if (GET_CODE (operands[1]) == CONST_DOUBLE) |
947 | { | |
948 | int i; | |
949 | union real_extract u; | |
950 | union float_extract { float f; int i; } v; | |
951 | ||
952 | /* Must be SFmode, otherwise this doesn't make sense. */ | |
953 | if (GET_MODE (operands[1]) != SFmode) | |
954 | abort (); | |
955 | ||
956 | bcopy (&CONST_DOUBLE_LOW (operands[1]), &u, sizeof u); | |
957 | v.f = REAL_VALUE_TRUNCATE (SFmode, u.d); | |
958 | i = v.i; | |
959 | ||
960 | operands[1] = gen_rtx (CONST_INT, VOIDmode, i); | |
961 | ||
962 | if (CONST_OK_FOR_LETTER_P (i, 'I')) | |
963 | return "mov %1,%0"; | |
964 | else if ((i & 0x000003FF) != 0) | |
965 | return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0"; | |
966 | else | |
967 | return "sethi %%hi(%a1),%0"; | |
968 | } | |
969 | else if (GET_CODE (operands[1]) == CONST_INT | |
970 | && ! CONST_OK_FOR_LETTER_P (INTVAL (operands[1]), 'I')) | |
ab835497 RK |
971 | { |
972 | int i = INTVAL (operands[1]); | |
973 | ||
915f619f | 974 | /* If all low order 10 bits are clear, then we only need a single |
ab835497 | 975 | sethi insn to load the constant. */ |
915f619f | 976 | if ((i & 0x000003FF) != 0) |
ab835497 RK |
977 | return "sethi %%hi(%a1),%0\n\tor %0,%%lo(%a1),%0"; |
978 | else | |
979 | return "sethi %%hi(%a1),%0"; | |
980 | } | |
2b9a9aea | 981 | /* Operand 1 must be a register, or a 'I' type CONST_INT. */ |
ab835497 RK |
982 | return "mov %1,%0"; |
983 | } | |
984 | \f | |
795068a4 JW |
985 | /* Return non-zero if it is OK to assume that the given memory operand is |
986 | aligned at least to a 8-byte boundary. This should only be called | |
987 | for memory accesses whose size is 8 bytes or larger. */ | |
988 | ||
7c56249d | 989 | int |
795068a4 JW |
990 | mem_aligned_8 (mem) |
991 | register rtx mem; | |
992 | { | |
993 | register rtx addr; | |
994 | register rtx base; | |
995 | register rtx offset; | |
996 | ||
997 | if (GET_CODE (mem) != MEM) | |
7c56249d | 998 | return 0; /* It's gotta be a MEM! */ |
795068a4 JW |
999 | |
1000 | addr = XEXP (mem, 0); | |
1001 | ||
1002 | #if 1 | |
1003 | /* Now that all misaligned double parms are copied on function entry, | |
1004 | we can assume any 64-bit object is 64-bit aligned. */ | |
1005 | ||
1006 | /* See what register we use in the address. */ | |
1007 | base = 0; | |
1008 | if (GET_CODE (addr) == PLUS) | |
1009 | { | |
1010 | if (GET_CODE (XEXP (addr, 0)) == REG | |
1011 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
1012 | { | |
1013 | base = XEXP (addr, 0); | |
1014 | offset = XEXP (addr, 1); | |
1015 | } | |
1016 | } | |
1017 | else if (GET_CODE (addr) == REG) | |
1018 | { | |
1019 | base = addr; | |
1020 | offset = const0_rtx; | |
1021 | } | |
1022 | ||
1023 | /* If it's the stack or frame pointer, check offset alignment. | |
2296cba3 | 1024 | We can have improper alignment in the function entry code. */ |
795068a4 JW |
1025 | if (base |
1026 | && (REGNO (base) == FRAME_POINTER_REGNUM | |
1027 | || REGNO (base) == STACK_POINTER_REGNUM)) | |
1028 | { | |
1029 | if ((INTVAL (offset) & 0x7) == 0) | |
1030 | return 1; | |
1031 | } | |
1032 | else | |
1033 | /* Anything else, we know is properly aligned. */ | |
1034 | return 1; | |
1035 | #else | |
1036 | /* If the operand is known to have been allocated in static storage, then | |
1037 | it must be aligned. */ | |
1038 | ||
1039 | if (CONSTANT_P (addr) || GET_CODE (addr) == LO_SUM) | |
1040 | return 1; | |
1041 | ||
1042 | base = 0; | |
1043 | if (GET_CODE (addr) == PLUS) | |
1044 | { | |
1045 | if (GET_CODE (XEXP (addr, 0)) == REG | |
1046 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
1047 | { | |
1048 | base = XEXP (addr, 0); | |
1049 | offset = XEXP (addr, 1); | |
1050 | } | |
1051 | } | |
1052 | else if (GET_CODE (addr) == REG) | |
1053 | { | |
1054 | base = addr; | |
1055 | offset = const0_rtx; | |
1056 | } | |
1057 | ||
1058 | /* Trust round enough offsets from the stack or frame pointer. | |
1059 | If TARGET_HOPE_ALIGN, trust round enough offset from any register. | |
1060 | If it is obviously unaligned, don't ever return true. */ | |
1061 | if (base | |
1062 | && (REGNO (base) == FRAME_POINTER_REGNUM | |
1063 | || REGNO (base) == STACK_POINTER_REGNUM | |
1064 | || TARGET_HOPE_ALIGN)) | |
1065 | { | |
1066 | if ((INTVAL (offset) & 0x7) == 0) | |
1067 | return 1; | |
1068 | } | |
1069 | /* Otherwise, we can assume that an access is aligned if it is to an | |
1070 | aggregate. Also, if TARGET_HOPE_ALIGN, then assume everything that isn't | |
1071 | obviously unaligned is aligned. */ | |
1072 | else if (MEM_IN_STRUCT_P (mem) || TARGET_HOPE_ALIGN) | |
1073 | return 1; | |
1074 | #endif | |
1075 | ||
1076 | /* An obviously unaligned address. */ | |
1077 | return 0; | |
1078 | } | |
1079 | ||
1080 | enum optype { REGOP, OFFSOP, MEMOP, PUSHOP, POPOP, CNSTOP, RNDOP }; | |
1081 | ||
ab835497 | 1082 | /* Output assembler code to perform a doubleword move insn |
795068a4 JW |
1083 | with operands OPERANDS. This is very similar to the following |
1084 | output_move_quad function. */ | |
ab835497 RK |
1085 | |
1086 | char * | |
1087 | output_move_double (operands) | |
1088 | rtx *operands; | |
1089 | { | |
795068a4 JW |
1090 | register rtx op0 = operands[0]; |
1091 | register rtx op1 = operands[1]; | |
1092 | register enum optype optype0; | |
1093 | register enum optype optype1; | |
ab835497 | 1094 | rtx latehalf[2]; |
795068a4 JW |
1095 | rtx addreg0 = 0; |
1096 | rtx addreg1 = 0; | |
ab835497 RK |
1097 | |
1098 | /* First classify both operands. */ | |
1099 | ||
795068a4 | 1100 | if (REG_P (op0)) |
ab835497 | 1101 | optype0 = REGOP; |
795068a4 | 1102 | else if (offsettable_memref_p (op0)) |
ab835497 | 1103 | optype0 = OFFSOP; |
795068a4 | 1104 | else if (GET_CODE (op0) == MEM) |
ab835497 RK |
1105 | optype0 = MEMOP; |
1106 | else | |
1107 | optype0 = RNDOP; | |
1108 | ||
795068a4 | 1109 | if (REG_P (op1)) |
ab835497 | 1110 | optype1 = REGOP; |
795068a4 | 1111 | else if (CONSTANT_P (op1)) |
ab835497 | 1112 | optype1 = CNSTOP; |
795068a4 | 1113 | else if (offsettable_memref_p (op1)) |
ab835497 | 1114 | optype1 = OFFSOP; |
795068a4 | 1115 | else if (GET_CODE (op1) == MEM) |
ab835497 RK |
1116 | optype1 = MEMOP; |
1117 | else | |
1118 | optype1 = RNDOP; | |
1119 | ||
1120 | /* Check for the cases that the operand constraints are not | |
1121 | supposed to allow to happen. Abort if we get one, | |
1122 | because generating code for these cases is painful. */ | |
1123 | ||
795068a4 JW |
1124 | if (optype0 == RNDOP || optype1 == RNDOP |
1125 | || (optype0 == MEM && optype1 == MEM)) | |
ab835497 RK |
1126 | abort (); |
1127 | ||
1128 | /* If an operand is an unoffsettable memory ref, find a register | |
1129 | we can increment temporarily to make it refer to the second word. */ | |
1130 | ||
1131 | if (optype0 == MEMOP) | |
795068a4 | 1132 | addreg0 = find_addr_reg (XEXP (op0, 0)); |
ab835497 RK |
1133 | |
1134 | if (optype1 == MEMOP) | |
795068a4 | 1135 | addreg1 = find_addr_reg (XEXP (op1, 0)); |
ab835497 RK |
1136 | |
1137 | /* Ok, we can do one word at a time. | |
795068a4 | 1138 | Set up in LATEHALF the operands to use for the |
ab835497 RK |
1139 | high-numbered (least significant) word and in some cases alter the |
1140 | operands in OPERANDS to be suitable for the low-numbered word. */ | |
1141 | ||
1142 | if (optype0 == REGOP) | |
795068a4 | 1143 | latehalf[0] = gen_rtx (REG, SImode, REGNO (op0) + 1); |
ab835497 | 1144 | else if (optype0 == OFFSOP) |
795068a4 | 1145 | latehalf[0] = adj_offsettable_operand (op0, 4); |
ab835497 | 1146 | else |
795068a4 | 1147 | latehalf[0] = op0; |
ab835497 RK |
1148 | |
1149 | if (optype1 == REGOP) | |
795068a4 | 1150 | latehalf[1] = gen_rtx (REG, SImode, REGNO (op1) + 1); |
ab835497 | 1151 | else if (optype1 == OFFSOP) |
795068a4 | 1152 | latehalf[1] = adj_offsettable_operand (op1, 4); |
ab835497 | 1153 | else if (optype1 == CNSTOP) |
795068a4 | 1154 | split_double (op1, &operands[1], &latehalf[1]); |
ab835497 | 1155 | else |
795068a4 | 1156 | latehalf[1] = op1; |
ab835497 | 1157 | |
795068a4 JW |
1158 | /* Easy case: try moving both words at once. Check for moving between |
1159 | an even/odd register pair and a memory location. */ | |
ab835497 | 1160 | if ((optype0 == REGOP && optype1 != REGOP && optype1 != CNSTOP |
795068a4 | 1161 | && (REGNO (op0) & 1) == 0) |
ab835497 | 1162 | || (optype0 != REGOP && optype0 != CNSTOP && optype1 == REGOP |
795068a4 | 1163 | && (REGNO (op1) & 1) == 0)) |
ab835497 | 1164 | { |
795068a4 | 1165 | register rtx mem; |
bc961ed7 RS |
1166 | |
1167 | if (optype0 == REGOP) | |
795068a4 | 1168 | mem = op1; |
bc961ed7 | 1169 | else |
795068a4 | 1170 | mem = op0; |
bc961ed7 | 1171 | |
795068a4 JW |
1172 | if (mem_aligned_8 (mem)) |
1173 | return (mem == op1 ? "ldd %1,%0" : "std %1,%0"); | |
ab835497 RK |
1174 | } |
1175 | ||
795068a4 JW |
1176 | /* If the first move would clobber the source of the second one, |
1177 | do them in the other order. */ | |
1178 | ||
1179 | /* Overlapping registers. */ | |
ab835497 | 1180 | if (optype0 == REGOP && optype1 == REGOP |
795068a4 | 1181 | && REGNO (op0) == REGNO (latehalf[1])) |
ab835497 | 1182 | { |
ab835497 RK |
1183 | /* Do that word. */ |
1184 | output_asm_insn (singlemove_string (latehalf), latehalf); | |
ab835497 RK |
1185 | /* Do low-numbered word. */ |
1186 | return singlemove_string (operands); | |
1187 | } | |
795068a4 | 1188 | /* Loading into a register which overlaps a register used in the address. */ |
ab835497 | 1189 | else if (optype0 == REGOP && optype1 != REGOP |
795068a4 | 1190 | && reg_overlap_mentioned_p (op0, op1)) |
ab835497 | 1191 | { |
795068a4 JW |
1192 | /* ??? This fails if the address is a double register address, each |
1193 | of which is clobbered by operand 0. */ | |
ab835497 RK |
1194 | /* Do the late half first. */ |
1195 | output_asm_insn (singlemove_string (latehalf), latehalf); | |
1196 | /* Then clobber. */ | |
1197 | return singlemove_string (operands); | |
1198 | } | |
1199 | ||
1200 | /* Normal case: do the two words, low-numbered first. */ | |
1201 | ||
1202 | output_asm_insn (singlemove_string (operands), operands); | |
1203 | ||
1204 | /* Make any unoffsettable addresses point at high-numbered word. */ | |
1205 | if (addreg0) | |
1206 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
1207 | if (addreg1) | |
1208 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
1209 | ||
1210 | /* Do that word. */ | |
1211 | output_asm_insn (singlemove_string (latehalf), latehalf); | |
1212 | ||
1213 | /* Undo the adds we just did. */ | |
1214 | if (addreg0) | |
1215 | output_asm_insn ("add %0,-0x4,%0", &addreg0); | |
1216 | if (addreg1) | |
1217 | output_asm_insn ("add %0,-0x4,%0", &addreg1); | |
1218 | ||
1219 | return ""; | |
1220 | } | |
795068a4 JW |
1221 | |
1222 | /* Output assembler code to perform a quadword move insn | |
2296cba3 | 1223 | with operands OPERANDS. This is very similar to the preceding |
795068a4 JW |
1224 | output_move_double function. */ |
1225 | ||
1226 | char * | |
1227 | output_move_quad (operands) | |
1228 | rtx *operands; | |
1229 | { | |
1230 | register rtx op0 = operands[0]; | |
1231 | register rtx op1 = operands[1]; | |
1232 | register enum optype optype0; | |
1233 | register enum optype optype1; | |
1234 | rtx wordpart[4][2]; | |
1235 | rtx addreg0 = 0; | |
1236 | rtx addreg1 = 0; | |
1237 | ||
1238 | /* First classify both operands. */ | |
1239 | ||
1240 | if (REG_P (op0)) | |
1241 | optype0 = REGOP; | |
1242 | else if (offsettable_memref_p (op0)) | |
1243 | optype0 = OFFSOP; | |
1244 | else if (GET_CODE (op0) == MEM) | |
1245 | optype0 = MEMOP; | |
1246 | else | |
1247 | optype0 = RNDOP; | |
1248 | ||
1249 | if (REG_P (op1)) | |
1250 | optype1 = REGOP; | |
1251 | else if (CONSTANT_P (op1)) | |
1252 | optype1 = CNSTOP; | |
1253 | else if (offsettable_memref_p (op1)) | |
1254 | optype1 = OFFSOP; | |
1255 | else if (GET_CODE (op1) == MEM) | |
1256 | optype1 = MEMOP; | |
1257 | else | |
1258 | optype1 = RNDOP; | |
1259 | ||
1260 | /* Check for the cases that the operand constraints are not | |
1261 | supposed to allow to happen. Abort if we get one, | |
1262 | because generating code for these cases is painful. */ | |
1263 | ||
1264 | if (optype0 == RNDOP || optype1 == RNDOP | |
1265 | || (optype0 == MEM && optype1 == MEM)) | |
1266 | abort (); | |
1267 | ||
1268 | /* If an operand is an unoffsettable memory ref, find a register | |
1269 | we can increment temporarily to make it refer to the later words. */ | |
1270 | ||
1271 | if (optype0 == MEMOP) | |
1272 | addreg0 = find_addr_reg (XEXP (op0, 0)); | |
1273 | ||
1274 | if (optype1 == MEMOP) | |
1275 | addreg1 = find_addr_reg (XEXP (op1, 0)); | |
1276 | ||
1277 | /* Ok, we can do one word at a time. | |
1278 | Set up in wordpart the operands to use for each word of the arguments. */ | |
1279 | ||
1280 | if (optype0 == REGOP) | |
1281 | { | |
1282 | wordpart[0][0] = gen_rtx (REG, SImode, REGNO (op0) + 0); | |
1283 | wordpart[1][0] = gen_rtx (REG, SImode, REGNO (op0) + 1); | |
1284 | wordpart[2][0] = gen_rtx (REG, SImode, REGNO (op0) + 2); | |
1285 | wordpart[3][0] = gen_rtx (REG, SImode, REGNO (op0) + 3); | |
1286 | } | |
1287 | else if (optype0 == OFFSOP) | |
1288 | { | |
1289 | wordpart[0][0] = adj_offsettable_operand (op0, 0); | |
1290 | wordpart[1][0] = adj_offsettable_operand (op0, 4); | |
1291 | wordpart[2][0] = adj_offsettable_operand (op0, 8); | |
1292 | wordpart[3][0] = adj_offsettable_operand (op0, 12); | |
1293 | } | |
1294 | else | |
1295 | { | |
1296 | wordpart[0][0] = op0; | |
1297 | wordpart[1][0] = op0; | |
1298 | wordpart[2][0] = op0; | |
1299 | wordpart[3][0] = op0; | |
1300 | } | |
1301 | ||
1302 | if (optype1 == REGOP) | |
1303 | { | |
1304 | wordpart[0][1] = gen_rtx (REG, SImode, REGNO (op1) + 0); | |
1305 | wordpart[1][1] = gen_rtx (REG, SImode, REGNO (op1) + 1); | |
1306 | wordpart[2][1] = gen_rtx (REG, SImode, REGNO (op1) + 2); | |
1307 | wordpart[3][1] = gen_rtx (REG, SImode, REGNO (op1) + 3); | |
1308 | } | |
1309 | else if (optype1 == OFFSOP) | |
1310 | { | |
1311 | wordpart[0][1] = adj_offsettable_operand (op1, 0); | |
1312 | wordpart[1][1] = adj_offsettable_operand (op1, 4); | |
1313 | wordpart[2][1] = adj_offsettable_operand (op1, 8); | |
1314 | wordpart[3][1] = adj_offsettable_operand (op1, 12); | |
1315 | } | |
1316 | else if (optype1 == CNSTOP) | |
1317 | { | |
1318 | /* This case isn't implemented yet, because there is no internal | |
1319 | representation for quad-word constants, and there is no split_quad | |
1320 | function. */ | |
1321 | #if 0 | |
1322 | split_quad (op1, &wordpart[0][1], &wordpart[1][1], | |
1323 | &wordpart[2][1], &wordpart[3][1]); | |
1324 | #else | |
1325 | abort (); | |
1326 | #endif | |
1327 | } | |
1328 | else | |
1329 | { | |
1330 | wordpart[0][1] = op1; | |
1331 | wordpart[1][1] = op1; | |
1332 | wordpart[2][1] = op1; | |
1333 | wordpart[3][1] = op1; | |
1334 | } | |
1335 | ||
1336 | /* Easy case: try moving the quad as two pairs. Check for moving between | |
1337 | an even/odd register pair and a memory location. */ | |
1338 | /* ??? Should also handle the case of non-offsettable addresses here. | |
1339 | We can at least do the first pair as a ldd/std, and then do the third | |
1340 | and fourth words individually. */ | |
1341 | if ((optype0 == REGOP && optype1 == OFFSOP && (REGNO (op0) & 1) == 0) | |
1342 | || (optype0 == OFFSOP && optype1 == REGOP && (REGNO (op1) & 1) == 0)) | |
1343 | { | |
1344 | rtx mem; | |
1345 | ||
1346 | if (optype0 == REGOP) | |
1347 | mem = op1; | |
1348 | else | |
1349 | mem = op0; | |
1350 | ||
1351 | if (mem_aligned_8 (mem)) | |
1352 | { | |
1353 | operands[2] = adj_offsettable_operand (mem, 8); | |
1354 | if (mem == op1) | |
1355 | return "ldd %1,%0;ldd %2,%S0"; | |
1356 | else | |
1357 | return "std %1,%0;std %S1,%2"; | |
1358 | } | |
1359 | } | |
1360 | ||
1361 | /* If the first move would clobber the source of the second one, | |
1362 | do them in the other order. */ | |
1363 | ||
1364 | /* Overlapping registers. */ | |
1365 | if (optype0 == REGOP && optype1 == REGOP | |
1366 | && (REGNO (op0) == REGNO (wordpart[1][3]) | |
1367 | || REGNO (op0) == REGNO (wordpart[1][2]) | |
1368 | || REGNO (op0) == REGNO (wordpart[1][1]))) | |
1369 | { | |
1370 | /* Do fourth word. */ | |
1371 | output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]); | |
1372 | /* Do the third word. */ | |
1373 | output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]); | |
1374 | /* Do the second word. */ | |
1375 | output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]); | |
1376 | /* Do lowest-numbered word. */ | |
1377 | return singlemove_string (wordpart[0]); | |
1378 | } | |
1379 | /* Loading into a register which overlaps a register used in the address. */ | |
1380 | if (optype0 == REGOP && optype1 != REGOP | |
1381 | && reg_overlap_mentioned_p (op0, op1)) | |
1382 | { | |
1383 | /* ??? Not implemented yet. This is a bit complicated, because we | |
1384 | must load which ever part overlaps the address last. If the address | |
1385 | is a double-reg address, then there are two parts which need to | |
1386 | be done last, which is impossible. We would need a scratch register | |
1387 | in that case. */ | |
1388 | abort (); | |
1389 | } | |
1390 | ||
1391 | /* Normal case: move the four words in lowest to higest address order. */ | |
1392 | ||
1393 | output_asm_insn (singlemove_string (wordpart[0]), wordpart[0]); | |
1394 | ||
1395 | /* Make any unoffsettable addresses point at the second word. */ | |
1396 | if (addreg0) | |
1397 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
1398 | if (addreg1) | |
1399 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
1400 | ||
1401 | /* Do the second word. */ | |
1402 | output_asm_insn (singlemove_string (wordpart[1]), wordpart[1]); | |
1403 | ||
1404 | /* Make any unoffsettable addresses point at the third word. */ | |
1405 | if (addreg0) | |
1406 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
1407 | if (addreg1) | |
1408 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
1409 | ||
1410 | /* Do the third word. */ | |
1411 | output_asm_insn (singlemove_string (wordpart[2]), wordpart[2]); | |
1412 | ||
1413 | /* Make any unoffsettable addresses point at the fourth word. */ | |
1414 | if (addreg0) | |
1415 | output_asm_insn ("add %0,0x4,%0", &addreg0); | |
1416 | if (addreg1) | |
1417 | output_asm_insn ("add %0,0x4,%0", &addreg1); | |
1418 | ||
1419 | /* Do the fourth word. */ | |
1420 | output_asm_insn (singlemove_string (wordpart[3]), wordpart[3]); | |
1421 | ||
1422 | /* Undo the adds we just did. */ | |
1423 | if (addreg0) | |
1424 | output_asm_insn ("add %0,-0xc,%0", &addreg0); | |
1425 | if (addreg1) | |
1426 | output_asm_insn ("add %0,-0xc,%0", &addreg1); | |
1427 | ||
1428 | return ""; | |
1429 | } | |
ab835497 | 1430 | \f |
795068a4 | 1431 | /* Output assembler code to perform a doubleword move insn with operands |
a3ee5899 JW |
1432 | OPERANDS, one of which must be a floating point register. */ |
1433 | ||
ab835497 RK |
1434 | char * |
1435 | output_fp_move_double (operands) | |
1436 | rtx *operands; | |
1437 | { | |
ab835497 RK |
1438 | if (FP_REG_P (operands[0])) |
1439 | { | |
1440 | if (FP_REG_P (operands[1])) | |
1441 | return "fmovs %1,%0\n\tfmovs %R1,%R0"; | |
a3ee5899 | 1442 | else if (GET_CODE (operands[1]) == REG) |
019c2b24 | 1443 | abort (); |
a3ee5899 JW |
1444 | else |
1445 | return output_move_double (operands); | |
ab835497 RK |
1446 | } |
1447 | else if (FP_REG_P (operands[1])) | |
1448 | { | |
1449 | if (GET_CODE (operands[0]) == REG) | |
019c2b24 | 1450 | abort (); |
a3ee5899 JW |
1451 | else |
1452 | return output_move_double (operands); | |
ab835497 RK |
1453 | } |
1454 | else abort (); | |
1455 | } | |
795068a4 JW |
1456 | |
1457 | /* Output assembler code to perform a quadword move insn with operands | |
1458 | OPERANDS, one of which must be a floating point register. */ | |
1459 | ||
1460 | char * | |
1461 | output_fp_move_quad (operands) | |
1462 | rtx *operands; | |
1463 | { | |
1464 | register rtx op0 = operands[0]; | |
1465 | register rtx op1 = operands[1]; | |
795068a4 JW |
1466 | |
1467 | if (FP_REG_P (op0)) | |
1468 | { | |
1469 | if (FP_REG_P (op1)) | |
1470 | return "fmovs %1,%0\n\tfmovs %R1,%R0\n\tfmovs %S1,%S0\n\tfmovs %T1,%T0"; | |
019c2b24 JW |
1471 | else if (GET_CODE (op1) == REG) |
1472 | abort (); | |
795068a4 JW |
1473 | else |
1474 | return output_move_quad (operands); | |
1475 | } | |
1476 | else if (FP_REG_P (op1)) | |
1477 | { | |
1478 | if (GET_CODE (op0) == REG) | |
019c2b24 | 1479 | abort (); |
795068a4 JW |
1480 | else |
1481 | return output_move_quad (operands); | |
1482 | } | |
1483 | else | |
1484 | abort (); | |
1485 | } | |
ab835497 RK |
1486 | \f |
1487 | /* Return a REG that occurs in ADDR with coefficient 1. | |
1488 | ADDR can be effectively incremented by incrementing REG. */ | |
1489 | ||
1490 | static rtx | |
1491 | find_addr_reg (addr) | |
1492 | rtx addr; | |
1493 | { | |
1494 | while (GET_CODE (addr) == PLUS) | |
1495 | { | |
1496 | /* We absolutely can not fudge the frame pointer here, because the | |
1497 | frame pointer must always be 8 byte aligned. It also confuses | |
1498 | debuggers. */ | |
1499 | if (GET_CODE (XEXP (addr, 0)) == REG | |
1500 | && REGNO (XEXP (addr, 0)) != FRAME_POINTER_REGNUM) | |
1501 | addr = XEXP (addr, 0); | |
1502 | else if (GET_CODE (XEXP (addr, 1)) == REG | |
1503 | && REGNO (XEXP (addr, 1)) != FRAME_POINTER_REGNUM) | |
1504 | addr = XEXP (addr, 1); | |
1505 | else if (CONSTANT_P (XEXP (addr, 0))) | |
1506 | addr = XEXP (addr, 1); | |
1507 | else if (CONSTANT_P (XEXP (addr, 1))) | |
1508 | addr = XEXP (addr, 0); | |
1509 | else | |
1510 | abort (); | |
1511 | } | |
1512 | if (GET_CODE (addr) == REG) | |
1513 | return addr; | |
1514 | abort (); | |
1515 | } | |
1516 | ||
1517 | void | |
1518 | output_sized_memop (opname, mode, signedp) | |
1519 | char *opname; | |
1520 | enum machine_mode mode; | |
1521 | int signedp; | |
1522 | { | |
1523 | static char *ld_size_suffix_u[] = { "ub", "uh", "", "?", "d" }; | |
1524 | static char *ld_size_suffix_s[] = { "sb", "sh", "", "?", "d" }; | |
1525 | static char *st_size_suffix[] = { "b", "h", "", "?", "d" }; | |
1526 | char **opnametab, *modename; | |
1527 | ||
1528 | if (opname[0] == 'l') | |
1529 | if (signedp) | |
1530 | opnametab = ld_size_suffix_s; | |
1531 | else | |
1532 | opnametab = ld_size_suffix_u; | |
1533 | else | |
1534 | opnametab = st_size_suffix; | |
1535 | modename = opnametab[GET_MODE_SIZE (mode) >> 1]; | |
1536 | ||
1537 | fprintf (asm_out_file, "\t%s%s", opname, modename); | |
1538 | } | |
1539 | \f | |
1540 | void | |
1541 | output_move_with_extension (operands) | |
1542 | rtx *operands; | |
1543 | { | |
1544 | if (GET_MODE (operands[2]) == HImode) | |
1545 | output_asm_insn ("sll %2,0x10,%0", operands); | |
1546 | else if (GET_MODE (operands[2]) == QImode) | |
1547 | output_asm_insn ("sll %2,0x18,%0", operands); | |
1548 | else | |
1549 | abort (); | |
1550 | } | |
1551 | \f | |
1552 | /* Load the address specified by OPERANDS[3] into the register | |
1553 | specified by OPERANDS[0]. | |
1554 | ||
1555 | OPERANDS[3] may be the result of a sum, hence it could either be: | |
1556 | ||
1557 | (1) CONST | |
1558 | (2) REG | |
1559 | (2) REG + CONST_INT | |
1560 | (3) REG + REG + CONST_INT | |
1561 | (4) REG + REG (special case of 3). | |
1562 | ||
1563 | Note that (3) is not a legitimate address. | |
1564 | All cases are handled here. */ | |
1565 | ||
1566 | void | |
1567 | output_load_address (operands) | |
1568 | rtx *operands; | |
1569 | { | |
1570 | rtx base, offset; | |
1571 | ||
1572 | if (CONSTANT_P (operands[3])) | |
1573 | { | |
1574 | output_asm_insn ("set %3,%0", operands); | |
1575 | return; | |
1576 | } | |
1577 | ||
1578 | if (REG_P (operands[3])) | |
1579 | { | |
1580 | if (REGNO (operands[0]) != REGNO (operands[3])) | |
1581 | output_asm_insn ("mov %3,%0", operands); | |
1582 | return; | |
1583 | } | |
1584 | ||
1585 | if (GET_CODE (operands[3]) != PLUS) | |
1586 | abort (); | |
1587 | ||
1588 | base = XEXP (operands[3], 0); | |
1589 | offset = XEXP (operands[3], 1); | |
1590 | ||
1591 | if (GET_CODE (base) == CONST_INT) | |
1592 | { | |
1593 | rtx tmp = base; | |
1594 | base = offset; | |
1595 | offset = tmp; | |
1596 | } | |
1597 | ||
1598 | if (GET_CODE (offset) != CONST_INT) | |
1599 | { | |
1600 | /* Operand is (PLUS (REG) (REG)). */ | |
1601 | base = operands[3]; | |
1602 | offset = const0_rtx; | |
1603 | } | |
1604 | ||
1605 | if (REG_P (base)) | |
1606 | { | |
1607 | operands[6] = base; | |
1608 | operands[7] = offset; | |
1609 | if (SMALL_INT (offset)) | |
1610 | output_asm_insn ("add %6,%7,%0", operands); | |
1611 | else | |
1612 | output_asm_insn ("set %7,%0\n\tadd %0,%6,%0", operands); | |
1613 | } | |
1614 | else if (GET_CODE (base) == PLUS) | |
1615 | { | |
1616 | operands[6] = XEXP (base, 0); | |
1617 | operands[7] = XEXP (base, 1); | |
1618 | operands[8] = offset; | |
1619 | ||
1620 | if (SMALL_INT (offset)) | |
1621 | output_asm_insn ("add %6,%7,%0\n\tadd %0,%8,%0", operands); | |
1622 | else | |
1623 | output_asm_insn ("set %8,%0\n\tadd %0,%6,%0\n\tadd %0,%7,%0", operands); | |
1624 | } | |
1625 | else | |
1626 | abort (); | |
1627 | } | |
1628 | ||
1629 | /* Output code to place a size count SIZE in register REG. | |
1630 | ALIGN is the size of the unit of transfer. | |
1631 | ||
1632 | Because block moves are pipelined, we don't include the | |
1633 | first element in the transfer of SIZE to REG. */ | |
1634 | ||
1635 | static void | |
1636 | output_size_for_block_move (size, reg, align) | |
1637 | rtx size, reg; | |
1638 | rtx align; | |
1639 | { | |
1640 | rtx xoperands[3]; | |
1641 | ||
1642 | xoperands[0] = reg; | |
1643 | xoperands[1] = size; | |
1644 | xoperands[2] = align; | |
1645 | if (GET_CODE (size) == REG) | |
1646 | output_asm_insn ("sub %1,%2,%0", xoperands); | |
1647 | else | |
1648 | { | |
1649 | xoperands[1] | |
1650 | = gen_rtx (CONST_INT, VOIDmode, INTVAL (size) - INTVAL (align)); | |
1651 | output_asm_insn ("set %1,%0", xoperands); | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | /* Emit code to perform a block move. | |
1656 | ||
1657 | OPERANDS[0] is the destination. | |
1658 | OPERANDS[1] is the source. | |
1659 | OPERANDS[2] is the size. | |
1660 | OPERANDS[3] is the alignment safe to use. | |
1661 | OPERANDS[4] is a register we can safely clobber as a temp. */ | |
1662 | ||
1663 | char * | |
1664 | output_block_move (operands) | |
1665 | rtx *operands; | |
1666 | { | |
1667 | /* A vector for our computed operands. Note that load_output_address | |
1668 | makes use of (and can clobber) up to the 8th element of this vector. */ | |
1669 | rtx xoperands[10]; | |
1670 | rtx zoperands[10]; | |
1671 | static int movstrsi_label = 0; | |
1672 | int i; | |
1673 | rtx temp1 = operands[4]; | |
1674 | rtx sizertx = operands[2]; | |
1675 | rtx alignrtx = operands[3]; | |
1676 | int align = INTVAL (alignrtx); | |
210aa14a | 1677 | char label3[30], label5[30]; |
ab835497 RK |
1678 | |
1679 | xoperands[0] = operands[0]; | |
1680 | xoperands[1] = operands[1]; | |
1681 | xoperands[2] = temp1; | |
1682 | ||
391b99c9 RS |
1683 | /* We can't move more than this many bytes at a time because we have only |
1684 | one register, %g1, to move them through. */ | |
1685 | if (align > UNITS_PER_WORD) | |
ab835497 | 1686 | { |
391b99c9 RS |
1687 | align = UNITS_PER_WORD; |
1688 | alignrtx = gen_rtx (CONST_INT, VOIDmode, UNITS_PER_WORD); | |
ab835497 RK |
1689 | } |
1690 | ||
391b99c9 RS |
1691 | /* We consider 8 ld/st pairs, for a total of 16 inline insns to be |
1692 | reasonable here. (Actually will emit a maximum of 18 inline insns for | |
1693 | the case of size == 31 and align == 4). */ | |
1694 | ||
1695 | if (GET_CODE (sizertx) == CONST_INT && (INTVAL (sizertx) / align) <= 8 | |
1696 | && memory_address_p (QImode, plus_constant_for_output (xoperands[0], | |
1697 | INTVAL (sizertx))) | |
1698 | && memory_address_p (QImode, plus_constant_for_output (xoperands[1], | |
1699 | INTVAL (sizertx)))) | |
ab835497 RK |
1700 | { |
1701 | int size = INTVAL (sizertx); | |
391b99c9 | 1702 | int offset = 0; |
ab835497 | 1703 | |
391b99c9 RS |
1704 | /* We will store different integers into this particular RTX. */ |
1705 | xoperands[2] = rtx_alloc (CONST_INT); | |
1706 | PUT_MODE (xoperands[2], VOIDmode); | |
ab835497 | 1707 | |
391b99c9 RS |
1708 | /* This case is currently not handled. Abort instead of generating |
1709 | bad code. */ | |
1710 | if (align > 4) | |
1711 | abort (); | |
ab835497 | 1712 | |
391b99c9 | 1713 | if (align >= 4) |
ab835497 | 1714 | { |
391b99c9 | 1715 | for (i = (size >> 2) - 1; i >= 0; i--) |
ab835497 | 1716 | { |
391b99c9 RS |
1717 | INTVAL (xoperands[2]) = (i << 2) + offset; |
1718 | output_asm_insn ("ld [%a1+%2],%%g1\n\tst %%g1,[%a0+%2]", | |
1719 | xoperands); | |
ab835497 | 1720 | } |
391b99c9 RS |
1721 | offset += (size & ~0x3); |
1722 | size = size & 0x3; | |
1723 | if (size == 0) | |
1724 | return ""; | |
ab835497 | 1725 | } |
391b99c9 RS |
1726 | |
1727 | if (align >= 2) | |
ab835497 | 1728 | { |
391b99c9 | 1729 | for (i = (size >> 1) - 1; i >= 0; i--) |
ab835497 | 1730 | { |
391b99c9 RS |
1731 | INTVAL (xoperands[2]) = (i << 1) + offset; |
1732 | output_asm_insn ("lduh [%a1+%2],%%g1\n\tsth %%g1,[%a0+%2]", | |
1733 | xoperands); | |
ab835497 | 1734 | } |
391b99c9 RS |
1735 | offset += (size & ~0x1); |
1736 | size = size & 0x1; | |
1737 | if (size == 0) | |
1738 | return ""; | |
ab835497 | 1739 | } |
391b99c9 RS |
1740 | |
1741 | if (align >= 1) | |
ab835497 | 1742 | { |
391b99c9 | 1743 | for (i = size - 1; i >= 0; i--) |
ab835497 | 1744 | { |
391b99c9 RS |
1745 | INTVAL (xoperands[2]) = i + offset; |
1746 | output_asm_insn ("ldub [%a1+%2],%%g1\n\tstb %%g1,[%a0+%2]", | |
1747 | xoperands); | |
ab835497 | 1748 | } |
391b99c9 | 1749 | return ""; |
ab835497 | 1750 | } |
391b99c9 RS |
1751 | |
1752 | /* We should never reach here. */ | |
1753 | abort (); | |
ab835497 RK |
1754 | } |
1755 | ||
391b99c9 RS |
1756 | /* If the size isn't known to be a multiple of the alignment, |
1757 | we have to do it in smaller pieces. If we could determine that | |
1758 | the size was a multiple of 2 (or whatever), we could be smarter | |
1759 | about this. */ | |
1760 | if (GET_CODE (sizertx) != CONST_INT) | |
1761 | align = 1; | |
1762 | else | |
1763 | { | |
1764 | int size = INTVAL (sizertx); | |
1765 | while (size % align) | |
1766 | align >>= 1; | |
1767 | } | |
1768 | ||
1769 | if (align != INTVAL (alignrtx)) | |
1770 | alignrtx = gen_rtx (CONST_INT, VOIDmode, align); | |
1771 | ||
ab835497 RK |
1772 | xoperands[3] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++); |
1773 | xoperands[4] = gen_rtx (CONST_INT, VOIDmode, align); | |
1774 | xoperands[5] = gen_rtx (CONST_INT, VOIDmode, movstrsi_label++); | |
1775 | ||
210aa14a RS |
1776 | ASM_GENERATE_INTERNAL_LABEL (label3, "Lm", INTVAL (xoperands[3])); |
1777 | ASM_GENERATE_INTERNAL_LABEL (label5, "Lm", INTVAL (xoperands[5])); | |
1778 | ||
391b99c9 RS |
1779 | /* This is the size of the transfer. Emit code to decrement the size |
1780 | value by ALIGN, and store the result in the temp1 register. */ | |
ab835497 RK |
1781 | output_size_for_block_move (sizertx, temp1, alignrtx); |
1782 | ||
1783 | /* Must handle the case when the size is zero or negative, so the first thing | |
1784 | we do is compare the size against zero, and only copy bytes if it is | |
1785 | zero or greater. Note that we have already subtracted off the alignment | |
1786 | once, so we must copy 1 alignment worth of bytes if the size is zero | |
1787 | here. | |
1788 | ||
1789 | The SUN assembler complains about labels in branch delay slots, so we | |
b4ac57ab | 1790 | do this before outputting the load address, so that there will always |
ab835497 RK |
1791 | be a harmless insn between the branch here and the next label emitted |
1792 | below. */ | |
1793 | ||
210aa14a RS |
1794 | { |
1795 | char pattern[100]; | |
1796 | ||
1797 | sprintf (pattern, "cmp %%2,0\n\tbl %s", &label5[1]); | |
1798 | output_asm_insn (pattern, xoperands); | |
1799 | } | |
ab835497 RK |
1800 | |
1801 | zoperands[0] = operands[0]; | |
1802 | zoperands[3] = plus_constant_for_output (operands[0], align); | |
1803 | output_load_address (zoperands); | |
1804 | ||
1805 | /* ??? This might be much faster if the loops below were preconditioned | |
1806 | and unrolled. | |
1807 | ||
1808 | That is, at run time, copy enough bytes one at a time to ensure that the | |
1809 | target and source addresses are aligned to the the largest possible | |
1810 | alignment. Then use a preconditioned unrolled loop to copy say 16 | |
1811 | bytes at a time. Then copy bytes one at a time until finish the rest. */ | |
1812 | ||
1813 | /* Output the first label separately, so that it is spaced properly. */ | |
1814 | ||
ab835497 | 1815 | ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "Lm", INTVAL (xoperands[3])); |
ab835497 | 1816 | |
210aa14a RS |
1817 | { |
1818 | char pattern[200]; | |
1819 | register char *ld_suffix = (align == 1) ? "ub" : (align == 2) ? "uh" : ""; | |
1820 | register char *st_suffix = (align == 1) ? "b" : (align == 2) ? "h" : ""; | |
1821 | ||
1822 | sprintf (pattern, "ld%s [%%1+%%2],%%%%g1\n\tsubcc %%2,%%4,%%2\n\tbge %s\n\tst%s %%%%g1,[%%0+%%2]\n%s:", ld_suffix, &label3[1], st_suffix, &label5[1]); | |
1823 | output_asm_insn (pattern, xoperands); | |
1824 | } | |
1825 | ||
ab835497 | 1826 | return ""; |
ab835497 RK |
1827 | } |
1828 | \f | |
1829 | /* Output reasonable peephole for set-on-condition-code insns. | |
1830 | Note that these insns assume a particular way of defining | |
1831 | labels. Therefore, *both* sparc.h and this function must | |
1832 | be changed if a new syntax is needed. */ | |
1833 | ||
1834 | char * | |
1835 | output_scc_insn (operands, insn) | |
1836 | rtx operands[]; | |
1837 | rtx insn; | |
1838 | { | |
1839 | static char string[100]; | |
1840 | rtx label = 0, next = insn; | |
1841 | int need_label = 0; | |
1842 | ||
1843 | /* Try doing a jump optimization which jump.c can't do for us | |
1844 | because we did not expose that setcc works by using branches. | |
1845 | ||
1846 | If this scc insn is followed by an unconditional branch, then have | |
1847 | the jump insn emitted here jump to that location, instead of to | |
1848 | the end of the scc sequence as usual. */ | |
1849 | ||
1850 | do | |
1851 | { | |
1852 | if (GET_CODE (next) == CODE_LABEL) | |
1853 | label = next; | |
1854 | next = NEXT_INSN (next); | |
1855 | if (next == 0) | |
1856 | break; | |
1857 | } | |
1858 | while (GET_CODE (next) == NOTE || GET_CODE (next) == CODE_LABEL); | |
1859 | ||
1860 | /* If we are in a sequence, and the following insn is a sequence also, | |
1861 | then just following the current insn's next field will take us to the | |
1862 | first insn of the next sequence, which is the wrong place. We don't | |
1863 | want to optimize with a branch that has had its delay slot filled. | |
1864 | Avoid this by verifying that NEXT_INSN (PREV_INSN (next)) == next | |
1865 | which fails only if NEXT is such a branch. */ | |
1866 | ||
1867 | if (next && GET_CODE (next) == JUMP_INSN && simplejump_p (next) | |
1868 | && (! final_sequence || NEXT_INSN (PREV_INSN (next)) == next)) | |
1869 | label = JUMP_LABEL (next); | |
1870 | /* If not optimizing, jump label fields are not set. To be safe, always | |
1871 | check here to whether label is still zero. */ | |
1872 | if (label == 0) | |
1873 | { | |
1874 | label = gen_label_rtx (); | |
1875 | need_label = 1; | |
1876 | } | |
1877 | ||
1878 | LABEL_NUSES (label) += 1; | |
1879 | ||
1880 | operands[2] = label; | |
1881 | ||
1882 | /* If we are in a delay slot, assume it is the delay slot of an fpcc | |
1883 | insn since our type isn't allowed anywhere else. */ | |
1884 | ||
1885 | /* ??? Fpcc instructions no longer have delay slots, so this code is | |
1886 | probably obsolete. */ | |
1887 | ||
1888 | /* The fastest way to emit code for this is an annulled branch followed | |
1889 | by two move insns. This will take two cycles if the branch is taken, | |
1890 | and three cycles if the branch is not taken. | |
1891 | ||
1892 | However, if we are in the delay slot of another branch, this won't work, | |
1893 | because we can't put a branch in the delay slot of another branch. | |
1894 | The above sequence would effectively take 3 or 4 cycles respectively | |
1895 | since a no op would have be inserted between the two branches. | |
1896 | In this case, we want to emit a move, annulled branch, and then the | |
1897 | second move. This sequence always takes 3 cycles, and hence is faster | |
1898 | when we are in a branch delay slot. */ | |
1899 | ||
1900 | if (final_sequence) | |
1901 | { | |
1902 | strcpy (string, "mov 0,%0\n\t"); | |
1903 | strcat (string, output_cbranch (operands[1], 2, 0, 1, 0)); | |
1904 | strcat (string, "\n\tmov 1,%0"); | |
1905 | } | |
1906 | else | |
1907 | { | |
1908 | strcpy (string, output_cbranch (operands[1], 2, 0, 1, 0)); | |
1909 | strcat (string, "\n\tmov 1,%0\n\tmov 0,%0"); | |
1910 | } | |
1911 | ||
1912 | if (need_label) | |
1913 | strcat (string, "\n%l2:"); | |
1914 | ||
1915 | return string; | |
1916 | } | |
1917 | \f | |
1918 | /* Vectors to keep interesting information about registers where | |
1919 | it can easily be got. */ | |
1920 | ||
1921 | /* Modes for condition codes. */ | |
4d449554 JW |
1922 | #define C_MODES \ |
1923 | ((1 << (int) CCmode) | (1 << (int) CC_NOOVmode) \ | |
1924 | | (1 << (int) CCFPmode) | (1 << (int) CCFPEmode)) | |
ab835497 RK |
1925 | |
1926 | /* Modes for single-word (and smaller) quantities. */ | |
1927 | #define S_MODES \ | |
1928 | (~C_MODES \ | |
1929 | & ~ ((1 << (int) DImode) | (1 << (int) TImode) \ | |
1930 | | (1 << (int) DFmode) | (1 << (int) TFmode))) | |
1931 | ||
1932 | /* Modes for double-word (and smaller) quantities. */ | |
1933 | #define D_MODES \ | |
1934 | (~C_MODES \ | |
1935 | & ~ ((1 << (int) TImode) | (1 << (int) TFmode))) | |
1936 | ||
1937 | /* Modes for quad-word quantities. */ | |
1938 | #define T_MODES (~C_MODES) | |
1939 | ||
1e4eb8d1 JW |
1940 | /* Modes for single-float quantities. We must allow any single word or |
1941 | smaller quantity. This is because the fix/float conversion instructions | |
1942 | take integer inputs/outputs from the float registers. */ | |
1943 | #define SF_MODES (S_MODES) | |
ab835497 RK |
1944 | |
1945 | /* Modes for double-float quantities. */ | |
1946 | #define DF_MODES (SF_MODES | (1 << (int) DFmode) | (1 << (int) SCmode)) | |
1947 | ||
1948 | /* Modes for quad-float quantities. */ | |
1949 | #define TF_MODES (DF_MODES | (1 << (int) TFmode) | (1 << (int) DCmode)) | |
1950 | ||
1951 | /* Value is 1 if register/mode pair is acceptable on sparc. | |
1952 | The funny mixture of D and T modes is because integer operations | |
1953 | do not specially operate on tetra quantities, so non-quad-aligned | |
1954 | registers can hold quadword quantities (except %o4 and %i4 because | |
1955 | they cross fixed registers. */ | |
1956 | ||
1957 | int hard_regno_mode_ok[] = { | |
1958 | C_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, | |
1959 | T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES, | |
1960 | T_MODES, S_MODES, T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, | |
1961 | T_MODES, S_MODES, T_MODES, S_MODES, D_MODES, S_MODES, D_MODES, S_MODES, | |
1962 | ||
1963 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
1964 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
1965 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES, | |
1966 | TF_MODES, SF_MODES, DF_MODES, SF_MODES, TF_MODES, SF_MODES, DF_MODES, SF_MODES}; | |
1967 | \f | |
1968 | #ifdef __GNUC__ | |
1969 | inline | |
1970 | #endif | |
1971 | static int | |
1972 | save_regs (file, low, high, base, offset, n_fregs) | |
1973 | FILE *file; | |
1974 | int low, high; | |
1975 | char *base; | |
1976 | int offset; | |
1977 | int n_fregs; | |
1978 | { | |
1979 | int i; | |
1980 | ||
1981 | for (i = low; i < high; i += 2) | |
1982 | { | |
1983 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
1984 | if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
1985 | fprintf (file, "\tstd %s,[%s+%d]\n", | |
1986 | reg_names[i], base, offset + 4 * n_fregs), | |
1987 | n_fregs += 2; | |
1988 | else | |
1989 | fprintf (file, "\tst %s,[%s+%d]\n", | |
1990 | reg_names[i], base, offset + 4 * n_fregs), | |
1991 | n_fregs += 2; | |
1992 | else if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
1993 | fprintf (file, "\tst %s,[%s+%d]\n", | |
1994 | reg_names[i+1], base, offset + 4 * n_fregs), | |
1995 | n_fregs += 2; | |
1996 | } | |
1997 | return n_fregs; | |
1998 | } | |
1999 | ||
2000 | #ifdef __GNUC__ | |
2001 | inline | |
2002 | #endif | |
2003 | static int | |
2004 | restore_regs (file, low, high, base, offset, n_fregs) | |
2005 | FILE *file; | |
2006 | int low, high; | |
2007 | char *base; | |
2008 | int offset; | |
2009 | { | |
2010 | int i; | |
2011 | ||
2012 | for (i = low; i < high; i += 2) | |
2013 | { | |
2014 | if (regs_ever_live[i] && ! call_used_regs[i]) | |
2015 | if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
2016 | fprintf (file, "\tldd [%s+%d], %s\n", | |
2017 | base, offset + 4 * n_fregs, reg_names[i]), | |
2018 | n_fregs += 2; | |
2019 | else | |
2020 | fprintf (file, "\tld [%s+%d],%s\n", | |
2021 | base, offset + 4 * n_fregs, reg_names[i]), | |
2022 | n_fregs += 2; | |
2023 | else if (regs_ever_live[i+1] && ! call_used_regs[i+1]) | |
2024 | fprintf (file, "\tld [%s+%d],%s\n", | |
2025 | base, offset + 4 * n_fregs, reg_names[i+1]), | |
2026 | n_fregs += 2; | |
2027 | } | |
2028 | return n_fregs; | |
2029 | } | |
2030 | ||
2031 | /* Static variables we want to share between prologue and epilogue. */ | |
2032 | ||
2033 | /* Number of live floating point registers needed to be saved. */ | |
2034 | static int num_fregs; | |
2035 | ||
ab835497 RK |
2036 | int |
2037 | compute_frame_size (size, leaf_function) | |
2038 | int size; | |
2039 | int leaf_function; | |
2040 | { | |
2041 | int fregs_ever_live = 0; | |
2042 | int n_fregs = 0, i; | |
2043 | int outgoing_args_size = (current_function_outgoing_args_size | |
2044 | + REG_PARM_STACK_SPACE (current_function_decl)); | |
2045 | ||
2046 | apparent_fsize = ((size) + 7 - STARTING_FRAME_OFFSET) & -8; | |
2047 | for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2) | |
2048 | fregs_ever_live |= regs_ever_live[i]|regs_ever_live[i+1]; | |
2049 | ||
2050 | if (TARGET_EPILOGUE && fregs_ever_live) | |
2051 | { | |
2052 | for (i = 32; i < FIRST_PSEUDO_REGISTER; i += 2) | |
2053 | if ((regs_ever_live[i] && ! call_used_regs[i]) | |
2054 | || (regs_ever_live[i+1] && ! call_used_regs[i+1])) | |
2055 | n_fregs += 2; | |
2056 | } | |
2057 | ||
2058 | /* Set up values for use in `function_epilogue'. */ | |
2059 | num_fregs = n_fregs; | |
2060 | ||
2061 | apparent_fsize += (outgoing_args_size+7) & -8; | |
2062 | if (leaf_function && n_fregs == 0 | |
2063 | && apparent_fsize == (REG_PARM_STACK_SPACE (current_function_decl) | |
2064 | - STARTING_FRAME_OFFSET)) | |
2065 | apparent_fsize = 0; | |
2066 | ||
2067 | actual_fsize = apparent_fsize + n_fregs*4; | |
2068 | ||
2069 | /* Make sure nothing can clobber our register windows. | |
2070 | If a SAVE must be done, or there is a stack-local variable, | |
2071 | the register window area must be allocated. */ | |
2072 | if (leaf_function == 0 || size > 0) | |
2073 | actual_fsize += (16 * UNITS_PER_WORD)+8; | |
2074 | ||
2075 | return actual_fsize; | |
2076 | } | |
2077 | ||
915f619f JW |
2078 | /* Output code for the function prologue. */ |
2079 | ||
ab835497 RK |
2080 | void |
2081 | output_function_prologue (file, size, leaf_function) | |
2082 | FILE *file; | |
2083 | int size; | |
915f619f | 2084 | int leaf_function; |
ab835497 | 2085 | { |
a07c1915 JW |
2086 | /* ??? This should be %sp+actual_fsize for a leaf function. I think it |
2087 | works only because it is never used. */ | |
ab835497 RK |
2088 | if (leaf_function) |
2089 | frame_base_name = "%sp+80"; | |
2090 | else | |
2091 | frame_base_name = "%fp"; | |
2092 | ||
915f619f JW |
2093 | /* Need to use actual_fsize, since we are also allocating |
2094 | space for our callee (and our own register save area). */ | |
ab835497 RK |
2095 | actual_fsize = compute_frame_size (size, leaf_function); |
2096 | ||
2097 | fprintf (file, "\t!#PROLOGUE# 0\n"); | |
915f619f JW |
2098 | if (actual_fsize == 0) |
2099 | /* do nothing. */ ; | |
2100 | else if (actual_fsize <= 4096) | |
ab835497 RK |
2101 | { |
2102 | if (! leaf_function) | |
2103 | fprintf (file, "\tsave %%sp,-%d,%%sp\n", actual_fsize); | |
2104 | else | |
2105 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize); | |
2106 | } | |
915f619f | 2107 | else if (actual_fsize <= 8192) |
ab835497 | 2108 | { |
915f619f JW |
2109 | /* For frames in the range 4097..8192, we can use just two insns. */ |
2110 | if (! leaf_function) | |
2111 | { | |
2112 | fprintf (file, "\tsave %%sp,-4096,%%sp\n"); | |
2113 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096); | |
2114 | } | |
2115 | else | |
2116 | { | |
2117 | fprintf (file, "\tadd %%sp,-4096,%%sp\n"); | |
2118 | fprintf (file, "\tadd %%sp,-%d,%%sp\n", actual_fsize - 4096); | |
2119 | } | |
ab835497 RK |
2120 | } |
2121 | else | |
2122 | { | |
915f619f JW |
2123 | if (! leaf_function) |
2124 | { | |
2125 | fprintf (file, "\tsethi %%hi(-%d),%%g1\n", actual_fsize); | |
2126 | if ((actual_fsize & 0x3ff) != 0) | |
2127 | fprintf (file, "\tor %%g1,%%lo(-%d),%%g1\n", actual_fsize); | |
2128 | fprintf (file, "\tsave %%sp,%%g1,%%sp\n"); | |
2129 | } | |
2130 | else | |
2131 | { | |
2132 | fprintf (file, "\tsethi %%hi(-%d),%%g1\n", actual_fsize); | |
2133 | if ((actual_fsize & 0x3ff) != 0) | |
2134 | fprintf (file, "\tor %%g1,%%lo(-%d),%%g1\n", actual_fsize); | |
2135 | fprintf (file, "\tadd %%sp,%%g1,%%sp\n"); | |
2136 | } | |
ab835497 RK |
2137 | } |
2138 | ||
2139 | /* If doing anything with PIC, do it now. */ | |
2140 | if (! flag_pic) | |
2141 | fprintf (file, "\t!#PROLOGUE# 1\n"); | |
2142 | ||
2143 | /* Figure out where to save any special registers. */ | |
2144 | if (num_fregs) | |
2145 | { | |
2146 | int offset, n_fregs = num_fregs; | |
2147 | ||
a07c1915 | 2148 | /* ??? This should always be -apparent_fsize. */ |
ab835497 RK |
2149 | if (! leaf_function) |
2150 | offset = -apparent_fsize; | |
2151 | else | |
2152 | offset = 0; | |
2153 | ||
2154 | if (TARGET_EPILOGUE && ! leaf_function) | |
2155 | n_fregs = save_regs (file, 0, 16, frame_base_name, offset, 0); | |
2156 | else if (leaf_function) | |
2157 | n_fregs = save_regs (file, 0, 32, frame_base_name, offset, 0); | |
2158 | if (TARGET_EPILOGUE) | |
2159 | save_regs (file, 32, FIRST_PSEUDO_REGISTER, | |
2160 | frame_base_name, offset, n_fregs); | |
2161 | } | |
2162 | ||
ab835497 RK |
2163 | leaf_label = 0; |
2164 | if (leaf_function && actual_fsize != 0) | |
2165 | { | |
2166 | /* warning ("leaf procedure with frame size %d", actual_fsize); */ | |
2167 | if (! TARGET_EPILOGUE) | |
2168 | leaf_label = gen_label_rtx (); | |
2169 | } | |
2170 | } | |
2171 | ||
915f619f JW |
2172 | /* Output code for the function epilogue. */ |
2173 | ||
ab835497 | 2174 | void |
ef8200df | 2175 | output_function_epilogue (file, size, leaf_function) |
ab835497 RK |
2176 | FILE *file; |
2177 | int size; | |
ef8200df | 2178 | int leaf_function; |
ab835497 | 2179 | { |
ab835497 RK |
2180 | char *ret; |
2181 | ||
2182 | if (leaf_label) | |
2183 | { | |
ab835497 RK |
2184 | emit_label_after (leaf_label, get_last_insn ()); |
2185 | final_scan_insn (get_last_insn (), file, 0, 0, 1); | |
2186 | } | |
2187 | ||
2188 | if (num_fregs) | |
2189 | { | |
2190 | int offset, n_fregs = num_fregs; | |
2191 | ||
a07c1915 | 2192 | /* ??? This should always be -apparent_fsize. */ |
ab835497 RK |
2193 | if (! leaf_function) |
2194 | offset = -apparent_fsize; | |
2195 | else | |
2196 | offset = 0; | |
2197 | ||
2198 | if (TARGET_EPILOGUE && ! leaf_function) | |
2199 | n_fregs = restore_regs (file, 0, 16, frame_base_name, offset, 0); | |
2200 | else if (leaf_function) | |
2201 | n_fregs = restore_regs (file, 0, 32, frame_base_name, offset, 0); | |
2202 | if (TARGET_EPILOGUE) | |
2203 | restore_regs (file, 32, FIRST_PSEUDO_REGISTER, | |
2204 | frame_base_name, offset, n_fregs); | |
2205 | } | |
2206 | ||
2207 | /* Work out how to skip the caller's unimp instruction if required. */ | |
2208 | if (leaf_function) | |
2209 | ret = (current_function_returns_struct ? "jmp %o7+12" : "retl"); | |
2210 | else | |
2211 | ret = (current_function_returns_struct ? "jmp %i7+12" : "ret"); | |
2212 | ||
ef8200df | 2213 | if (TARGET_EPILOGUE || leaf_label) |
ab835497 | 2214 | { |
ef8200df JW |
2215 | int old_target_epilogue = TARGET_EPILOGUE; |
2216 | target_flags &= ~old_target_epilogue; | |
ab835497 | 2217 | |
ef8200df JW |
2218 | if (! leaf_function) |
2219 | { | |
2220 | /* If we wound up with things in our delay slot, flush them here. */ | |
2221 | if (current_function_epilogue_delay_list) | |
ab835497 | 2222 | { |
ef8200df JW |
2223 | rtx insn = emit_jump_insn_after (gen_rtx (RETURN, VOIDmode), |
2224 | get_last_insn ()); | |
2225 | PATTERN (insn) = gen_rtx (PARALLEL, VOIDmode, | |
2226 | gen_rtvec (2, | |
2227 | PATTERN (XEXP (current_function_epilogue_delay_list, 0)), | |
2228 | PATTERN (insn))); | |
2229 | final_scan_insn (insn, file, 1, 0, 1); | |
ab835497 RK |
2230 | } |
2231 | else | |
ef8200df JW |
2232 | fprintf (file, "\t%s\n\trestore\n", ret); |
2233 | } | |
915f619f JW |
2234 | /* All of the following cases are for leaf functions. */ |
2235 | else if (current_function_epilogue_delay_list) | |
ef8200df | 2236 | { |
915f619f JW |
2237 | /* eligible_for_epilogue_delay_slot ensures that if this is a |
2238 | leaf function, then we will only have insn in the delay slot | |
2239 | if the frame size is zero, thus no adjust for the stack is | |
2240 | needed here. */ | |
2241 | if (actual_fsize != 0) | |
ef8200df | 2242 | abort (); |
915f619f JW |
2243 | fprintf (file, "\t%s\n", ret); |
2244 | final_scan_insn (XEXP (current_function_epilogue_delay_list, 0), | |
2245 | file, 1, 0, 1); | |
ab835497 | 2246 | } |
915f619f JW |
2247 | else if (actual_fsize <= 4096) |
2248 | fprintf (file, "\t%s\n\tsub %%sp,-%d,%%sp\n", ret, actual_fsize); | |
2249 | else if (actual_fsize <= 8192) | |
2250 | fprintf (file, "\tsub %%sp,-4096,%%sp\n\t%s\n\tsub %%sp,-%d,%%sp\n", | |
2251 | ret, actual_fsize - 4096); | |
2252 | else if ((actual_fsize & 0x3ff) == 0) | |
2253 | fprintf (file, "\tsethi %%hi(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n", | |
2254 | actual_fsize, ret); | |
2255 | else | |
2256 | fprintf (file, "\tsethi %%hi(%d),%%g1\n\tor %%g1,%%lo(%d),%%g1\n\t%s\n\tadd %%sp,%%g1,%%sp\n", | |
2257 | actual_fsize, actual_fsize, ret); | |
ef8200df | 2258 | target_flags |= old_target_epilogue; |
ab835497 RK |
2259 | } |
2260 | } | |
3ea1fdd3 JW |
2261 | |
2262 | /* Do what is necessary for `va_start'. The argument is ignored; | |
2263 | We look at the current function to determine if stdarg or varargs | |
2264 | is used and return the address of the first unnamed parameter. */ | |
2265 | ||
2266 | rtx | |
2267 | sparc_builtin_saveregs (arglist) | |
2268 | tree arglist; | |
2269 | { | |
2270 | tree fntype = TREE_TYPE (current_function_decl); | |
2271 | int stdarg = (TYPE_ARG_TYPES (fntype) != 0 | |
2272 | && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype))) | |
2273 | != void_type_node)); | |
2274 | int first_reg = current_function_args_info; | |
2275 | rtx address; | |
2276 | int regno; | |
2277 | ||
2278 | if (! stdarg) | |
2279 | first_reg = 0; | |
2280 | ||
2281 | for (regno = first_reg; regno < NPARM_REGS; regno++) | |
2282 | emit_move_insn (gen_rtx (MEM, word_mode, | |
2283 | gen_rtx (PLUS, Pmode, | |
2284 | frame_pointer_rtx, | |
2285 | GEN_INT (STACK_POINTER_OFFSET | |
2286 | + UNITS_PER_WORD * regno))), | |
2287 | gen_rtx (REG, word_mode, BASE_INCOMING_ARG_REG (word_mode) | |
2288 | + regno)); | |
2289 | ||
2290 | address = gen_rtx (PLUS, Pmode, | |
2291 | frame_pointer_rtx, | |
2292 | GEN_INT (STACK_POINTER_OFFSET | |
2293 | + UNITS_PER_WORD * first_reg)); | |
2294 | ||
2295 | return address; | |
2296 | } | |
ab835497 RK |
2297 | \f |
2298 | /* Return the string to output a conditional branch to LABEL, which is | |
2299 | the operand number of the label. OP is the conditional expression. The | |
2300 | mode of register 0 says what kind of comparison we made. | |
2301 | ||
2302 | REVERSED is non-zero if we should reverse the sense of the comparison. | |
2303 | ||
2304 | ANNUL is non-zero if we should generate an annulling branch. | |
2305 | ||
2306 | NOOP is non-zero if we have to follow this branch by a noop. */ | |
2307 | ||
2308 | char * | |
2309 | output_cbranch (op, label, reversed, annul, noop) | |
2310 | rtx op; | |
2311 | int label; | |
2312 | int reversed, annul, noop; | |
2313 | { | |
2314 | static char string[20]; | |
2315 | enum rtx_code code = GET_CODE (op); | |
2316 | enum machine_mode mode = GET_MODE (XEXP (op, 0)); | |
2317 | static char labelno[] = " %lX"; | |
2318 | ||
b4ac57ab | 2319 | /* ??? FP branches can not be preceded by another floating point insn. |
ab835497 RK |
2320 | Because there is currently no concept of pre-delay slots, we can fix |
2321 | this only by always emitting a nop before a floating point branch. */ | |
2322 | ||
4d449554 | 2323 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2324 | strcpy (string, "nop\n\t"); |
2325 | ||
2326 | /* If not floating-point or if EQ or NE, we can just reverse the code. */ | |
4d449554 JW |
2327 | if (reversed |
2328 | && ((mode != CCFPmode && mode != CCFPEmode) || code == EQ || code == NE)) | |
ab835497 RK |
2329 | code = reverse_condition (code), reversed = 0; |
2330 | ||
2331 | /* Start by writing the branch condition. */ | |
2332 | switch (code) | |
2333 | { | |
2334 | case NE: | |
4d449554 | 2335 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2336 | strcat (string, "fbne"); |
2337 | else | |
2338 | strcpy (string, "bne"); | |
2339 | break; | |
2340 | ||
2341 | case EQ: | |
4d449554 | 2342 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2343 | strcat (string, "fbe"); |
2344 | else | |
2345 | strcpy (string, "be"); | |
2346 | break; | |
2347 | ||
2348 | case GE: | |
4d449554 | 2349 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2350 | { |
2351 | if (reversed) | |
2352 | strcat (string, "fbul"); | |
2353 | else | |
2354 | strcat (string, "fbge"); | |
2355 | } | |
2356 | else if (mode == CC_NOOVmode) | |
2357 | strcpy (string, "bpos"); | |
2358 | else | |
2359 | strcpy (string, "bge"); | |
2360 | break; | |
2361 | ||
2362 | case GT: | |
4d449554 | 2363 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2364 | { |
2365 | if (reversed) | |
2366 | strcat (string, "fbule"); | |
2367 | else | |
2368 | strcat (string, "fbg"); | |
2369 | } | |
2370 | else | |
2371 | strcpy (string, "bg"); | |
2372 | break; | |
2373 | ||
2374 | case LE: | |
4d449554 | 2375 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2376 | { |
2377 | if (reversed) | |
2378 | strcat (string, "fbug"); | |
2379 | else | |
2380 | strcat (string, "fble"); | |
2381 | } | |
2382 | else | |
2383 | strcpy (string, "ble"); | |
2384 | break; | |
2385 | ||
2386 | case LT: | |
4d449554 | 2387 | if (mode == CCFPmode || mode == CCFPEmode) |
ab835497 RK |
2388 | { |
2389 | if (reversed) | |
2390 | strcat (string, "fbuge"); | |
2391 | else | |
2392 | strcat (string, "fbl"); | |
2393 | } | |
2394 | else if (mode == CC_NOOVmode) | |
2395 | strcpy (string, "bneg"); | |
2396 | else | |
2397 | strcpy (string, "bl"); | |
2398 | break; | |
2399 | ||
2400 | case GEU: | |
2401 | strcpy (string, "bgeu"); | |
2402 | break; | |
2403 | ||
2404 | case GTU: | |
2405 | strcpy (string, "bgu"); | |
2406 | break; | |
2407 | ||
2408 | case LEU: | |
2409 | strcpy (string, "bleu"); | |
2410 | break; | |
2411 | ||
2412 | case LTU: | |
2413 | strcpy (string, "blu"); | |
2414 | break; | |
2415 | } | |
2416 | ||
2417 | /* Now add the annulling, the label, and a possible noop. */ | |
2418 | if (annul) | |
2419 | strcat (string, ",a"); | |
2420 | ||
2421 | labelno[3] = label + '0'; | |
2422 | strcat (string, labelno); | |
2423 | ||
2424 | if (noop) | |
2425 | strcat (string, "\n\tnop"); | |
2426 | ||
2427 | return string; | |
2428 | } | |
2429 | ||
795068a4 JW |
2430 | /* Output assembler code to return from a function. */ |
2431 | ||
ab835497 RK |
2432 | char * |
2433 | output_return (operands) | |
2434 | rtx *operands; | |
2435 | { | |
2436 | if (leaf_label) | |
2437 | { | |
2438 | operands[0] = leaf_label; | |
2439 | return "b,a %l0"; | |
2440 | } | |
2441 | else if (leaf_function) | |
2442 | { | |
915f619f JW |
2443 | /* If we didn't allocate a frame pointer for the current function, |
2444 | the stack pointer might have been adjusted. Output code to | |
2445 | restore it now. */ | |
2446 | ||
ab835497 | 2447 | operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize); |
915f619f JW |
2448 | |
2449 | /* Use sub of negated value in first two cases instead of add to | |
2450 | allow actual_fsize == 4096. */ | |
2451 | ||
2452 | if (actual_fsize <= 4096) | |
ab835497 RK |
2453 | { |
2454 | if (current_function_returns_struct) | |
915f619f | 2455 | return "jmp %%o7+12\n\tsub %%sp,-%0,%%sp"; |
ab835497 | 2456 | else |
915f619f | 2457 | return "retl\n\tsub %%sp,-%0,%%sp"; |
ab835497 | 2458 | } |
915f619f | 2459 | else if (actual_fsize <= 8192) |
ab835497 | 2460 | { |
915f619f | 2461 | operands[0] = gen_rtx (CONST_INT, VOIDmode, actual_fsize - 4096); |
ab835497 | 2462 | if (current_function_returns_struct) |
915f619f JW |
2463 | return "sub %%sp,-4096,%%sp\n\tjmp %%o7+12\n\tsub %%sp,-%0,%%sp"; |
2464 | else | |
2465 | return "sub %%sp,-4096,%%sp\n\tretl\n\tsub %%sp,-%0,%%sp"; | |
2466 | } | |
2467 | else if (current_function_returns_struct) | |
2468 | { | |
2469 | if ((actual_fsize & 0x3ff) != 0) | |
ab835497 RK |
2470 | return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp"; |
2471 | else | |
915f619f JW |
2472 | return "sethi %%hi(%a0),%%g1\n\tjmp %%o7+12\n\tadd %%sp,%%g1,%%sp"; |
2473 | } | |
2474 | else | |
2475 | { | |
2476 | if ((actual_fsize & 0x3ff) != 0) | |
ab835497 | 2477 | return "sethi %%hi(%a0),%%g1\n\tor %%g1,%%lo(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp"; |
915f619f JW |
2478 | else |
2479 | return "sethi %%hi(%a0),%%g1\n\tretl\n\tadd %%sp,%%g1,%%sp"; | |
ab835497 RK |
2480 | } |
2481 | } | |
2482 | else | |
2483 | { | |
2484 | if (current_function_returns_struct) | |
2485 | return "jmp %%i7+12\n\trestore"; | |
2486 | else | |
2487 | return "ret\n\trestore"; | |
2488 | } | |
2489 | } | |
ab835497 RK |
2490 | \f |
2491 | /* Leaf functions and non-leaf functions have different needs. */ | |
2492 | ||
2493 | static int | |
2494 | reg_leaf_alloc_order[] = REG_LEAF_ALLOC_ORDER; | |
2495 | ||
2496 | static int | |
2497 | reg_nonleaf_alloc_order[] = REG_ALLOC_ORDER; | |
2498 | ||
2499 | static int *reg_alloc_orders[] = { | |
2500 | reg_leaf_alloc_order, | |
2501 | reg_nonleaf_alloc_order}; | |
2502 | ||
2503 | void | |
2504 | order_regs_for_local_alloc () | |
2505 | { | |
2506 | static int last_order_nonleaf = 1; | |
2507 | ||
2508 | if (regs_ever_live[15] != last_order_nonleaf) | |
2509 | { | |
2510 | last_order_nonleaf = !last_order_nonleaf; | |
2511 | bcopy (reg_alloc_orders[last_order_nonleaf], reg_alloc_order, | |
2512 | FIRST_PSEUDO_REGISTER * sizeof (int)); | |
2513 | } | |
2514 | } | |
2515 | \f | |
35016322 JW |
2516 | /* Return 1 if REGNO (reg1) is even and REGNO (reg1) == REGNO (reg2) - 1. |
2517 | This makes them candidates for using ldd and std insns. | |
2518 | ||
2519 | Note reg1 and reg2 *must* be hard registers. To be sure we will | |
2520 | abort if we are passed pseudo registers. */ | |
2521 | ||
2522 | int | |
7c56249d | 2523 | registers_ok_for_ldd_peep (reg1, reg2) |
35016322 JW |
2524 | rtx reg1, reg2; |
2525 | { | |
2526 | ||
2527 | /* We might have been passed a SUBREG. */ | |
2528 | if (GET_CODE (reg1) != REG || GET_CODE (reg2) != REG) | |
2529 | return 0; | |
2530 | ||
35016322 JW |
2531 | if (REGNO (reg1) % 2 != 0) |
2532 | return 0; | |
2533 | ||
2534 | return (REGNO (reg1) == REGNO (reg2) - 1); | |
2535 | ||
2536 | } | |
2537 | ||
2538 | /* Return 1 if addr1 and addr2 are suitable for use in an ldd or | |
2539 | std insn. | |
2540 | ||
2541 | This can only happen when addr1 and addr2 are consecutive memory | |
2542 | locations (addr1 + 4 == addr2). addr1 must also be aligned on a | |
2543 | 64 bit boundary (addr1 % 8 == 0). | |
2544 | ||
2545 | We know %sp and %fp are kept aligned on a 64 bit boundary. Other | |
2546 | registers are assumed to *never* be properly aligned and are | |
2547 | rejected. | |
2548 | ||
2549 | Knowing %sp and %fp are kept aligned on a 64 bit boundary, we | |
2550 | need only check that the offset for addr1 % 8 == 0. */ | |
2551 | ||
2552 | int | |
7c56249d | 2553 | addrs_ok_for_ldd_peep (addr1, addr2) |
35016322 JW |
2554 | rtx addr1, addr2; |
2555 | { | |
2556 | int reg1, offset1; | |
2557 | ||
2558 | /* Extract a register number and offset (if used) from the first addr. */ | |
2559 | if (GET_CODE (addr1) == PLUS) | |
2560 | { | |
2561 | /* If not a REG, return zero. */ | |
2562 | if (GET_CODE (XEXP (addr1, 0)) != REG) | |
2563 | return 0; | |
2564 | else | |
2565 | { | |
2566 | reg1 = REGNO (XEXP (addr1, 0)); | |
2567 | /* The offset must be constant! */ | |
2568 | if (GET_CODE (XEXP (addr1, 1)) != CONST_INT) | |
2569 | return 0; | |
2570 | offset1 = INTVAL (XEXP (addr1, 1)); | |
2571 | } | |
2572 | } | |
2573 | else if (GET_CODE (addr1) != REG) | |
2574 | return 0; | |
2575 | else | |
2576 | { | |
2577 | reg1 = REGNO (addr1); | |
2578 | /* This was a simple (mem (reg)) expression. Offset is 0. */ | |
2579 | offset1 = 0; | |
2580 | } | |
2581 | ||
2582 | /* Make sure the second address is a (mem (plus (reg) (const_int). */ | |
2583 | if (GET_CODE (addr2) != PLUS) | |
2584 | return 0; | |
2585 | ||
2586 | if (GET_CODE (XEXP (addr2, 0)) != REG | |
2587 | || GET_CODE (XEXP (addr2, 1)) != CONST_INT) | |
2588 | return 0; | |
2589 | ||
2590 | /* Only %fp and %sp are allowed. Additionally both addresses must | |
2591 | use the same register. */ | |
2592 | if (reg1 != FRAME_POINTER_REGNUM && reg1 != STACK_POINTER_REGNUM) | |
2593 | return 0; | |
2594 | ||
2595 | if (reg1 != REGNO (XEXP (addr2, 0))) | |
2596 | return 0; | |
2597 | ||
2296cba3 | 2598 | /* The first offset must be evenly divisible by 8 to ensure the |
35016322 JW |
2599 | address is 64 bit aligned. */ |
2600 | if (offset1 % 8 != 0) | |
2601 | return 0; | |
2602 | ||
2603 | /* The offset for the second addr must be 4 more than the first addr. */ | |
2604 | if (INTVAL (XEXP (addr2, 1)) != offset1 + 4) | |
2605 | return 0; | |
2606 | ||
2607 | /* All the tests passed. addr1 and addr2 are valid for ldd and std | |
2608 | instructions. */ | |
2609 | return 1; | |
2610 | } | |
7c56249d JL |
2611 | |
2612 | /* Return 1 if reg is a pseudo, or is the first register in | |
2613 | a hard register pair. This makes it a candidate for use in | |
2614 | ldd and std insns. */ | |
2615 | ||
2616 | int | |
2617 | register_ok_for_ldd (reg) | |
2618 | rtx reg; | |
2619 | { | |
2620 | ||
2621 | /* We might have been passed a SUBREG. */ | |
2622 | if (GET_CODE (reg) != REG) | |
2623 | return 0; | |
2624 | ||
2625 | if (REGNO (reg) < FIRST_PSEUDO_REGISTER) | |
2626 | return (REGNO (reg) % 2 == 0); | |
2627 | else | |
2628 | return 1; | |
2629 | ||
2630 | } | |
ab835497 | 2631 | \f |
ab835497 RK |
2632 | /* Print operand X (an rtx) in assembler syntax to file FILE. |
2633 | CODE is a letter or dot (`z' in `%z0') or 0 if no letter was specified. | |
2634 | For `%' followed by punctuation, CODE is the punctuation and X is null. */ | |
2635 | ||
2636 | void | |
2637 | print_operand (file, x, code) | |
2638 | FILE *file; | |
2639 | rtx x; | |
2640 | int code; | |
2641 | { | |
2642 | switch (code) | |
2643 | { | |
2644 | case '#': | |
2645 | /* Output a 'nop' if there's nothing for the delay slot. */ | |
2646 | if (dbr_sequence_length () == 0) | |
2647 | fputs ("\n\tnop", file); | |
2648 | return; | |
2649 | case '*': | |
c6ce0969 JW |
2650 | /* Output an annul flag if there's nothing for the delay slot and we |
2651 | are optimizing. This is always used with '(' below. */ | |
2652 | /* Sun OS 4.1.1 dbx can't handle an annulled unconditional branch; | |
2653 | this is a dbx bug. So, we only do this when optimizing. */ | |
2654 | if (dbr_sequence_length () == 0 && optimize) | |
2655 | fputs (",a", file); | |
2656 | return; | |
2657 | case '(': | |
2658 | /* Output a 'nop' if there's nothing for the delay slot and we are | |
2659 | not optimizing. This is always used with '*' above. */ | |
2660 | if (dbr_sequence_length () == 0 && ! optimize) | |
2661 | fputs ("\n\tnop", file); | |
ab835497 RK |
2662 | return; |
2663 | case 'Y': | |
2664 | /* Adjust the operand to take into account a RESTORE operation. */ | |
2665 | if (GET_CODE (x) != REG) | |
b3b1e8bd JW |
2666 | output_operand_lossage ("Invalid %%Y operand"); |
2667 | else if (REGNO (x) < 8) | |
ab835497 RK |
2668 | fputs (reg_names[REGNO (x)], file); |
2669 | else if (REGNO (x) >= 24 && REGNO (x) < 32) | |
2670 | fputs (reg_names[REGNO (x)-16], file); | |
2671 | else | |
b3b1e8bd | 2672 | output_operand_lossage ("Invalid %%Y operand"); |
ab835497 | 2673 | return; |
ab835497 | 2674 | case 'R': |
795068a4 | 2675 | /* Print out the second register name of a register pair or quad. |
ab835497 RK |
2676 | I.e., R (%o0) => %o1. */ |
2677 | fputs (reg_names[REGNO (x)+1], file); | |
2678 | return; | |
795068a4 JW |
2679 | case 'S': |
2680 | /* Print out the third register name of a register quad. | |
2681 | I.e., S (%o0) => %o2. */ | |
2682 | fputs (reg_names[REGNO (x)+2], file); | |
2683 | return; | |
2684 | case 'T': | |
2685 | /* Print out the fourth register name of a register quad. | |
2686 | I.e., T (%o0) => %o3. */ | |
2687 | fputs (reg_names[REGNO (x)+3], file); | |
2688 | return; | |
ab835497 RK |
2689 | case 'm': |
2690 | /* Print the operand's address only. */ | |
2691 | output_address (XEXP (x, 0)); | |
2692 | return; | |
2693 | case 'r': | |
2694 | /* In this case we need a register. Use %g0 if the | |
77a02b01 | 2695 | operand is const0_rtx. */ |
76052e74 RS |
2696 | if (x == const0_rtx |
2697 | || (GET_MODE (x) != VOIDmode && x == CONST0_RTX (GET_MODE (x)))) | |
ab835497 RK |
2698 | { |
2699 | fputs ("%g0", file); | |
2700 | return; | |
2701 | } | |
2702 | else | |
2703 | break; | |
2704 | ||
2705 | case 'A': | |
2706 | switch (GET_CODE (x)) | |
2707 | { | |
2708 | case IOR: fputs ("or", file); break; | |
2709 | case AND: fputs ("and", file); break; | |
2710 | case XOR: fputs ("xor", file); break; | |
b3b1e8bd | 2711 | default: output_operand_lossage ("Invalid %%A operand"); |
ab835497 RK |
2712 | } |
2713 | return; | |
2714 | ||
2715 | case 'B': | |
2716 | switch (GET_CODE (x)) | |
2717 | { | |
2718 | case IOR: fputs ("orn", file); break; | |
2719 | case AND: fputs ("andn", file); break; | |
2720 | case XOR: fputs ("xnor", file); break; | |
b3b1e8bd | 2721 | default: output_operand_lossage ("Invalid %%B operand"); |
ab835497 RK |
2722 | } |
2723 | return; | |
2724 | ||
2725 | case 'b': | |
2726 | { | |
2727 | /* Print a sign-extended character. */ | |
2728 | int i = INTVAL (x) & 0xff; | |
2729 | if (i & 0x80) | |
2730 | i |= 0xffffff00; | |
2731 | fprintf (file, "%d", i); | |
2732 | return; | |
2733 | } | |
2734 | ||
2735 | case 0: | |
2736 | /* Do nothing special. */ | |
2737 | break; | |
2738 | ||
2739 | default: | |
2740 | /* Undocumented flag. */ | |
415f583e | 2741 | output_operand_lossage ("invalid operand output code"); |
ab835497 RK |
2742 | } |
2743 | ||
2744 | if (GET_CODE (x) == REG) | |
2745 | fputs (reg_names[REGNO (x)], file); | |
2746 | else if (GET_CODE (x) == MEM) | |
2747 | { | |
2748 | fputc ('[', file); | |
2749 | if (CONSTANT_P (XEXP (x, 0))) | |
2750 | /* Poor Sun assembler doesn't understand absolute addressing. */ | |
2751 | fputs ("%g0+", file); | |
2752 | output_address (XEXP (x, 0)); | |
2753 | fputc (']', file); | |
2754 | } | |
2755 | else if (GET_CODE (x) == HIGH) | |
2756 | { | |
2757 | fputs ("%hi(", file); | |
2758 | output_addr_const (file, XEXP (x, 0)); | |
2759 | fputc (')', file); | |
2760 | } | |
2761 | else if (GET_CODE (x) == LO_SUM) | |
2762 | { | |
2763 | print_operand (file, XEXP (x, 0), 0); | |
2764 | fputs ("+%lo(", file); | |
2765 | output_addr_const (file, XEXP (x, 1)); | |
2766 | fputc (')', file); | |
2767 | } | |
e601abce JW |
2768 | else if (GET_CODE (x) == CONST_DOUBLE |
2769 | && (GET_MODE (x) == VOIDmode | |
2770 | || GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)) | |
ab835497 RK |
2771 | { |
2772 | if (CONST_DOUBLE_HIGH (x) == 0) | |
2773 | fprintf (file, "%u", CONST_DOUBLE_LOW (x)); | |
2774 | else if (CONST_DOUBLE_HIGH (x) == -1 | |
2775 | && CONST_DOUBLE_LOW (x) < 0) | |
2776 | fprintf (file, "%d", CONST_DOUBLE_LOW (x)); | |
2777 | else | |
e601abce | 2778 | output_operand_lossage ("long long constant not a valid immediate operand"); |
ab835497 | 2779 | } |
e601abce JW |
2780 | else if (GET_CODE (x) == CONST_DOUBLE) |
2781 | output_operand_lossage ("floating point constant not a valid immediate operand"); | |
ab835497 RK |
2782 | else { output_addr_const (file, x); } |
2783 | } | |
2784 | \f | |
2785 | /* This function outputs assembler code for VALUE to FILE, where VALUE is | |
2786 | a 64 bit (DImode) value. */ | |
2787 | ||
2788 | /* ??? If there is a 64 bit counterpart to .word that the assembler | |
2789 | understands, then using that would simply this code greatly. */ | |
2790 | ||
2791 | void | |
2792 | output_double_int (file, value) | |
2793 | FILE *file; | |
2794 | rtx value; | |
2795 | { | |
2796 | if (GET_CODE (value) == CONST_INT) | |
2797 | { | |
2798 | if (INTVAL (value) < 0) | |
2799 | ASM_OUTPUT_INT (file, constm1_rtx); | |
2800 | else | |
2801 | ASM_OUTPUT_INT (file, const0_rtx); | |
2802 | ASM_OUTPUT_INT (file, value); | |
2803 | } | |
2804 | else if (GET_CODE (value) == CONST_DOUBLE) | |
2805 | { | |
2806 | ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode, | |
2807 | CONST_DOUBLE_HIGH (value))); | |
2808 | ASM_OUTPUT_INT (file, gen_rtx (CONST_INT, VOIDmode, | |
2809 | CONST_DOUBLE_LOW (value))); | |
2810 | } | |
2811 | else if (GET_CODE (value) == SYMBOL_REF | |
2812 | || GET_CODE (value) == CONST | |
2813 | || GET_CODE (value) == PLUS) | |
2814 | { | |
2815 | /* Addresses are only 32 bits. */ | |
2816 | ASM_OUTPUT_INT (file, const0_rtx); | |
2817 | ASM_OUTPUT_INT (file, value); | |
2818 | } | |
2819 | else | |
2820 | abort (); | |
2821 | } | |
210aa14a | 2822 | \f |
77a02b01 JW |
2823 | #ifndef CHAR_TYPE_SIZE |
2824 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
2825 | #endif | |
2826 | ||
2827 | #ifndef SHORT_TYPE_SIZE | |
2828 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) | |
2829 | #endif | |
2830 | ||
2831 | #ifndef INT_TYPE_SIZE | |
2832 | #define INT_TYPE_SIZE BITS_PER_WORD | |
2833 | #endif | |
2834 | ||
2835 | #ifndef LONG_TYPE_SIZE | |
2836 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
2837 | #endif | |
2838 | ||
2839 | #ifndef LONG_LONG_TYPE_SIZE | |
2840 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
2841 | #endif | |
2842 | ||
2843 | #ifndef FLOAT_TYPE_SIZE | |
2844 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
2845 | #endif | |
2846 | ||
2847 | #ifndef DOUBLE_TYPE_SIZE | |
2848 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
2849 | #endif | |
2850 | ||
2851 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
2852 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
2853 | #endif | |
210aa14a RS |
2854 | |
2855 | unsigned long | |
2856 | sparc_type_code (type) | |
2857 | register tree type; | |
2858 | { | |
2859 | register unsigned long qualifiers = 0; | |
2860 | register unsigned shift = 6; | |
2861 | ||
2862 | for (;;) | |
2863 | { | |
2864 | switch (TREE_CODE (type)) | |
2865 | { | |
2866 | case ERROR_MARK: | |
2867 | return qualifiers; | |
2868 | ||
2869 | case ARRAY_TYPE: | |
2870 | qualifiers |= (3 << shift); | |
2871 | shift += 2; | |
2872 | type = TREE_TYPE (type); | |
2873 | break; | |
2874 | ||
2875 | case FUNCTION_TYPE: | |
2876 | case METHOD_TYPE: | |
2877 | qualifiers |= (2 << shift); | |
2878 | shift += 2; | |
2879 | type = TREE_TYPE (type); | |
2880 | break; | |
2881 | ||
2882 | case POINTER_TYPE: | |
2883 | case REFERENCE_TYPE: | |
2884 | case OFFSET_TYPE: | |
2885 | qualifiers |= (1 << shift); | |
2886 | shift += 2; | |
2887 | type = TREE_TYPE (type); | |
2888 | break; | |
ab835497 | 2889 | |
210aa14a RS |
2890 | case RECORD_TYPE: |
2891 | return (qualifiers | 8); | |
2892 | ||
2893 | case UNION_TYPE: | |
2894 | return (qualifiers | 9); | |
2895 | ||
2896 | case ENUMERAL_TYPE: | |
2897 | return (qualifiers | 10); | |
2898 | ||
2899 | case VOID_TYPE: | |
2900 | return (qualifiers | 16); | |
2901 | ||
2902 | case INTEGER_TYPE: | |
77a02b01 JW |
2903 | /* Carefully distinguish all the standard types of C, |
2904 | without messing up if the language is not C. | |
2905 | Note that we check only for the names that contain spaces; | |
2906 | other names might occur by coincidence in other languages. */ | |
2907 | if (TYPE_NAME (type) != 0 | |
2908 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
2909 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
2910 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
2911 | { | |
2912 | char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); | |
2913 | ||
2914 | if (!strcmp (name, "unsigned char")) | |
2915 | return (qualifiers | 12); | |
2916 | if (!strcmp (name, "signed char")) | |
2917 | return (qualifiers | 2); | |
2918 | if (!strcmp (name, "unsigned int")) | |
2919 | return (qualifiers | 14); | |
2920 | if (!strcmp (name, "short int")) | |
2921 | return (qualifiers | 3); | |
2922 | if (!strcmp (name, "short unsigned int")) | |
2923 | return (qualifiers | 13); | |
2924 | if (!strcmp (name, "long int")) | |
2925 | return (qualifiers | 5); | |
2926 | if (!strcmp (name, "long unsigned int")) | |
2927 | return (qualifiers | 15); | |
2928 | if (!strcmp (name, "long long int")) | |
2929 | return (qualifiers | 5); /* Who knows? */ | |
2930 | if (!strcmp (name, "long long unsigned int")) | |
2931 | return (qualifiers | 15); /* Who knows? */ | |
2932 | } | |
2933 | ||
2934 | /* Most integer types will be sorted out above, however, for the | |
2935 | sake of special `array index' integer types, the following code | |
2936 | is also provided. */ | |
2937 | ||
2938 | if (TYPE_PRECISION (type) == INT_TYPE_SIZE) | |
2939 | return (qualifiers | (TREE_UNSIGNED (type) ? 14 : 4)); | |
2940 | ||
2941 | if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) | |
2942 | return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5)); | |
2943 | ||
2944 | if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) | |
2945 | return (qualifiers | (TREE_UNSIGNED (type) ? 15 : 5)); | |
2946 | ||
2947 | if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) | |
2948 | return (qualifiers | (TREE_UNSIGNED (type) ? 13 : 3)); | |
2949 | ||
2950 | if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) | |
2951 | return (qualifiers | (TREE_UNSIGNED (type) ? 12 : 2)); | |
2952 | ||
2953 | abort (); | |
210aa14a RS |
2954 | |
2955 | case REAL_TYPE: | |
77a02b01 JW |
2956 | /* Carefully distinguish all the standard types of C, |
2957 | without messing up if the language is not C. */ | |
2958 | if (TYPE_NAME (type) != 0 | |
2959 | && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
2960 | && DECL_NAME (TYPE_NAME (type)) != 0 | |
2961 | && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) | |
2962 | { | |
2963 | char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); | |
2964 | ||
2965 | if (!strcmp (name, "long double")) | |
2966 | return (qualifiers | 7); /* Who knows? */ | |
2967 | } | |
2968 | ||
2969 | if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) | |
2970 | return (qualifiers | 7); | |
2971 | if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) | |
210aa14a | 2972 | return (qualifiers | 6); |
77a02b01 | 2973 | if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) |
210aa14a | 2974 | return (qualifiers | 7); /* Who knows? */ |
77a02b01 | 2975 | abort (); |
210aa14a RS |
2976 | |
2977 | case COMPLEX_TYPE: /* GNU Fortran COMPLEX type. */ | |
13d39dbc | 2978 | /* ??? We need to distinguish between double and float complex types, |
c82aa69a JW |
2979 | but I don't know how yet because I can't reach this code from |
2980 | existing front-ends. */ | |
2981 | return (qualifiers | 7); /* Who knows? */ | |
2982 | ||
210aa14a RS |
2983 | case CHAR_TYPE: /* GNU Pascal CHAR type. Not used in C. */ |
2984 | case BOOLEAN_TYPE: /* GNU Fortran BOOLEAN type. */ | |
2985 | case FILE_TYPE: /* GNU Pascal FILE type. */ | |
2986 | case STRING_TYPE: /* GNU Fortran STRING type. */ | |
2987 | case LANG_TYPE: /* ? */ | |
2988 | abort (); | |
2989 | ||
2990 | default: | |
2991 | abort (); /* Not a type! */ | |
2992 | } | |
2993 | } | |
2994 | } | |
ead69aea | 2995 | \f |
c819be5b JW |
2996 | /* Subroutines to support a flat (single) register window calling |
2997 | convention. */ | |
2998 | ||
2999 | /* Single-register window sparc stack frames look like: | |
3000 | ||
3001 | Before call After call | |
3002 | +-----------------------+ +-----------------------+ | |
3003 | high | | | | | |
3004 | mem. | | | | | |
3005 | | caller's temps. | | caller's temps. | | |
3006 | | | | | | |
3007 | +-----------------------+ +-----------------------+ | |
3008 | | | | | | |
3009 | | arguments on stack. | | arguments on stack. | | |
3010 | | |FP+92->| | | |
3011 | +-----------------------+ +-----------------------+ | |
3012 | | 6 words to save | | 6 words to save | | |
3013 | | arguments passed | | arguments passed | | |
3014 | | in registers, even | | in registers, even | | |
3015 | SP+68->| if not passed. |FP+68->| if not passed. | | |
3016 | +-----------------------+ +-----------------------+ | |
3017 | | 1 word struct addr |FP+64->| 1 word struct addr | | |
3018 | +-----------------------+ +-----------------------+ | |
3019 | | | | | | |
3020 | | 16 word reg save area | | 16 word reg save area | | |
3021 | SP->| | FP->| | | |
3022 | +-----------------------+ +-----------------------+ | |
3023 | | 4 word area for | | |
3024 | FP-16->| fp/alu reg moves | | |
3025 | +-----------------------+ | |
3026 | | | | |
3027 | | local variables | | |
3028 | | | | |
3029 | +-----------------------+ | |
3030 | | | | |
3031 | | fp register save | | |
3032 | | | | |
3033 | +-----------------------+ | |
3034 | | | | |
3035 | | gp register save | | |
3036 | | | | |
3037 | +-----------------------+ | |
3038 | | | | |
3039 | | alloca allocations | | |
3040 | | | | |
3041 | +-----------------------+ | |
3042 | | | | |
3043 | | arguments on stack | | |
3044 | SP+92->| | | |
3045 | +-----------------------+ | |
3046 | | 6 words to save | | |
3047 | | arguments passed | | |
3048 | | in registers, even | | |
3049 | low SP+68->| if not passed. | | |
3050 | memory +-----------------------+ | |
3051 | SP+64->| 1 word struct addr | | |
3052 | +-----------------------+ | |
3053 | | | | |
3054 | I 16 word reg save area | | |
3055 | SP->| | | |
3056 | +-----------------------+ */ | |
3057 | ||
3058 | /* Structure to be filled in by sparc_frw_compute_frame_size with register | |
3059 | save masks, and offsets for the current function. */ | |
3060 | ||
3061 | struct sparc_frame_info | |
3062 | { | |
3063 | unsigned long total_size; /* # bytes that the entire frame takes up. */ | |
3064 | unsigned long var_size; /* # bytes that variables take up. */ | |
3065 | unsigned long args_size; /* # bytes that outgoing arguments take up. */ | |
3066 | unsigned long extra_size; /* # bytes of extra gunk. */ | |
3067 | unsigned int gp_reg_size; /* # bytes needed to store gp regs. */ | |
3068 | unsigned int fp_reg_size; /* # bytes needed to store fp regs. */ | |
3069 | unsigned long mask; /* Mask of saved gp registers. */ | |
3070 | unsigned long fmask; /* Mask of saved fp registers. */ | |
3071 | unsigned long gp_sp_offset; /* Offset from new sp to store gp regs. */ | |
3072 | unsigned long fp_sp_offset; /* Offset from new sp to store fp regs. */ | |
3073 | int initialized; /* Nonzero if frame size already calculated. */ | |
3074 | }; | |
3075 | ||
3076 | /* Current frame information calculated by sparc_frw_compute_frame_size. */ | |
3077 | struct sparc_frame_info current_frame_info; | |
3078 | ||
3079 | /* Zero structure to initialize current_frame_info. */ | |
3080 | struct sparc_frame_info zero_frame_info; | |
3081 | ||
3082 | /* Tell prologue and epilogue if register REGNO should be saved / restored. */ | |
3083 | ||
3084 | #define MUST_SAVE_REGISTER(regno) \ | |
3085 | ((regs_ever_live[regno] && !call_used_regs[regno]) \ | |
3086 | || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed) \ | |
3087 | || (regno == 15 && regs_ever_live[15])) | |
3088 | ||
3089 | /* Return the bytes needed to compute the frame pointer from the current | |
3090 | stack pointer. */ | |
3091 | ||
3092 | unsigned long | |
3093 | sparc_frw_compute_frame_size (size) | |
3094 | int size; /* # of var. bytes allocated. */ | |
3095 | { | |
3096 | int regno; | |
3097 | unsigned long total_size; /* # bytes that the entire frame takes up. */ | |
3098 | unsigned long var_size; /* # bytes that variables take up. */ | |
3099 | unsigned long args_size; /* # bytes that outgoing arguments take up. */ | |
3100 | unsigned long extra_size; /* # extra bytes. */ | |
3101 | unsigned int gp_reg_size; /* # bytes needed to store gp regs. */ | |
3102 | unsigned int fp_reg_size; /* # bytes needed to store fp regs. */ | |
3103 | unsigned long mask; /* Mask of saved gp registers. */ | |
3104 | unsigned long fmask; /* Mask of saved fp registers. */ | |
3105 | ||
3106 | /* This is the size of the 16 word reg save area, 1 word struct addr | |
3107 | area, and 4 word fp/alu register copy area. */ | |
3108 | extra_size = -STARTING_FRAME_OFFSET + FIRST_PARM_OFFSET(0); | |
3109 | var_size = size; | |
3110 | /* Also include the size needed for the 6 parameter registers. */ | |
3111 | args_size = current_function_outgoing_args_size + 24; | |
3112 | total_size = var_size + args_size + extra_size; | |
3113 | gp_reg_size = 0; | |
3114 | fp_reg_size = 0; | |
3115 | mask = 0; | |
3116 | fmask = 0; | |
3117 | ||
3118 | /* Calculate space needed for gp registers. */ | |
3119 | for (regno = 1; regno <= 31; regno++) | |
3120 | { | |
3121 | if (MUST_SAVE_REGISTER (regno)) | |
3122 | { | |
3123 | if ((regno & 0x1) == 0 && MUST_SAVE_REGISTER (regno+1)) | |
3124 | { | |
3125 | if (gp_reg_size % 8 != 0) | |
3126 | gp_reg_size += UNITS_PER_WORD; | |
3127 | gp_reg_size += 2 * UNITS_PER_WORD; | |
3128 | mask |= 3 << regno; | |
3129 | regno++; | |
3130 | } | |
3131 | else | |
3132 | { | |
3133 | gp_reg_size += UNITS_PER_WORD; | |
3134 | mask |= 1 << regno; | |
3135 | } | |
3136 | } | |
3137 | } | |
3138 | /* Add extra word in case we have to align the space to a double word | |
3139 | boundary. */ | |
3140 | if (gp_reg_size != 0) | |
3141 | gp_reg_size += UNITS_PER_WORD; | |
3142 | ||
3143 | /* Calculate space needed for fp registers. */ | |
3144 | for (regno = 32; regno <= 63; regno++) | |
3145 | { | |
3146 | if (regs_ever_live[regno] && !call_used_regs[regno]) | |
3147 | { | |
3148 | fp_reg_size += UNITS_PER_WORD; | |
3149 | fmask |= 1 << (regno - 32); | |
3150 | } | |
3151 | } | |
3152 | ||
3153 | total_size += gp_reg_size + fp_reg_size; | |
3154 | ||
3155 | if (total_size == extra_size) | |
3156 | total_size = extra_size = 0; | |
3157 | ||
3158 | total_size = SPARC_STACK_ALIGN (total_size); | |
3159 | ||
3160 | /* Save other computed information. */ | |
3161 | current_frame_info.total_size = total_size; | |
3162 | current_frame_info.var_size = var_size; | |
3163 | current_frame_info.args_size = args_size; | |
3164 | current_frame_info.extra_size = extra_size; | |
3165 | current_frame_info.gp_reg_size = gp_reg_size; | |
3166 | current_frame_info.fp_reg_size = fp_reg_size; | |
3167 | current_frame_info.mask = mask; | |
3168 | current_frame_info.fmask = fmask; | |
3169 | current_frame_info.initialized = reload_completed; | |
3170 | ||
3171 | if (mask) | |
3172 | { | |
3173 | unsigned long offset = args_size; | |
3174 | if (extra_size) | |
3175 | offset += FIRST_PARM_OFFSET(0); | |
3176 | current_frame_info.gp_sp_offset = offset; | |
3177 | } | |
3178 | ||
3179 | if (fmask) | |
3180 | { | |
3181 | unsigned long offset = args_size + gp_reg_size; | |
3182 | if (extra_size) | |
3183 | offset += FIRST_PARM_OFFSET(0); | |
3184 | current_frame_info.fp_sp_offset = offset; | |
3185 | } | |
3186 | ||
3187 | /* Ok, we're done. */ | |
3188 | return total_size; | |
3189 | } | |
3190 | \f | |
3191 | /* Common code to save/restore registers. */ | |
3192 | ||
3193 | void | |
3194 | sparc_frw_save_restore (file, word_op, doubleword_op) | |
3195 | FILE *file; /* Stream to write to. */ | |
3196 | char *word_op; /* Operation to do for one word. */ | |
3197 | char *doubleword_op; /* Operation to do for doubleword. */ | |
3198 | { | |
3199 | int regno; | |
3200 | unsigned long mask = current_frame_info.mask; | |
3201 | unsigned long fmask = current_frame_info.fmask; | |
3202 | unsigned long gp_offset; | |
3203 | unsigned long fp_offset; | |
3204 | unsigned long max_offset; | |
3205 | char *base_reg; | |
3206 | ||
3207 | if (mask == 0 && fmask == 0) | |
3208 | return; | |
3209 | ||
3210 | base_reg = reg_names[STACK_POINTER_REGNUM]; | |
3211 | gp_offset = current_frame_info.gp_sp_offset; | |
3212 | fp_offset = current_frame_info.fp_sp_offset; | |
3213 | max_offset = (gp_offset > fp_offset) ? gp_offset : fp_offset; | |
3214 | ||
3215 | /* Deal with calling functions with a large structure. */ | |
3216 | if (max_offset >= 4096) | |
3217 | { | |
3218 | char *temp = "%g2"; | |
3219 | fprintf (file, "\tset %ld,%s\n", max_offset, temp); | |
3220 | fprintf (file, "\tadd %s,%s,%s\n", temp, base_reg, temp); | |
3221 | base_reg = temp; | |
3222 | gp_offset = max_offset - gp_offset; | |
3223 | fp_offset = max_offset - fp_offset; | |
3224 | } | |
3225 | ||
3226 | /* Save registers starting from high to low. The debuggers prefer | |
3227 | at least the return register be stored at func+4, and also it | |
3228 | allows us not to need a nop in the epilog if at least one | |
3229 | register is reloaded in addition to return address. */ | |
3230 | ||
3231 | if (mask || frame_pointer_needed) | |
3232 | { | |
3233 | for (regno = 1; regno <= 31; regno++) | |
3234 | { | |
3235 | if ((mask & (1L << regno)) != 0 | |
3236 | || (regno == FRAME_POINTER_REGNUM && frame_pointer_needed)) | |
3237 | { | |
3238 | if ((regno & 0x1) == 0 && ((mask & (1L << regno+1)) != 0)) | |
3239 | { | |
3240 | if (gp_offset % 8 != 0) | |
3241 | gp_offset += UNITS_PER_WORD; | |
3242 | ||
3243 | if (word_op[0] == 's') | |
3244 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
3245 | doubleword_op, reg_names[regno], | |
3246 | base_reg, gp_offset); | |
3247 | else | |
3248 | fprintf (file, "\t%s [%s+%d],%s\n", | |
3249 | doubleword_op, base_reg, gp_offset, | |
3250 | reg_names[regno]); | |
3251 | ||
3252 | gp_offset += 2 * UNITS_PER_WORD; | |
3253 | regno++; | |
3254 | } | |
3255 | else | |
3256 | { | |
3257 | if (word_op[0] == 's') | |
3258 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
3259 | word_op, reg_names[regno], | |
3260 | base_reg, gp_offset); | |
3261 | else | |
3262 | fprintf (file, "\t%s [%s+%d],%s\n", | |
3263 | word_op, base_reg, gp_offset, reg_names[regno]); | |
3264 | ||
3265 | gp_offset += UNITS_PER_WORD; | |
3266 | } | |
3267 | } | |
3268 | } | |
3269 | } | |
3270 | ||
3271 | if (fmask) | |
3272 | { | |
3273 | for (regno = 32; regno <= 63; regno++) | |
3274 | { | |
3275 | if ((fmask & (1L << (regno - 32))) != 0) | |
3276 | { | |
3277 | if (word_op[0] == 's') | |
3278 | fprintf (file, "\t%s %s,[%s+%d]\n", | |
3279 | word_op, reg_names[regno], | |
3280 | base_reg, gp_offset); | |
3281 | else | |
3282 | fprintf (file, "\t%s [%s+%d],%s\n", | |
3283 | word_op, base_reg, gp_offset, reg_names[regno]); | |
3284 | ||
3285 | fp_offset += UNITS_PER_WORD; | |
3286 | } | |
3287 | } | |
3288 | } | |
3289 | } | |
3290 | \f | |
3291 | /* Set up the stack and frame (if desired) for the function. */ | |
3292 | ||
3293 | void | |
3294 | sparc_frw_output_function_prologue (file, size, ignored) | |
3295 | FILE *file; | |
3296 | int size; | |
3297 | { | |
3298 | extern char call_used_regs[]; | |
c819be5b JW |
3299 | int tsize; |
3300 | char *sp_str = reg_names[STACK_POINTER_REGNUM]; | |
a07c1915 JW |
3301 | |
3302 | /* ??? This should be %sp+actual_fsize for a leaf function. I think it | |
3303 | works only because it is never used. */ | |
c819be5b | 3304 | frame_base_name |
d4f55d3b | 3305 | = (!frame_pointer_needed) ? "%sp+80" : reg_names[FRAME_POINTER_REGNUM]; |
c819be5b JW |
3306 | |
3307 | fprintf (file, "\t!#PROLOGUE# 0\n"); | |
3308 | ||
3309 | size = SPARC_STACK_ALIGN (size); | |
3310 | tsize = (! current_frame_info.initialized | |
3311 | ? sparc_frw_compute_frame_size (size) | |
3312 | : current_frame_info.total_size); | |
3313 | ||
3314 | if (tsize > 0) | |
3315 | { | |
3316 | if (tsize <= 4095) | |
3317 | fprintf (file, | |
3318 | "\tsub %s,%d,%s\t\t!# vars= %d, regs= %d/%d, args = %d, extra= %d\n", | |
3319 | sp_str, tsize, sp_str, current_frame_info.var_size, | |
3320 | current_frame_info.gp_reg_size / 4, | |
3321 | current_frame_info.fp_reg_size / 8, | |
3322 | current_function_outgoing_args_size, | |
3323 | current_frame_info.extra_size); | |
3324 | else | |
3325 | fprintf (file, | |
3326 | "\tset %d,%s\n\tsub\t%s,%s,%s\t\t!# vars= %d, regs= %d/%d, args = %d, sfo= %d\n", | |
3327 | tsize, "%g1", sp_str, "%g1", | |
3328 | sp_str, current_frame_info.var_size, | |
3329 | current_frame_info.gp_reg_size / 4, | |
3330 | current_frame_info.fp_reg_size / 8, | |
3331 | current_function_outgoing_args_size, | |
3332 | current_frame_info.extra_size); | |
3333 | } | |
3334 | ||
3335 | sparc_frw_save_restore (file, "st", "std"); | |
3336 | ||
3337 | if (frame_pointer_needed) | |
3338 | { | |
3339 | if (tsize <= 4095) | |
3340 | fprintf (file, "\tadd %s,%d,%s\t!# set up frame pointer\n", sp_str, | |
3341 | tsize, frame_base_name); | |
3342 | else | |
3343 | fprintf (file, "\tadd %s,%s,%s\t!# set up frame pointer\n", sp_str, | |
3344 | "%g1", frame_base_name); | |
3345 | } | |
3346 | } | |
3347 | \f | |
3348 | /* Do any necessary cleanup after a function to restore stack, frame, | |
3349 | and regs. */ | |
3350 | ||
3351 | void | |
3352 | sparc_frw_output_function_epilogue (file, size, ignored1, ignored2) | |
3353 | FILE *file; | |
3354 | int size; | |
3355 | { | |
3356 | extern FILE *asm_out_data_file, *asm_out_file; | |
3357 | extern char call_used_regs[]; | |
3358 | extern int frame_pointer_needed; | |
3359 | int tsize; | |
3360 | char *sp_str = reg_names[STACK_POINTER_REGNUM]; | |
3361 | char *t1_str = "%g1"; | |
3362 | rtx epilogue_delay = current_function_epilogue_delay_list; | |
3363 | int noepilogue = FALSE; | |
c819be5b JW |
3364 | |
3365 | /* The epilogue does not depend on any registers, but the stack | |
3366 | registers, so we assume that if we have 1 pending nop, it can be | |
3367 | ignored, and 2 it must be filled (2 nops occur for integer | |
3368 | multiply and divide). */ | |
3369 | ||
3370 | size = SPARC_STACK_ALIGN (size); | |
3371 | tsize = (!current_frame_info.initialized | |
3372 | ? sparc_frw_compute_frame_size (size) | |
3373 | : current_frame_info.total_size); | |
3374 | ||
3375 | if (tsize == 0 && epilogue_delay == 0) | |
3376 | { | |
3377 | rtx insn = get_last_insn (); | |
3378 | ||
3379 | /* If the last insn was a BARRIER, we don't have to write any code | |
3380 | because a jump (aka return) was put there. */ | |
3381 | if (GET_CODE (insn) == NOTE) | |
3382 | insn = prev_nonnote_insn (insn); | |
3383 | if (insn && GET_CODE (insn) == BARRIER) | |
3384 | noepilogue = TRUE; | |
3385 | } | |
3386 | ||
3387 | if (!noepilogue) | |
3388 | { | |
3389 | /* In the reload sequence, we don't need to fill the load delay | |
3390 | slots for most of the loads, also see if we can fill the final | |
3391 | delay slot if not otherwise filled by the reload sequence. */ | |
3392 | ||
3393 | if (tsize > 4095) | |
3394 | fprintf (file, "\tset %d,%s\n", tsize, t1_str); | |
3395 | ||
3396 | if (frame_pointer_needed) | |
3397 | { | |
3398 | char *fp_str = reg_names[FRAME_POINTER_REGNUM]; | |
3399 | if (tsize > 4095) | |
3400 | fprintf (file,"\tsub %s,%s,%s\t\t!# sp not trusted here\n", | |
3401 | fp_str, t1_str, sp_str); | |
3402 | else | |
3403 | fprintf (file,"\tsub %s,%d,%s\t\t!# sp not trusted here\n", | |
3404 | fp_str, tsize, sp_str); | |
3405 | } | |
3406 | ||
3407 | sparc_frw_save_restore (file, "ld", "ldd"); | |
3408 | ||
c819be5b JW |
3409 | if (current_function_returns_struct) |
3410 | fprintf (file, "\tjmp %%o7+12\n"); | |
3411 | else | |
3412 | fprintf (file, "\tretl\n"); | |
3413 | ||
3414 | /* If the only register saved is the return address, we need a | |
3415 | nop, unless we have an instruction to put into it. Otherwise | |
3416 | we don't since reloading multiple registers doesn't reference | |
3417 | the register being loaded. */ | |
3418 | ||
3419 | if (epilogue_delay) | |
3420 | { | |
3421 | if (tsize) | |
3422 | abort (); | |
3423 | final_scan_insn (XEXP (epilogue_delay, 0), file, 1, -2, 1); | |
3424 | } | |
3425 | ||
3426 | else if (tsize > 4095) | |
3427 | fprintf (file, "\tadd %s,%s,%s\n", sp_str, t1_str, sp_str); | |
3428 | ||
3429 | else if (tsize > 0) | |
3430 | fprintf (file, "\tadd %s,%d,%s\n", sp_str, tsize, sp_str); | |
3431 | ||
3432 | else | |
3433 | fprintf (file, "\tnop\n"); | |
3434 | } | |
3435 | ||
3436 | /* Reset state info for each function. */ | |
3437 | current_frame_info = zero_frame_info; | |
3438 | } | |
3439 | \f | |
3440 | /* Define the number of delay slots needed for the function epilogue. | |
3441 | ||
3442 | On the sparc, we need a slot if either no stack has been allocated, | |
3443 | or the only register saved is the return register. */ | |
3444 | ||
3445 | int | |
3446 | sparc_frw_epilogue_delay_slots () | |
3447 | { | |
3448 | if (!current_frame_info.initialized) | |
3449 | (void) sparc_frw_compute_frame_size (get_frame_size ()); | |
3450 | ||
3451 | if (current_frame_info.total_size == 0) | |
3452 | return 1; | |
3453 | ||
c819be5b JW |
3454 | return 0; |
3455 | } | |
3456 | ||
3457 | /* Return true is TRIAL is a valid insn for the epilogue delay slot. | |
3458 | Any single length instruction which doesn't reference the stack or frame | |
3459 | pointer is OK. */ | |
3460 | ||
3461 | int | |
3462 | sparc_frw_eligible_for_epilogue_delay (trial, slot) | |
3463 | rtx trial; | |
3464 | int slot; | |
3465 | { | |
3466 | if (get_attr_length (trial) == 1 | |
3467 | && ! reg_mentioned_p (stack_pointer_rtx, PATTERN (trial)) | |
3468 | && ! reg_mentioned_p (frame_pointer_rtx, PATTERN (trial))) | |
3469 | return 1; | |
3470 | return 0; | |
3471 | } |