]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/a29k/a29k.c
Include function.h in most files.
[thirdparty/gcc.git] / gcc / config / a29k / a29k.c
1 /* Subroutines used for code generation on AMD Am29000.
2 Copyright (C) 1987, 88, 90-94, 1995, 1997, 1999 Free Software
3 Foundation, Inc.
4 Contributed by Richard Kenner (kenner@nyu.edu)
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include "config.h"
24 #include <stdio.h>
25 #include "rtl.h"
26 #include "regs.h"
27 #include "hard-reg-set.h"
28 #include "real.h"
29 #include "insn-config.h"
30 #include "conditions.h"
31 #include "insn-flags.h"
32 #include "output.h"
33 #include "insn-attr.h"
34 #include "flags.h"
35 #include "recog.h"
36 #include "function.h"
37 #include "expr.h"
38 #include "obstack.h"
39 #include "tree.h"
40 #include "reload.h"
41
42 #define min(A,B) ((A) < (B) ? (A) : (B))
43
44 /* This gives the size in words of the register stack for the current
45 procedure. */
46
47 static int a29k_regstack_size;
48
49 /* True if the current procedure has a call instruction. */
50
51 static int a29k_makes_calls;
52
53 /* This points to the last insn of the insn prologue. It is set when
54 an insn without a filled delay slot is found near the start of the
55 function. */
56
57 static char *a29k_last_prologue_insn;
58
59 /* This points to the first insn that will be in the epilogue. It is null if
60 no epilogue is required. */
61
62 static char *a29k_first_epilogue_insn;
63
64 /* This is nonzero if a a29k_first_epilogue_insn was put in a delay slot. It
65 indicates that an intermediate label needs to be written. */
66
67 static int a29k_first_epilogue_insn_used;
68
69 /* Location to hold the name of the current function. We need this prolog to
70 contain the tag words prior to the declaration. So the name must be stored
71 away. */
72
73 char *a29k_function_name;
74
75 /* Mapping of registers to debug register numbers. The only change is
76 for the frame pointer and the register numbers used for the incoming
77 arguments. */
78
79 int a29k_debug_reg_map[FIRST_PSEUDO_REGISTER];
80
81 /* Save information from a "cmpxx" operation until the branch or scc is
82 emitted. */
83
84 rtx a29k_compare_op0, a29k_compare_op1;
85 int a29k_compare_fp_p;
86
87 /* Gives names for registers. */
88 extern char *reg_names[];
89 \f
90 /* Returns 1 if OP is a 8-bit constant. */
91
92 int
93 cint_8_operand (op, mode)
94 register rtx op;
95 enum machine_mode mode;
96 {
97 return GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffffff00) == 0;
98 }
99
100 /* Returns 1 if OP is a 16-bit constant. */
101
102 int
103 cint_16_operand (op, mode)
104 rtx op;
105 enum machine_mode mode;
106 {
107 return GET_CODE (op) == CONST_INT && (INTVAL (op) & 0xffff0000) == 0;
108 }
109
110 /* Returns 1 if OP is a constant that cannot be moved in a single insn. */
111
112 int
113 long_const_operand (op, mode)
114 register rtx op;
115 enum machine_mode mode;
116 {
117 if (! CONSTANT_P (op))
118 return 0;
119
120 if (TARGET_29050 && GET_CODE (op) == CONST_INT
121 && (INTVAL (op) & 0xffff) == 0)
122 return 0;
123
124 return (GET_CODE (op) != CONST_INT
125 || ((INTVAL (op) & 0xffff0000) != 0
126 && (INTVAL (op) & 0xffff0000) != 0xffff0000
127 && INTVAL (op) != 0x80000000));
128 }
129 \f
130 /* The following four functions detect constants of 0, 8, 16, and 24 used as
131 a position in ZERO_EXTRACT operations. They can either be the appropriate
132 constant integer or a shift (which will be produced by combine). */
133
134 static int
135 shift_constant_operand (op, mode, val)
136 rtx op;
137 enum machine_mode mode;
138 int val;
139 {
140 return ((GET_CODE (op) == CONST_INT && INTVAL (op) == val)
141 || (GET_CODE (op) == ASHIFT
142 && GET_CODE (XEXP (op, 0)) == CONST_INT
143 && INTVAL (XEXP (op, 0)) == val / 8
144 && GET_CODE (XEXP (op, 1)) == CONST_INT
145 && INTVAL (XEXP (op, 1)) == 3));
146 }
147
148 int
149 const_0_operand (op, mode)
150 rtx op;
151 enum machine_mode mode;
152 {
153 return shift_constant_operand (op, mode, 0);
154 }
155
156 int
157 const_8_operand (op, mode)
158 rtx op;
159 enum machine_mode mode;
160 {
161 return shift_constant_operand (op, mode, 8);
162 }
163
164 int
165 const_16_operand (op, mode)
166 rtx op;
167 enum machine_mode mode;
168 {
169 return shift_constant_operand (op, mode, 16);
170 }
171
172 int
173 const_24_operand (op, mode)
174 rtx op;
175 enum machine_mode mode;
176 {
177 return shift_constant_operand (op, mode, 24);
178 }
179
180 /* Returns 1 if OP is a floating-point constant of the proper mode. */
181
182 int
183 float_const_operand (op, mode)
184 rtx op;
185 enum machine_mode mode;
186 {
187 return GET_CODE (op) == CONST_DOUBLE && GET_MODE (op) == mode;
188 }
189
190 /* Returns 1 if OP is a floating-point constant of the proper mode or a
191 general-purpose register. */
192
193 int
194 gpc_reg_or_float_constant_operand (op, mode)
195 rtx op;
196 enum machine_mode mode;
197 {
198 return float_const_operand (op, mode) || gpc_reg_operand (op, mode);
199 }
200
201 /* Returns 1 if OP is an integer constant of the proper mode or a
202 general-purpose register. */
203
204 int
205 gpc_reg_or_integer_constant_operand (op, mode)
206 rtx op;
207 enum machine_mode mode;
208 {
209 return ((GET_MODE (op) == VOIDmode
210 && (GET_CODE (op) == CONST_INT || GET_CODE (op) == CONST_DOUBLE))
211 || gpc_reg_operand (op, mode));
212 }
213 \f
214 /* Returns 1 if OP is a special machine register. */
215
216 int
217 spec_reg_operand (op, mode)
218 rtx op;
219 enum machine_mode mode;
220 {
221 if (GET_CODE (op) != REG || GET_MODE (op) != mode)
222 return 0;
223
224 switch (GET_MODE_CLASS (mode))
225 {
226 case MODE_PARTIAL_INT:
227 return REGNO (op) >= R_BP && REGNO (op) <= R_CR;
228 case MODE_INT:
229 return REGNO (op) >= R_Q && REGNO (op) <= R_EXO;
230 default:
231 return 0;
232 }
233 }
234
235 /* Returns 1 if OP is an accumulator register. */
236
237 int
238 accum_reg_operand (op, mode)
239 rtx op;
240 enum machine_mode mode;
241 {
242 return (GET_CODE (op) == REG
243 && REGNO (op) >= R_ACU (0) && REGNO (op) <= R_ACU (3));
244 }
245
246 /* Returns 1 if OP is a normal data register. */
247
248 int
249 gpc_reg_operand (op, mode)
250 rtx op;
251 enum machine_mode mode;
252 {
253 int regno;
254
255 if (GET_MODE (op) != mode && mode != VOIDmode)
256 return 0;
257
258 if (GET_CODE (op) == REG)
259 regno = REGNO (op);
260 else if (GET_CODE (op) == SUBREG && GET_CODE (SUBREG_REG (op)) == REG)
261 {
262 regno = REGNO (SUBREG_REG (op));
263 if (regno < FIRST_PSEUDO_REGISTER)
264 regno += SUBREG_WORD (op);
265 }
266 else
267 return 0;
268
269 return (regno >= FIRST_PSEUDO_REGISTER || regno < R_BP
270 || (regno >= R_KR (0) && regno <= R_KR (31)));
271 }
272
273 /* Returns 1 if OP is either an 8-bit constant integer or a general register.
274 If a register, it must be in the proper mode unless MODE is VOIDmode. */
275
276 int
277 srcb_operand (op, mode)
278 register rtx op;
279 enum machine_mode mode;
280 {
281 if (GET_CODE (op) == CONST_INT
282 && (mode == QImode
283 || (INTVAL (op) & 0xffffff00) == 0))
284 return 1;
285
286 if (GET_MODE (op) != mode && mode != VOIDmode)
287 return 0;
288
289 return gpc_reg_operand (op, mode);
290 }
291
292 int
293 cmplsrcb_operand (op, mode)
294 register rtx op;
295 enum machine_mode mode;
296 {
297 if (GET_CODE (op) == CONST_INT
298 && (mode == QImode
299 || (INTVAL (op) & 0xffffff00) == 0xffffff00))
300 return 1;
301
302 if (GET_MODE (op) != mode && mode != VOIDmode)
303 return 0;
304
305 return gpc_reg_operand (op, mode);
306 }
307
308 /* Return 1 if OP is either an immediate or a general register. This is used
309 for the input operand of mtsr/mtrsim. */
310
311 int
312 gpc_reg_or_immediate_operand (op, mode)
313 rtx op;
314 enum machine_mode mode;
315 {
316 return gpc_reg_operand (op, mode) || immediate_operand (op, mode);
317 }
318
319 /* Return 1 if OP can be used as the second operand of and AND insn. This
320 includes srcb_operand and a constant whose complement fits in 8 bits. */
321
322 int
323 and_operand (op, mode)
324 rtx op;
325 enum machine_mode mode;
326 {
327 return (srcb_operand (op, mode)
328 || (GET_CODE (op) == CONST_INT
329 && ((unsigned) ((~ INTVAL (op)) & GET_MODE_MASK (mode)) < 256)));
330 }
331
332 /* Return 1 if OP can be used as the second operand of an ADD insn.
333 This is the same as above, except we use negative, rather than
334 complement. */
335
336 int
337 add_operand (op, mode)
338 rtx op;
339 enum machine_mode mode;
340 {
341 return (srcb_operand (op, mode)
342 || (GET_CODE (op) == CONST_INT
343 && ((unsigned) ((- INTVAL (op)) & GET_MODE_MASK (mode)) < 256)));
344 }
345
346 /* Return 1 if OP is a valid address in a CALL_INSN. These are a SYMBOL_REF
347 to the current function, all SYMBOL_REFs if TARGET_SMALL_MEMORY, or
348 a sufficiently-small constant. */
349
350 int
351 call_operand (op, mode)
352 rtx op;
353 enum machine_mode mode;
354 {
355 switch (GET_CODE (op))
356 {
357 case SYMBOL_REF:
358 return (TARGET_SMALL_MEMORY
359 || (! TARGET_LARGE_MEMORY
360 && ((GET_CODE (op) == SYMBOL_REF && SYMBOL_REF_FLAG (op))
361 || ! strcmp (XSTR (op, 0), current_function_name))));
362
363 case CONST_INT:
364 return (unsigned HOST_WIDE_INT) INTVAL (op) < 0x40000;
365
366 default:
367 return 0;
368 }
369 }
370 \f
371 /* Return 1 if OP can be used as the input operand for a move insn. */
372
373 int
374 in_operand (op, mode)
375 rtx op;
376 enum machine_mode mode;
377 {
378 rtx orig_op = op;
379
380 if (! general_operand (op, mode))
381 return 0;
382
383 while (GET_CODE (op) == SUBREG)
384 op = SUBREG_REG (op);
385
386 switch (GET_CODE (op))
387 {
388 case REG:
389 return 1;
390
391 case MEM:
392 return (GET_MODE_SIZE (mode) >= UNITS_PER_WORD || TARGET_DW_ENABLE);
393
394 case CONST_INT:
395 if (GET_MODE_CLASS (mode) != MODE_INT
396 && GET_MODE_CLASS (mode) != MODE_PARTIAL_INT)
397 return 0;
398
399 return 1;
400
401 case CONST:
402 case SYMBOL_REF:
403 case LABEL_REF:
404 return (GET_MODE (op) == mode
405 || mode == SImode || mode == HImode || mode == QImode);
406
407 case CONST_DOUBLE:
408 return ((GET_MODE_CLASS (mode) == MODE_FLOAT
409 && mode == GET_MODE (op))
410 || (GET_MODE (op) == VOIDmode
411 && GET_MODE_CLASS (mode) == MODE_INT));
412
413 default:
414 return 0;
415 }
416 }
417
418 /* Return 1 if OP can be used as the output operand for a move insn. */
419
420 int
421 out_operand (op, mode)
422 rtx op;
423 enum machine_mode mode;
424 {
425 rtx orig_op = op;
426
427 if (! general_operand (op, mode))
428 return 0;
429
430 while (GET_CODE (op) == SUBREG)
431 op = SUBREG_REG (op);
432
433 if (GET_CODE (op) == REG)
434 return (gpc_reg_operand (orig_op, mode)
435 || spec_reg_operand (orig_op, mode)
436 || (GET_MODE_CLASS (mode) == MODE_FLOAT
437 && accum_reg_operand (orig_op, mode)));
438
439 else if (GET_CODE (op) == MEM)
440 return (GET_MODE_SIZE (mode) >= UNITS_PER_WORD || TARGET_DW_ENABLE);
441 else
442 return 0;
443 }
444
445 /* Return 1 if OP is an item in memory, given that we are in reload. */
446
447 int
448 reload_memory_operand (op, mode)
449 rtx op;
450 enum machine_mode mode;
451 {
452 int regno = true_regnum (op);
453
454 return (! CONSTANT_P (op)
455 && (regno == -1
456 || (GET_CODE (op) == REG
457 && REGNO (op) >= FIRST_PSEUDO_REGISTER)));
458 }
459
460 /* Given an object for which reload_memory_operand is true, return the address
461 of the operand, taking into account anything that reload may do. */
462
463 rtx
464 a29k_get_reloaded_address (op)
465 rtx op;
466 {
467 if (GET_CODE (op) == SUBREG)
468 {
469 if (SUBREG_WORD (op) != 0)
470 abort ();
471
472 op = SUBREG_REG (op);
473 }
474
475 if (GET_CODE (op) == REG)
476 op = reg_equiv_mem[REGNO (op)];
477
478 return find_replacement (&XEXP (op, 0));
479 }
480 \f
481 /* Subfunction of the following function. Update the flags of any MEM
482 found in part of X. */
483
484 static void
485 a29k_set_memflags_1 (x, in_struct_p, scalar_p, volatile_p, unchanging_p)
486 rtx x;
487 int in_struct_p, scalar_p, volatile_p, unchanging_p;
488 {
489 int i;
490
491 switch (GET_CODE (x))
492 {
493 case SEQUENCE:
494 case PARALLEL:
495 for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
496 a29k_set_memflags_1 (XVECEXP (x, 0, i), in_struct_p, volatile_p,
497 unchanging_p);
498 break;
499
500 case INSN:
501 a29k_set_memflags_1 (PATTERN (x), in_struct_p, volatile_p,
502 unchanging_p);
503 break;
504
505 case SET:
506 a29k_set_memflags_1 (SET_DEST (x), in_struct_p, volatile_p,
507 unchanging_p);
508 a29k_set_memflags_1 (SET_SRC (x), in_struct_p, volatile_p, unchanging_p);
509 break;
510
511 case MEM:
512 MEM_IN_STRUCT_P (x) = in_struct_p;
513 MEM_SCALAR_P (x) = scalar_p;
514 MEM_VOLATILE_P (x) = volatile_p;
515 RTX_UNCHANGING_P (x) = unchanging_p;
516 break;
517 }
518 }
519
520 /* Given INSN, which is either an INSN or a SEQUENCE generated to
521 perform a memory operation, look for any MEMs in either a SET_DEST or
522 a SET_SRC and copy the in-struct, unchanging, and volatile flags from
523 REF into each of the MEMs found. If REF is not a MEM, don't do
524 anything. */
525
526 void
527 a29k_set_memflags (insn, ref)
528 rtx insn;
529 rtx ref;
530 {
531 /* Note that it is always safe to get these flags, though they won't
532 be what we think if REF is not a MEM. */
533 int in_struct_p = MEM_IN_STRUCT_P (ref);
534 int scalar_p = MEM_SCALAR_P (ref);
535 int volatile_p = MEM_VOLATILE_P (ref);
536 int unchanging_p = RTX_UNCHANGING_P (ref);
537
538 if (GET_CODE (ref) != MEM
539 || (! in_struct_p && ! volatile_p && ! unchanging_p))
540 return;
541
542 a29k_set_memflags_1 (insn, in_struct_p, scalar_p, volatile_p, unchanging_p);
543 }
544 \f
545 /* Return 1 if OP is a comparison operator that we have in floating-point. */
546
547 int
548 fp_comparison_operator (op, mode)
549 rtx op;
550 enum machine_mode mode;
551 {
552 return ((mode == VOIDmode || mode == GET_MODE (op))
553 && (GET_CODE (op) == EQ || GET_CODE (op) == GT ||
554 GET_CODE (op) == GE));
555 }
556
557 /* Return 1 if OP is a valid branch comparison. */
558
559 int
560 branch_operator (op, mode)
561 rtx op;
562 enum machine_mode mode;
563 {
564 return ((mode == VOIDmode || mode == GET_MODE (op))
565 && (GET_CODE (op) == GE || GET_CODE (op) == LT));
566 }
567 \f
568 /* Return 1 if OP is a load multiple operation. It is known to be a
569 PARALLEL and the first three sections will be tested. */
570
571 int
572 load_multiple_operation (op, mode)
573 rtx op;
574 enum machine_mode mode;
575 {
576 int count = XVECLEN (op, 0) - 2;
577 int dest_regno;
578 rtx src_addr;
579 int i;
580
581 /* Perform a quick check so we don't blow up below. */
582 if (count <= 1
583 || GET_CODE (XVECEXP (op, 0, 0)) != SET
584 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != REG
585 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != MEM)
586 return 0;
587
588 dest_regno = REGNO (SET_DEST (XVECEXP (op, 0, 0)));
589 src_addr = XEXP (SET_SRC (XVECEXP (op, 0, 0)), 0);
590
591 for (i = 1; i < count; i++)
592 {
593 rtx elt = XVECEXP (op, 0, i + 2);
594
595 if (GET_CODE (elt) != SET
596 || GET_CODE (SET_DEST (elt)) != REG
597 || GET_MODE (SET_DEST (elt)) != SImode
598 || REGNO (SET_DEST (elt)) != dest_regno + i
599 || GET_CODE (SET_SRC (elt)) != MEM
600 || GET_MODE (SET_SRC (elt)) != SImode
601 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
602 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
603 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
604 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != i * 4)
605 return 0;
606 }
607
608 return 1;
609 }
610
611 /* Similar, but tests for store multiple. */
612
613 int
614 store_multiple_operation (op, mode)
615 rtx op;
616 enum machine_mode mode;
617 {
618 int num_special = TARGET_NO_STOREM_BUG ? 2 : 1;
619 int count = XVECLEN (op, 0) - num_special;
620 int src_regno;
621 rtx dest_addr;
622 int i;
623
624 /* Perform a quick check so we don't blow up below. */
625 if (count <= 1
626 || GET_CODE (XVECEXP (op, 0, 0)) != SET
627 || GET_CODE (SET_DEST (XVECEXP (op, 0, 0))) != MEM
628 || GET_CODE (SET_SRC (XVECEXP (op, 0, 0))) != REG)
629 return 0;
630
631 src_regno = REGNO (SET_SRC (XVECEXP (op, 0, 0)));
632 dest_addr = XEXP (SET_DEST (XVECEXP (op, 0, 0)), 0);
633
634 for (i = 1; i < count; i++)
635 {
636 rtx elt = XVECEXP (op, 0, i + num_special);
637
638 if (GET_CODE (elt) != SET
639 || GET_CODE (SET_SRC (elt)) != REG
640 || GET_MODE (SET_SRC (elt)) != SImode
641 || REGNO (SET_SRC (elt)) != src_regno + i
642 || GET_CODE (SET_DEST (elt)) != MEM
643 || GET_MODE (SET_DEST (elt)) != SImode
644 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
645 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_addr)
646 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
647 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != i * 4)
648 return 0;
649 }
650
651 return 1;
652 }
653 \f
654 /* Given a special register REG and MASK, a value being masked against a
655 quantity to which the special register is set, return 1 if the masking
656 operation is built-in to the setting of that special register. */
657
658 int
659 masks_bits_for_special (reg, mask)
660 rtx reg;
661 rtx mask;
662 {
663 int needed_mask_value;
664
665 if (GET_CODE (reg) != REG || GET_CODE (mask) != CONST_INT)
666 abort ();
667
668 switch (REGNO (reg))
669 {
670 case R_BP:
671 case R_INT:
672 needed_mask_value = 3;
673 break;
674
675 case R_FC:
676 needed_mask_value = 31;
677 break;
678
679 case R_CR:
680 case R_LRU:
681 needed_mask_value = 255;
682 break;
683
684 case R_FPE:
685 needed_mask_value = 511;
686 break;
687
688 case R_MMU:
689 needed_mask_value = 0x3ff;
690 break;
691
692 case R_OPS:
693 case R_CPS:
694 case R_RBP:
695 case R_FPS:
696 needed_mask_value = 0xffff;
697 break;
698
699 case R_VAB:
700 needed_mask_value = 0xffff0000;
701 break;
702
703 case R_Q:
704 case R_CFG:
705 case R_CHA:
706 case R_CHD:
707 case R_CHC:
708 case R_TMC:
709 case R_TMR:
710 case R_PC0:
711 case R_PC1:
712 case R_PC2:
713 return 0;
714
715 default:
716 abort ();
717 }
718
719 return (INTVAL (mask) & ~ needed_mask_value) == 0;
720 }
721 \f
722 /* Return nonzero if this label is that of the return point, but there is
723 a non-null epilogue. */
724
725 int
726 epilogue_operand (op, mode)
727 rtx op;
728 enum machine_mode mode;
729 {
730 return next_active_insn (op) == 0 && a29k_first_epilogue_insn != 0;
731 }
732 \f
733 /* Return the register class of a scratch register needed to copy IN into
734 or out of a register in CLASS in MODE. If it can be done directly,
735 NO_REGS is returned. */
736
737 enum reg_class
738 secondary_reload_class (class, mode, in)
739 enum reg_class class;
740 enum machine_mode mode;
741 rtx in;
742 {
743 int regno = -1;
744 enum rtx_code code = GET_CODE (in);
745
746 if (! CONSTANT_P (in))
747 {
748 regno = true_regnum (in);
749
750 /* A pseudo is the same as memory. */
751 if (regno == -1 || regno >= FIRST_PSEUDO_REGISTER)
752 code = MEM;
753 }
754
755 /* If we are transferring between memory and a multi-word mode, we need
756 CR. */
757
758 if (code == MEM && GET_MODE_SIZE (mode) > UNITS_PER_WORD)
759 return CR_REGS;
760
761 /* If between memory and a mode smaller than a word without DW being
762 enabled, we need BP. */
763
764 if (code == MEM && ! TARGET_DW_ENABLE
765 && GET_MODE_SIZE (mode) < UNITS_PER_WORD)
766 return BP_REGS;
767
768 /* Otherwise, we can place anything into GENERAL_REGS and can put
769 GENERAL_REGS into anything. */
770 if (class == GENERAL_REGS
771 || (regno != -1
772 && (regno < R_BP
773 || (regno >= R_KR (0) && regno <= R_KR (31)))))
774 return NO_REGS;
775
776 /* We can place 16-bit constants into a special register. */
777 if (code == CONST_INT
778 && (GET_MODE_BITSIZE (mode) <= 16 || (unsigned) INTVAL (in) <= 65535)
779 && (class == BP_REGS || class == Q_REGS || class == SPECIAL_REGS))
780 return NO_REGS;
781
782 /* Otherwise, we need GENERAL_REGS. */
783 return GENERAL_REGS;
784 }
785 \f
786 /* START is the zero-based incoming argument register index used (0 is 160,
787 i.e., the first incoming argument register) and COUNT is the number used.
788
789 Mark the corresponding incoming registers as neither fixed nor call used.
790 For each register used for incoming arguments, we have one less local
791 register that can be used. So also mark some high-numbered registers as
792 fixed.
793
794 Return the first register number to use for the argument. */
795
796 int
797 incoming_reg (start, count)
798 int start;
799 int count;
800 {
801 int i;
802
803 /* We only use 16 argument registers, so truncate at the end of the
804 area. */
805 if (start + count > 16)
806 count = 16 - start;
807
808 if (! TARGET_NO_REUSE_ARGS)
809 /* Mark all the used registers as not fixed and saved over calls. */
810 for (i = R_AR (start); i < R_AR (start + count); i++)
811 {
812 fixed_regs[i] = call_used_regs[i] = call_fixed_regs[i] = 0;
813 CLEAR_HARD_REG_BIT (fixed_reg_set, i);
814 CLEAR_HARD_REG_BIT (call_used_reg_set, i);
815 CLEAR_HARD_REG_BIT (call_fixed_reg_set, i);
816 }
817
818 /* Shorten the maximum size of the frame.
819 Remember that R_AR(-1,-2) are place holders for the caller's lr0,lr1.
820 Make sure to keep the frame rounded to an even boundary. Rounding up
821 to an 8 byte boundary will use a slot. Otherwise a frame with 121 local
822 regs and 5 arguments will overrun the stack (121+1 + 5 + 2 > 128). */
823 /* ??? An alternative would be to never allocate one reg. */
824 for (i = (R_AR (0) - 2 - start - count) & ~1; i < R_AR (0) - 2 - start; i++)
825 {
826 fixed_regs[i] = call_used_regs[i] = call_fixed_regs[i] = 1;
827 SET_HARD_REG_BIT (fixed_reg_set, i);
828 SET_HARD_REG_BIT (call_used_reg_set, i);
829 SET_HARD_REG_BIT (call_fixed_reg_set, i);
830 }
831
832 return R_AR (start);
833 }
834 \f
835 /* Add CLOBBERs to CALL_INSN_FUNCTION_USAGE chain of INSN indicating
836 that LR2 up to, but not including, OP are clobbered. If OP is
837 zero, indicate all parameter registers are clobbered. */
838
839 void
840 a29k_clobbers_to (insn, op)
841 rtx insn;
842 rtx op;
843 {
844 int i;
845 int high_regno;
846
847 if (op == 0)
848 high_regno = R_LR (18);
849 else if (GET_CODE (op) != REG || REGNO (op) < R_LR (0)
850 || REGNO (op) > R_LR (18))
851 abort ();
852 else
853 high_regno = REGNO (op);
854
855 for (i = R_LR (2); i < high_regno; i++)
856 CALL_INSN_FUNCTION_USAGE (insn)
857 = gen_rtx (EXPR_LIST, VOIDmode,
858 gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, SImode, i)),
859 CALL_INSN_FUNCTION_USAGE (insn));
860 }
861 \f
862 /* These routines are used in finding insns to fill delay slots in the
863 epilogue. */
864
865 /* Return 1 if the current function will adjust the register stack. */
866
867 int
868 needs_regstack_p ()
869 {
870 int i;
871 rtx insn;
872
873 if (frame_pointer_needed)
874 return 1;
875
876 /* If any local register is used, we need to adjust the regstack. */
877 for (i = R_LR (127); i >= R_LR (0); i --)
878 if (regs_ever_live[i])
879 return 1;
880
881 /* We need a register stack if we make any calls. */
882 for (insn = get_insns (); insn; insn = next_insn (insn))
883 if (GET_CODE (insn) == CALL_INSN
884 || (GET_CODE (insn) == INSN
885 && GET_CODE (PATTERN (insn)) == SEQUENCE
886 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN))
887 return 1;
888
889 /* Otherwise, we don't. */
890 return 0;
891 }
892
893 /* Return 1 if X uses a local register. */
894
895 int
896 uses_local_reg_p (x)
897 rtx x;
898 {
899 char *fmt;
900 int i, j;
901
902 switch (GET_CODE (x))
903 {
904 case REG:
905 return REGNO (x) >= R_LR (0) && REGNO (x) <= R_FP;
906
907 case CONST_INT:
908 case CONST:
909 case PC:
910 case CC0:
911 case LABEL_REF:
912 case SYMBOL_REF:
913 return 0;
914 }
915
916 fmt = GET_RTX_FORMAT (GET_CODE (x));
917 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
918 {
919 if (fmt[i] == 'e')
920 {
921 if (uses_local_reg_p (XEXP (x, i)))
922 return 1;
923 }
924 else if (fmt[i] == 'E')
925 {
926 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
927 if (uses_local_reg_p (XVECEXP (x, i, j)))
928 return 1;
929 }
930 }
931
932 return 0;
933 }
934
935 /* Returns 1 if this function is known to have a null epilogue. */
936
937 int
938 null_epilogue ()
939 {
940 return (reload_completed && ! needs_regstack_p ()
941 && get_frame_size () == 0
942 && current_function_pretend_args_size == 0);
943 }
944 \f
945 /* Write out the assembler form of an operand. Recognize the following
946 special options:
947
948 %N means write the low-order 8 bits of the negative of the constant
949 %Q means write a QImode operand (truncate constants to 8 bits)
950 %M means write the low-order 16 bits of the constant
951 %m means write the low-order 16 bits shifted left 16 bits
952 %C means write the low-order 8 bits of the complement of the constant
953 %b means write `f' is this is a reversed condition, `t' otherwise
954 %B means write `t' is this is a reversed condition, `f' otherwise
955 %J means write the 29k opcode part for a comparison operation
956 %e means write the label with an extra `X' is this is the epilogue
957 otherwise the normal label name
958 %E means write nothing if this insn has a delay slot,
959 a nop unless this is the epilogue label, in which case
960 write the first epilogue insn
961 %F means write just the normal operand if the insn has a delay slot;
962 otherwise, this is a recursive call so output the
963 symbol + 4 and write the first prologue insn in the
964 delay slot.
965 %L means write the register number plus one ("low order" register)
966 or the low-order part of a multi-word constant
967 %O means write the register number plus two
968 %P means write the register number plus three ("low order" of TImode)
969 %S means write the number of words in the mode of the operand,
970 minus one (for CR)
971 %V means write the number of elements in a PARALLEL minus 1
972 %# means write nothing if we have a delay slot, "\n\tnop" otherwise
973 %* means write the register name for TPC. */
974
975 void
976 print_operand (file, x, code)
977 FILE *file;
978 rtx x;
979 char code;
980 {
981 char buf[100];
982
983 /* These macros test for integers and extract the low-order bits. */
984 #define INT_P(X) \
985 ((GET_CODE (X) == CONST_INT || GET_CODE (X) == CONST_DOUBLE) \
986 && GET_MODE (X) == VOIDmode)
987
988 #define INT_LOWPART(X) \
989 (GET_CODE (X) == CONST_INT ? INTVAL (X) : CONST_DOUBLE_LOW (X))
990
991 switch (code)
992 {
993 case 'Q':
994 if (GET_CODE (x) == REG)
995 break;
996 else if (! INT_P (x))
997 output_operand_lossage ("invalid %%Q value");
998 fprintf (file, "%d", INT_LOWPART (x) & 0xff);
999 return;
1000
1001 case 'C':
1002 if (! INT_P (x))
1003 output_operand_lossage ("invalid %%C value");
1004 fprintf (file, "%d", (~ INT_LOWPART (x)) & 0xff);
1005 return;
1006
1007 case 'N':
1008 if (! INT_P (x))
1009 output_operand_lossage ("invalid %%N value");
1010 fprintf (file, "%d", (- INT_LOWPART (x)) & 0xff);
1011 return;
1012
1013 case 'M':
1014 if (! INT_P (x))
1015 output_operand_lossage ("invalid %%M value");
1016 fprintf (file, "%d", INT_LOWPART (x) & 0xffff);
1017 return;
1018
1019 case 'm':
1020 if (! INT_P (x))
1021 output_operand_lossage ("invalid %%m value");
1022 fprintf (file, "%d", (INT_LOWPART (x) & 0xffff) << 16);
1023 return;
1024
1025 case 'b':
1026 if (GET_CODE (x) == GE)
1027 fprintf (file, "f");
1028 else
1029 fprintf (file, "t");
1030 return;
1031
1032 case 'B':
1033 if (GET_CODE (x) == GE)
1034 fprintf (file, "t");
1035 else
1036 fprintf (file, "f");
1037 return;
1038
1039 case 'J':
1040 /* It so happens that the RTX names for the conditions are the same as
1041 the 29k's insns except for "ne", which requires "neq". */
1042 fprintf (file, GET_RTX_NAME (GET_CODE (x)));
1043 if (GET_CODE (x) == NE)
1044 fprintf (file, "q");
1045 return;
1046
1047 case 'e':
1048 if (optimize && flag_delayed_branch
1049 && a29k_last_prologue_insn == 0 && epilogue_operand (x, VOIDmode)
1050 && dbr_sequence_length () == 0)
1051 {
1052 /* We need to output the label number of the last label in the
1053 function, which is not necessarily X since there might be
1054 a USE insn in between. First go forward to the last insn, then
1055 back up to a label. */
1056 while (NEXT_INSN (x) != 0)
1057 x = NEXT_INSN (x);
1058
1059 while (GET_CODE (x) != CODE_LABEL)
1060 x = PREV_INSN (x);
1061
1062 ASM_GENERATE_INTERNAL_LABEL (buf, "LX", CODE_LABEL_NUMBER (x));
1063 assemble_name (file, buf);
1064 }
1065 else
1066 output_asm_label (x);
1067 return;
1068
1069 case 'E':
1070 if (dbr_sequence_length ())
1071 ;
1072 else if (a29k_last_prologue_insn)
1073 {
1074 fprintf (file, "\n\t%s", a29k_last_prologue_insn);
1075 a29k_last_prologue_insn = 0;
1076 }
1077 else if (optimize && flag_delayed_branch
1078 && epilogue_operand (x, VOIDmode))
1079 {
1080 fprintf (file, "\n\t%s", a29k_first_epilogue_insn);
1081 a29k_first_epilogue_insn_used = 1;
1082 }
1083 else
1084 fprintf (file, "\n\tnop");
1085 return;
1086
1087 case 'F':
1088 output_addr_const (file, x);
1089 if (dbr_sequence_length () == 0)
1090 {
1091 /* If this doesn't have its delay slot filled, see if we need to
1092 put the last insn of the prolog in it. If not, see if this is
1093 a recursive call. If so, we can put the first insn of its
1094 prolog in the delay slot. Otherwise, write a nop. */
1095 if (a29k_last_prologue_insn)
1096 {
1097 fprintf (file, "\n\t%s", a29k_last_prologue_insn);
1098 a29k_last_prologue_insn = 0;
1099 }
1100 else if (GET_CODE (x) == SYMBOL_REF
1101 && ! strcmp (XSTR (x, 0), current_function_name))
1102 fprintf (file, "+4\n\t%s,%d",
1103 a29k_regstack_size >= 64 ? "const gr121" : "sub gr1,gr1",
1104 a29k_regstack_size * 4);
1105 else
1106 fprintf (file, "\n\tnop");
1107 }
1108 return;
1109
1110 case 'L':
1111 if (GET_CODE (x) == CONST_DOUBLE && GET_MODE (x) == DFmode)
1112 {
1113 union real_extract u;
1114
1115 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
1116 fprintf (file, "$double1(%.20e)", u.d);
1117 }
1118 else if (GET_CODE (x) == REG)
1119 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
1120 else
1121 output_operand_lossage ("invalid %%L value");
1122 return;
1123
1124 case 'O':
1125 if (GET_CODE (x) != REG)
1126 output_operand_lossage ("invalid %%O value");
1127 fprintf (file, "%s", reg_names[REGNO (x) + 2]);
1128 return;
1129
1130 case 'P':
1131 if (GET_CODE (x) != REG)
1132 output_operand_lossage ("invalid %%P value");
1133 fprintf (file, "%s", reg_names[REGNO (x) + 3]);
1134 return;
1135
1136 case 'S':
1137 fprintf (file, "%d", (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD)-1);
1138 return;
1139
1140 case 'V':
1141 if (GET_CODE (x) != PARALLEL)
1142 output_operand_lossage ("invalid %%V value");
1143 fprintf (file, "%d", XVECLEN (x, 0) - 2);
1144 return;
1145
1146 case '#':
1147 if (dbr_sequence_length () == 0)
1148 {
1149 if (a29k_last_prologue_insn)
1150 {
1151 fprintf (file, "\n\t%s", a29k_last_prologue_insn);
1152 a29k_last_prologue_insn = 0;
1153 }
1154 else
1155 fprintf (file, "\n\tnop");
1156 }
1157 return;
1158
1159 case '*':
1160 fprintf (file, "%s", reg_names [R_TPC]);
1161 return;
1162 }
1163
1164 if (GET_CODE (x) == REG)
1165 fprintf (file, "%s", reg_names [REGNO (x)]);
1166
1167 else if (GET_CODE (x) == MEM)
1168 output_address (XEXP (x, 0));
1169
1170 else if (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == SUBREG
1171 && GET_CODE (SUBREG_REG (XEXP (x, 0))) == CONST_DOUBLE)
1172 {
1173 union real_extract u;
1174
1175 if (GET_MODE (SUBREG_REG (XEXP (x, 0))) == SFmode)
1176 fprintf (file, "$float");
1177 else
1178 fprintf (file, "$double%d", SUBREG_WORD (XEXP (x, 0)));
1179 bcopy ((char *) &CONST_DOUBLE_LOW (SUBREG_REG (XEXP (x, 0))),
1180 (char *) &u, sizeof u);
1181 fprintf (file, "(%.20e)", u.d);
1182 }
1183
1184 else if (GET_CODE (x) == CONST_DOUBLE
1185 && GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
1186 {
1187 union real_extract u;
1188
1189 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
1190 fprintf (file, "$%s(%.20e)",
1191 GET_MODE (x) == SFmode ? "float" : "double0", u.d);
1192 }
1193
1194 else
1195 output_addr_const (file, x);
1196 }
1197 \f
1198 /* This page contains routines to output function prolog and epilog code. */
1199
1200 /* Compute the size of the register stack, and determine if there are any
1201 call instructions. */
1202
1203 static void
1204 compute_regstack_size ()
1205 {
1206 int i;
1207 rtx insn;
1208
1209 /* See if we make any calls. We need to set lr1 if so. */
1210 a29k_makes_calls = 0;
1211 for (insn = get_insns (); insn; insn = next_insn (insn))
1212 if (GET_CODE (insn) == CALL_INSN
1213 || (GET_CODE (insn) == INSN
1214 && GET_CODE (PATTERN (insn)) == SEQUENCE
1215 && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == CALL_INSN))
1216 {
1217 a29k_makes_calls = 1;
1218 break;
1219 }
1220
1221 /* Find the highest local register used. */
1222 for (i = R_LR (127); i >= R_LR (0); i--)
1223 if (regs_ever_live[i])
1224 break;
1225
1226 a29k_regstack_size = i - (R_LR (0) - 1);
1227
1228 /* If calling routines, ensure we count lr0 & lr1. */
1229 if (a29k_makes_calls && a29k_regstack_size < 2)
1230 a29k_regstack_size = 2;
1231
1232 /* Count frame pointer and align to 8 byte boundary (even number of
1233 registers). */
1234 a29k_regstack_size += frame_pointer_needed;
1235 if (a29k_regstack_size & 1) a29k_regstack_size++;
1236 }
1237
1238 /* Sets register names for incoming arguments and frame pointer.
1239 This can't be computed until after register allocation. */
1240
1241 void
1242 a29k_compute_reg_names ()
1243 {
1244 int i;
1245
1246 compute_regstack_size ();
1247
1248 /* Set the names and numbers of the frame pointer and incoming argument
1249 registers. */
1250
1251 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1252 a29k_debug_reg_map[i] = i;
1253
1254 reg_names[FRAME_POINTER_REGNUM] = reg_names[R_LR (a29k_regstack_size - 1)];
1255 a29k_debug_reg_map[FRAME_POINTER_REGNUM] = R_LR (a29k_regstack_size - 1);
1256
1257 for (i = 0; i < 16; i++)
1258 {
1259 reg_names[R_AR (i)] = reg_names[R_LR (a29k_regstack_size + i + 2)];
1260 a29k_debug_reg_map[R_AR (i)] = R_LR (a29k_regstack_size + i + 2);
1261 }
1262
1263 /* If using kernel register map, swap numbers for kernel and user
1264 registers. */
1265 if (TARGET_KERNEL_REGISTERS)
1266 for (i = 0; i < 32; i++)
1267 {
1268 int tem = a29k_debug_reg_map[i];
1269 a29k_debug_reg_map[i] = a29k_debug_reg_map[R_KR (i)];
1270 a29k_debug_reg_map[R_KR (i)] = tem;
1271 }
1272 }
1273
1274 /* Output function prolog code to file FILE. Memory stack size is SIZE. */
1275
1276 void
1277 output_prolog (file, size)
1278 FILE *file;
1279 int size;
1280 {
1281 int i;
1282 int arg_count = 0;
1283 rtx insn;
1284 unsigned int tag_word;
1285
1286 /* See how many incoming arguments we have in registers. */
1287 for (i = R_AR (0); i < R_AR (16); i++)
1288 if (! fixed_regs[i])
1289 arg_count++;
1290
1291 /* The argument count includes the caller's lr0 and lr1. */
1292 arg_count += 2;
1293
1294 /* Compute memory stack size. Add in number of bytes that the we should
1295 push and pretend the caller did and the size of outgoing arguments.
1296 Then round to a doubleword boundary. */
1297 size += (current_function_pretend_args_size
1298 + current_function_outgoing_args_size);
1299 size = (size + 7) & ~7;
1300
1301 /* Write header words. See if one or two word form. */
1302 tag_word = (frame_pointer_needed ? 0x400000 : 0) + (arg_count << 16);
1303
1304 if (size / 8 > 0xff)
1305 fprintf (file, "\t.word %d, 0x%0x\n", (size / 8) << 2,
1306 0x800000 + tag_word);
1307 else
1308 fprintf (file, "\t.word 0x%0x\n", tag_word + ((size / 8) << 3));
1309
1310 /* Define the function name. */
1311 assemble_name (file, a29k_function_name);
1312 fprintf (file, ":\n");
1313
1314 /* Push the register stack by the proper amount. There are two possible
1315 ways to do this. */
1316 if (a29k_regstack_size >= 256/4)
1317 fprintf (file, "\tconst %s,%d\n\tsub gr1,gr1,%s\n",
1318 reg_names[R_TAV], a29k_regstack_size * 4, reg_names[R_TAV]);
1319 else if (a29k_regstack_size)
1320 fprintf (file, "\tsub gr1,gr1,%d\n", a29k_regstack_size * 4);
1321
1322 /* Test that the registers are available. */
1323 if (a29k_regstack_size)
1324 fprintf (file, "\tasgeu V_%sSPILL,gr1,%s\n",
1325 TARGET_KERNEL_REGISTERS ? "K" : "", reg_names[R_RAB]);
1326
1327 /* Set up frame pointer, if one is needed. */
1328 if (frame_pointer_needed)
1329 fprintf (file, "\tsll %s,%s,0\n", reg_names[FRAME_POINTER_REGNUM],
1330 reg_names[R_MSP]);
1331
1332 /* Make room for any frame space. There are three ways to do this. */
1333 if (size >= 256)
1334 {
1335 fprintf (file, "\tconst %s,%d\n", reg_names[R_TAV], size);
1336 if (size >= 65536)
1337 fprintf (file, "\tconsth %s,%d\n", reg_names[R_TAV], size);
1338 if (TARGET_STACK_CHECK)
1339 fprintf (file, "\tcall %s,__msp_check\n", reg_names[R_TPC]);
1340 fprintf (file, "\tsub %s,%s,%s\n",
1341 reg_names[R_MSP], reg_names[R_MSP], reg_names[R_TAV]);
1342 }
1343 else if (size)
1344 {
1345 if (TARGET_STACK_CHECK)
1346 fprintf (file, "\tcall %s,__msp_check\n", reg_names[R_TPC]);
1347 fprintf (file, "\tsub %s,%s,%d\n",
1348 reg_names[R_MSP], reg_names[R_MSP], size);
1349 }
1350
1351 /* If this routine will make calls, set lr1. If we see an insn that
1352 can use a delay slot before a call or jump, save this insn for that
1353 slot (this condition is equivalent to seeing if we have an insn that
1354 needs delay slots before an insn that has a filled delay slot). */
1355 a29k_last_prologue_insn = 0;
1356 if (a29k_makes_calls)
1357 {
1358 i = (a29k_regstack_size + arg_count) * 4;
1359 if (i >= 256)
1360 fprintf (file, "\tconst %s,%d\n\tadd lr1,gr1,%s\n",
1361 reg_names[R_TAV], i, reg_names[R_TAV]);
1362 else
1363 {
1364 if (optimize && flag_delayed_branch)
1365 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
1366 {
1367 if (GET_CODE (insn) == CODE_LABEL
1368 || (GET_CODE (insn) == INSN
1369 && GET_CODE (PATTERN (insn)) == SEQUENCE))
1370 break;
1371
1372 if (GET_CODE (insn) == NOTE
1373 || (GET_CODE (insn) == INSN
1374 && (GET_CODE (PATTERN (insn)) == USE
1375 || GET_CODE (PATTERN (insn)) == CLOBBER)))
1376 continue;
1377
1378 if (num_delay_slots (insn) > 0)
1379 {
1380 a29k_last_prologue_insn = (char *) oballoc (100);
1381 sprintf (a29k_last_prologue_insn, "add lr1,gr1,%d", i);
1382 break;
1383 }
1384 }
1385
1386 if (a29k_last_prologue_insn == 0)
1387 fprintf (file, "\tadd lr1,gr1,%d\n", i);
1388 }
1389 }
1390
1391 /* Compute the first insn of the epilogue. */
1392 a29k_first_epilogue_insn_used = 0;
1393
1394 if (size == 0 && a29k_regstack_size == 0 && ! frame_pointer_needed)
1395 a29k_first_epilogue_insn = 0;
1396 else
1397 a29k_first_epilogue_insn = (char *) oballoc (100);
1398
1399 if (frame_pointer_needed)
1400 sprintf (a29k_first_epilogue_insn, "sll %s,%s,0",
1401 reg_names[R_MSP], reg_names[FRAME_POINTER_REGNUM]);
1402 else if (a29k_regstack_size)
1403 {
1404 if (a29k_regstack_size >= 256 / 4)
1405 sprintf (a29k_first_epilogue_insn, "const %s,%d",
1406 reg_names[R_TAV], a29k_regstack_size * 4);
1407 else
1408 sprintf (a29k_first_epilogue_insn, "add gr1,gr1,%d",
1409 a29k_regstack_size * 4);
1410 }
1411 else if (size)
1412 {
1413 if (size >= 256)
1414 sprintf (a29k_first_epilogue_insn, "const %s,%d",
1415 reg_names[R_TAV], size);
1416 else
1417 sprintf (a29k_first_epilogue_insn, "add %s,%s,%d",
1418 reg_names[R_MSP], reg_names[R_MSP], size);
1419 }
1420 }
1421 \f
1422 /* Call this after writing what might be the first instruction of the
1423 epilogue. If that first insn was used in a delay slot, an intermediate
1424 label is written. */
1425
1426 static void
1427 check_epilogue_internal_label (file)
1428 FILE *file;
1429 {
1430 rtx insn;
1431
1432 if (! a29k_first_epilogue_insn_used)
1433 return;
1434
1435 for (insn = get_last_insn ();
1436 GET_CODE (insn) != CODE_LABEL;
1437 insn = PREV_INSN (insn))
1438 ;
1439
1440 ASM_OUTPUT_INTERNAL_LABEL (file, "LX", CODE_LABEL_NUMBER (insn));
1441 a29k_first_epilogue_insn_used = 0;
1442 }
1443
1444 /* Output the epilog of the last procedure to file FILE. SIZE is the memory
1445 stack size. The register stack size is in the variable
1446 A29K_REGSTACK_SIZE. */
1447
1448 void
1449 output_epilog (file, size)
1450 FILE *file;
1451 int size;
1452 {
1453 rtx insn;
1454 int locals_unavailable = 0; /* True until after first insn
1455 after gr1 update. */
1456
1457 /* If we hit a BARRIER before a real insn or CODE_LABEL, we don't
1458 need to do anything because we are never jumped to. */
1459 insn = get_last_insn ();
1460 if (GET_CODE (insn) == NOTE)
1461 insn = prev_nonnote_insn (insn);
1462
1463 if (insn && GET_CODE (insn) == BARRIER)
1464 return;
1465
1466 /* If a frame pointer was needed we must restore the memory stack pointer
1467 before adjusting the register stack. */
1468 if (frame_pointer_needed)
1469 {
1470 fprintf (file, "\tsll %s,%s,0\n",
1471 reg_names[R_MSP], reg_names[FRAME_POINTER_REGNUM]);
1472 check_epilogue_internal_label (file);
1473 }
1474
1475 /* Restore the register stack. There are two ways to do this. */
1476 if (a29k_regstack_size)
1477 {
1478 if (a29k_regstack_size >= 256/4)
1479 {
1480 fprintf (file, "\tconst %s,%d\n",
1481 reg_names[R_TAV], a29k_regstack_size * 4);
1482 check_epilogue_internal_label (file);
1483 fprintf (file, "\tadd gr1,gr1,%s\n", reg_names[R_TAV]);
1484 }
1485 else
1486 {
1487 fprintf (file, "\tadd gr1,gr1,%d\n", a29k_regstack_size * 4);
1488 check_epilogue_internal_label (file);
1489 }
1490 locals_unavailable = 1;
1491 }
1492
1493 /* Restore the memory stack pointer if there is no frame pointer.
1494 Adjust the size to include any pretend arguments and pushed
1495 arguments and round to doubleword boundary. */
1496 size += (current_function_pretend_args_size
1497 + current_function_outgoing_args_size);
1498 size = (size + 7) & ~7;
1499
1500 if (size && ! frame_pointer_needed)
1501 {
1502 if (size >= 256)
1503 {
1504 fprintf (file, "\tconst %s,%d\n", reg_names[R_TAV], size);
1505 check_epilogue_internal_label (file);
1506 locals_unavailable = 0;
1507 if (size >= 65536)
1508 fprintf (file, "\tconsth %s,%d\n", reg_names[R_TAV], size);
1509 fprintf (file, "\tadd %s,%s,%s\n",
1510 reg_names[R_MSP], reg_names[R_MSP], reg_names[R_TAV]);
1511 }
1512 else
1513 {
1514 fprintf (file, "\tadd %s,%s,%d\n",
1515 reg_names[R_MSP], reg_names[R_MSP], size);
1516 check_epilogue_internal_label (file);
1517 locals_unavailable = 0;
1518 }
1519 }
1520
1521 if (locals_unavailable)
1522 {
1523 /* If we have an insn for this delay slot, write it. */
1524 if (current_function_epilogue_delay_list)
1525 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1526 file, 1, -2, 1);
1527 else
1528 fprintf (file, "\tnop\n");
1529 }
1530
1531 fprintf (file, "\tjmpi lr0\n");
1532 if (a29k_regstack_size)
1533 fprintf (file, "\tasleu V_%sFILL,lr1,%s\n",
1534 TARGET_KERNEL_REGISTERS ? "K" : "", reg_names[R_RFB]);
1535 else if (current_function_epilogue_delay_list)
1536 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1537 file, 1, -2, 1);
1538 else
1539 fprintf (file, "\tnop\n");
1540 }