* dwarf2out.c, fold-const.c, ipa-type-escape.c,
[official-gcc.git] / gcc / config / crx / crx.c
blob8eb4d0dcbbac985e1dac2d75e092304e78846be3
1 /* Output routines for GCC for CRX.
2 Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published
9 by the Free Software Foundation; either version 2, or (at your
10 option) any later version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /*****************************************************************************/
23 /* HEADER INCLUDES */
24 /*****************************************************************************/
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "tm.h"
30 #include "rtl.h"
31 #include "tree.h"
32 #include "tm_p.h"
33 #include "regs.h"
34 #include "hard-reg-set.h"
35 #include "real.h"
36 #include "insn-config.h"
37 #include "conditions.h"
38 #include "output.h"
39 #include "insn-codes.h"
40 #include "insn-attr.h"
41 #include "flags.h"
42 #include "except.h"
43 #include "function.h"
44 #include "recog.h"
45 #include "expr.h"
46 #include "optabs.h"
47 #include "toplev.h"
48 #include "basic-block.h"
49 #include "target.h"
50 #include "target-def.h"
52 /*****************************************************************************/
53 /* DEFINITIONS */
54 /*****************************************************************************/
56 /* Maximum number of register used for passing parameters. */
57 #define MAX_REG_FOR_PASSING_ARGS 5
59 /* Minimum number register used for passing parameters. */
60 #define MIN_REG_FOR_PASSING_ARGS 2
62 /* The maximum count of words supported in the assembly of the architecture in
63 * a push/pop instruction. */
64 #define MAX_COUNT 8
66 /* Predicate is true if the current function is a 'noreturn' function, i.e. it
67 * is qualified as volatile. */
68 #define FUNC_IS_NORETURN_P(decl) (TREE_THIS_VOLATILE (decl))
70 /* The following 3 macros are used in crx_legitimate_address_p() */
72 /* Returns 1 if the scale factor of an index address is valid. */
73 #define SCALE_FOR_INDEX_P(X) \
74 (GET_CODE (X) == CONST_INT \
75 && (INTVAL (X) == 1 || INTVAL (X) == 2 \
76 || INTVAL(X) == 4 || INTVAL (X) == 8))
78 /* Nonzero if the rtx X is a signed const int of n bits */
79 #define RTX_SIGNED_INT_FITS_N_BITS(X,n) \
80 ((GET_CODE(X) == CONST_INT \
81 && SIGNED_INT_FITS_N_BITS(INTVAL(X),n)) ? 1 : 0)
83 /* Nonzero if the rtx X is an unsigned const int of n bits. */
84 #define RTX_UNSIGNED_INT_FITS_N_BITS(X,n) \
85 ((GET_CODE(X) == CONST_INT \
86 && UNSIGNED_INT_FITS_N_BITS(INTVAL(X),n)) ? 1 : 0)
89 /* Register relative legal displacement */
90 #define CRX_REGISTER_RELATIVE_DISP_P(X) \
91 (CONSTANT_ADDRESS_P(X) \
92 && (GET_CODE (X) != CONST_INT \
93 || RTX_SIGNED_INT_FITS_N_BITS(X, GET_MODE_BITSIZE (Pmode))))
95 /*****************************************************************************/
96 /* STATIC VARIABLES */
97 /*****************************************************************************/
99 /* Non-zero if the last param processed is passed in a register. */
100 static int last_parm_in_reg;
102 /* Will hold the number of the last register the prologue saves, -1 if no
103 * register is saved. */
104 static int last_reg_to_save;
106 /* Each object in the array is a register number. Mark 1 for registers that
107 * need to be saved. */
108 static int save_regs[FIRST_PSEUDO_REGISTER];
110 /* Number of bytes saved on the stack for non-scratch registers */
111 static int sum_regs = 0;
113 /* Number of bytes saved on the stack for local variables. */
114 static int local_vars_size;
116 /* The sum of 2 sizes: locals vars and padding byte for saving the registers.
117 * Used in expand_prologue() and expand_epilogue(). */
118 static int size_for_adjusting_sp;
120 /* In case of a POST_INC or POST_DEC memory reference, we must report the mode
121 * of the memory reference from PRINT_OPERAND to PRINT_OPERAND_ADDRESS. */
122 static enum machine_mode output_memory_reference_mode;
124 /*****************************************************************************/
125 /* GLOBAL VARIABLES */
126 /*****************************************************************************/
128 /* Table of machine attributes. */
129 const struct attribute_spec crx_attribute_table[];
131 /* Test and compare insns use these globals to generate branch insns. */
132 rtx crx_compare_op0 = NULL_RTX;
133 rtx crx_compare_op1 = NULL_RTX;
135 /*****************************************************************************/
136 /* TARGETM FUNCTION PROTOTYPES */
137 /*****************************************************************************/
139 static bool crx_fixed_condition_code_regs (unsigned int *, unsigned int *);
140 static rtx crx_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
141 int incoming ATTRIBUTE_UNUSED);
142 static bool crx_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED);
144 /*****************************************************************************/
145 /* STACK LAYOUT AND CALLING CONVENTIONS */
146 /*****************************************************************************/
148 #undef TARGET_FIXED_CONDITION_CODE_REGS
149 #define TARGET_FIXED_CONDITION_CODE_REGS crx_fixed_condition_code_regs
151 #undef TARGET_STRUCT_VALUE_RTX
152 #define TARGET_STRUCT_VALUE_RTX crx_struct_value_rtx
154 #undef TARGET_RETURN_IN_MEMORY
155 #define TARGET_RETURN_IN_MEMORY crx_return_in_memory
157 /*****************************************************************************/
158 /* TARGET-SPECIFIC USES OF `__attribute__' */
159 /*****************************************************************************/
161 #undef TARGET_ATTRIBUTE_TABLE
162 #define TARGET_ATTRIBUTE_TABLE crx_attribute_table
164 const struct attribute_spec crx_attribute_table[] = {
165 /* ISRs have special prologue and epilogue requirements. */
166 {"interrupt", 0, 0, false, true, true, NULL},
167 {NULL, 0, 0, false, false, false, NULL}
171 /* Initialize 'targetm' variable which contains pointers to functions and data
172 * relating to the target machine. */
174 struct gcc_target targetm = TARGET_INITIALIZER;
177 /*****************************************************************************/
178 /* TARGET HOOK IMPLEMENTATIONS */
179 /*****************************************************************************/
181 /* Return the fixed registers used for condition codes. */
183 static bool
184 crx_fixed_condition_code_regs (unsigned int *p1, unsigned int *p2)
186 *p1 = CC_REGNUM;
187 *p2 = INVALID_REGNUM;
188 return true;
191 /* Implements hook TARGET_STRUCT_VALUE_RTX. */
193 static rtx
194 crx_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
195 int incoming ATTRIBUTE_UNUSED)
197 return gen_rtx_REG (Pmode, CRX_STRUCT_VALUE_REGNUM);
200 /* Implements hook TARGET_RETURN_IN_MEMORY. */
202 static bool
203 crx_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
205 if (TYPE_MODE (type) == BLKmode)
207 HOST_WIDE_INT size = int_size_in_bytes (type);
208 return (size == -1 || size > 8);
210 else
211 return false;
215 /*****************************************************************************/
216 /* MACRO IMPLEMENTATIONS */
217 /*****************************************************************************/
219 /* STACK LAYOUT AND CALLING CONVENTIONS ROUTINES */
220 /* --------------------------------------------- */
222 /* Return nonzero if the current function being compiled is an interrupt
223 * function as specified by the "interrupt" attribute. */
226 crx_interrupt_function_p (void)
228 tree attributes;
230 attributes = TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl));
231 return lookup_attribute ("interrupt", attributes) != NULL_TREE;
234 /* Compute values for the array save_regs and the variable sum_regs. The index
235 * of save_regs is numbers of register, each will get 1 if we need to save it
236 * in the current function, 0 if not. sum_regs is the total sum of the
237 * registers being saved. */
239 static void
240 crx_compute_save_regs (void)
242 unsigned int regno;
244 /* initialize here so in case the function is no-return it will be -1. */
245 last_reg_to_save = -1;
247 /* No need to save any registers if the function never returns. */
248 if (FUNC_IS_NORETURN_P (current_function_decl))
249 return;
251 /* Initialize the number of bytes to be saved. */
252 sum_regs = 0;
254 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
256 if (fixed_regs[regno])
258 save_regs[regno] = 0;
259 continue;
262 /* If this reg is used and not call-used (except RA), save it. */
263 if (crx_interrupt_function_p())
265 if (!current_function_is_leaf && call_used_regs[regno])
266 /* this is a volatile reg in a non-leaf interrupt routine - save it
267 * for the sake of its sons. */
268 save_regs[regno] = 1;
270 else if (regs_ever_live[regno])
271 /* This reg is used - save it. */
272 save_regs[regno] = 1;
273 else
274 /* This reg is not used, and is not a volatile - don't save. */
275 save_regs[regno] = 0;
277 else
279 /* If this reg is used and not call-used (except RA), save it. */
280 if (regs_ever_live[regno]
281 && (!call_used_regs[regno] || regno == RETURN_ADDRESS_REGNUM))
282 save_regs[regno] = 1;
283 else
284 save_regs[regno] = 0;
288 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
289 if (save_regs[regno] == 1)
291 last_reg_to_save = regno;
292 sum_regs += UNITS_PER_WORD;
296 /* Compute the size of the local area and the size to be adjusted by the
297 * prologue and epilogue. */
299 static void
300 crx_compute_frame (void)
302 /* For aligning the local variables. */
303 int stack_alignment = STACK_BOUNDARY / BITS_PER_UNIT;
304 int padding_locals;
306 /* Padding needed for each element of the frame. */
307 local_vars_size = get_frame_size ();
309 /* Align to the stack alignment. */
310 padding_locals = local_vars_size % stack_alignment;
311 if (padding_locals)
312 padding_locals = stack_alignment - padding_locals;
314 local_vars_size += padding_locals;
316 size_for_adjusting_sp = local_vars_size + (ACCUMULATE_OUTGOING_ARGS ?
317 current_function_outgoing_args_size : 0);
320 /* Implements the macro INITIAL_ELIMINATION_OFFSET, return the OFFSET. */
323 crx_initial_elimination_offset (int from, int to)
325 /* Compute this since we need to use sum_regs. */
326 crx_compute_save_regs ();
328 /* Compute this since we need to use local_vars_size. */
329 crx_compute_frame ();
331 if ((from) == FRAME_POINTER_REGNUM && (to) == STACK_POINTER_REGNUM)
332 return (ACCUMULATE_OUTGOING_ARGS ?
333 current_function_outgoing_args_size : 0);
334 else if ((from) == ARG_POINTER_REGNUM && (to) == FRAME_POINTER_REGNUM)
335 return (sum_regs + local_vars_size);
336 else if ((from) == ARG_POINTER_REGNUM && (to) == STACK_POINTER_REGNUM)
337 return (sum_regs + local_vars_size +
338 (ACCUMULATE_OUTGOING_ARGS ?
339 current_function_outgoing_args_size : 0));
340 else
341 abort ();
344 /* REGISTER USAGE */
345 /* -------------- */
347 /* Return the class number of the smallest class containing reg number REGNO.
348 * This could be a conditional expression or could index an array. */
350 enum reg_class
351 crx_regno_reg_class (int regno)
353 if (regno >= 0 && regno < SP_REGNUM)
354 return NOSP_REGS;
356 if (regno == SP_REGNUM) return GENERAL_REGS;
358 if (regno == LO_REGNUM) return LO_REGS;
359 if (regno == HI_REGNUM) return HI_REGS;
361 return NO_REGS;
364 /* Transfer between HILO_REGS and memory via secondary reloading. */
366 enum reg_class
367 crx_secondary_reload_class (enum reg_class class,
368 enum machine_mode mode ATTRIBUTE_UNUSED,
369 rtx x ATTRIBUTE_UNUSED)
371 if (reg_classes_intersect_p (class, HILO_REGS)
372 && true_regnum (x) == -1)
373 return GENERAL_REGS;
375 return NO_REGS;
378 /* Return 1 if hard register REGNO can hold a value of machine-mode MODE. */
381 crx_hard_regno_mode_ok (int regno, enum machine_mode mode)
383 /* CC can only hold CCmode values. */
384 if (regno == CC_REGNUM)
385 return GET_MODE_CLASS (mode) == MODE_CC;
386 if (GET_MODE_CLASS (mode) == MODE_CC)
387 return 0;
388 /* HILO registers can only hold SImode and DImode */
389 if (HILO_REGNO_P (regno))
390 return mode == SImode || mode == DImode;
391 return 1;
394 /* PASSING FUNCTION ARGUMENTS */
395 /* -------------------------- */
397 /* If enough param regs are available for passing the param of type TYPE return
398 * the number of registers needed else 0. */
400 static int
401 enough_regs_for_param (CUMULATIVE_ARGS * cum, tree type,
402 enum machine_mode mode)
404 int type_size;
405 int remaining_size;
407 if (mode != BLKmode)
408 type_size = GET_MODE_BITSIZE (mode);
409 else
410 type_size = int_size_in_bytes (type) * BITS_PER_UNIT;
412 remaining_size =
413 BITS_PER_WORD * (MAX_REG_FOR_PASSING_ARGS -
414 (MIN_REG_FOR_PASSING_ARGS + cum->ints) + 1);
416 /* Any variable which is too big to pass in two registers, will pass on
417 * stack. */
418 if ((remaining_size >= type_size) && (type_size <= 2 * BITS_PER_WORD))
419 return (type_size + BITS_PER_WORD - 1) / BITS_PER_WORD;
421 return 0;
424 /* Implements the macro FUNCTION_ARG defined in crx.h. */
427 crx_function_arg (CUMULATIVE_ARGS * cum, enum machine_mode mode, tree type,
428 int named ATTRIBUTE_UNUSED)
430 last_parm_in_reg = 0;
432 /* Function_arg() is called with this type just after all the args have had
433 * their registers assigned. The rtx that function_arg returns from this type
434 * is supposed to pass to 'gen_call' but currently it is not implemented (see
435 * macro GEN_CALL). */
436 if (type == void_type_node)
437 return NULL_RTX;
439 if (targetm.calls.must_pass_in_stack (mode, type) || (cum->ints < 0))
440 return NULL_RTX;
442 if (mode == BLKmode)
444 /* Enable structures that need padding bytes at the end to pass to a
445 * function in registers. */
446 if (enough_regs_for_param (cum, type, mode) != 0)
448 last_parm_in_reg = 1;
449 return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints);
453 if (MIN_REG_FOR_PASSING_ARGS + cum->ints > MAX_REG_FOR_PASSING_ARGS)
454 return NULL_RTX;
455 else
457 if (enough_regs_for_param (cum, type, mode) != 0)
459 last_parm_in_reg = 1;
460 return gen_rtx_REG (mode, MIN_REG_FOR_PASSING_ARGS + cum->ints);
464 return NULL_RTX;
467 /* Implements the macro INIT_CUMULATIVE_ARGS defined in crx.h. */
469 void
470 crx_init_cumulative_args (CUMULATIVE_ARGS * cum, tree fntype,
471 rtx libfunc ATTRIBUTE_UNUSED)
473 tree param, next_param;
475 cum->ints = 0;
477 /* Determine if this function has variable arguments. This is indicated by
478 * the last argument being 'void_type_mode' if there are no variable
479 * arguments. Change here for a different vararg. */
480 for (param = (fntype) ? TYPE_ARG_TYPES (fntype) : 0;
481 param != (tree) 0; param = next_param)
483 next_param = TREE_CHAIN (param);
484 if (next_param == (tree) 0 && TREE_VALUE (param) != void_type_node)
486 cum->ints = -1;
487 return;
492 /* Implements the macro FUNCTION_ARG_ADVANCE defined in crx.h. */
494 void
495 crx_function_arg_advance (CUMULATIVE_ARGS * cum, enum machine_mode mode,
496 tree type, int named ATTRIBUTE_UNUSED)
498 /* l holds the number of registers required */
499 int l = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
501 /* If the parameter isn't passed on a register don't advance cum. */
502 if (!last_parm_in_reg)
503 return;
505 if (targetm.calls.must_pass_in_stack (mode, type) || (cum->ints < 0))
506 return;
508 if (mode == SImode || mode == HImode || mode == QImode || mode == DImode)
510 if (l <= 1)
511 cum->ints += 1;
512 else
513 cum->ints += l;
515 else if (mode == SFmode || mode == DFmode)
516 cum->ints += l;
517 else if ((mode) == BLKmode)
519 if ((l = enough_regs_for_param (cum, type, mode)) != 0)
520 cum->ints += l;
525 /* Implements the macro FUNCTION_ARG_REGNO_P defined in crx.h. Return non-zero
526 * if N is a register used for passing parameters. */
529 crx_function_arg_regno_p (int n)
531 return (n <= MAX_REG_FOR_PASSING_ARGS && n >= MIN_REG_FOR_PASSING_ARGS);
534 /* ADDRESSING MODES */
535 /* ---------------- */
537 /* Implements the macro GO_IF_LEGITIMATE_ADDRESS defined in crx.h.
538 * The legitimate addressing modes for the CRX are:
540 * Relocations --> const | symbol_ref | label_ref
541 * Absolute address --> 32 bit absolute
542 * Post increment --> reg + 12 bit disp.
543 * Post modify --> reg + 12 bit disp.
544 * Register relative --> reg | 32 bit disp. + reg | 4 bit + reg
545 * Scaled index --> reg + reg | 22 bit disp. + reg + reg |
546 * 22 disp. + reg + reg + (2 | 4 | 8) */
549 crx_legitimate_address_p (enum machine_mode mode ATTRIBUTE_UNUSED,
550 rtx x, int strict)
552 /* Absolute address */
553 if (RTX_UNSIGNED_INT_FITS_N_BITS(x, GET_MODE_BITSIZE(Pmode)))
554 return 1;
556 /* Label */
557 if (GET_CODE (x) == CONST
558 || GET_CODE (x) == SYMBOL_REF
559 || GET_CODE (x) == LABEL_REF
560 || (GET_CODE (x) == REG && (strict ? STRICT_REG_OK_FOR_BASE_P (x)
561 : NONSTRICT_REG_OK_FOR_BASE_P (x))))
562 return 1;
564 /* Post increment - The first argument is a register and the second is
565 * 12-bit long int. */
566 if (GET_CODE (x) == POST_INC || GET_CODE (x) == POST_DEC)
568 /* Don't allow modes to be referenced through post autoinc/dec that
569 * cannot be loaded/stored with a single instruction */
570 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
571 return 0;
573 if((GET_CODE (XEXP (x, 0)) == REG)
574 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
575 : NONSTRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))))
576 return 1;
579 /* Post modify */
580 if (GET_CODE (x) == POST_MODIFY)
582 /* Don't allow modes to be referenced through post autoinc/dec that
583 * cannot be loaded/stored with a single instruction */
584 if (GET_MODE_SIZE (mode) > UNITS_PER_WORD)
585 return 0;
587 if (!(GET_CODE (XEXP (x, 0)) == REG
588 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
589 : NONSTRICT_REG_OK_FOR_BASE_P (XEXP (x, 0)))
590 && RTX_SIGNED_INT_FITS_N_BITS(XEXP (XEXP (x, 1), 1), 12)))
591 return 0;
593 if(!(GET_CODE (XEXP (x, 1)) == PLUS || GET_CODE (XEXP (x, 1)) == MINUS))
594 return 0;
596 if(!rtx_equal_p(XEXP (x, 0), XEXP (XEXP (x, 1), 0)))
597 return 0;
599 return 1;
602 if (GET_CODE (x) == PLUS)
604 /* Register relative */
605 if (GET_CODE (XEXP (x, 0)) == REG
606 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
607 : NONSTRICT_REG_OK_FOR_BASE_P (XEXP (x, 0)))
608 && (CRX_REGISTER_RELATIVE_DISP_P (XEXP (x, 1))))
609 return 1;
611 /* Scaled index with factor 1 */
612 /* 1a. reg + reg */
613 if (GET_CODE (XEXP (x, 0)) == REG
614 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 0))
615 : REG_OK_FOR_INDEX_P (XEXP (x, 0)))
616 && GET_CODE (XEXP (x, 1)) == REG
617 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 1))
618 : REG_OK_FOR_INDEXED_BASE_P (XEXP (x, 1))))
619 return 1;
621 /* Scaled index with different factor */
622 /* 1b. reg * scale + reg */
623 if (GET_CODE (XEXP (x, 0)) == MULT
624 && GET_CODE (XEXP( XEXP (x, 0), 0)) == REG
625 && (strict ? STRICT_REG_OK_FOR_INDEX_P (XEXP( XEXP (x, 0), 0))
626 : NONSTRICT_REG_OK_FOR_INDEX_P (XEXP( XEXP (x, 0), 0)))
627 && (SCALE_FOR_INDEX_P (XEXP( XEXP (x, 0), 1)))
628 && GET_CODE (XEXP (x, 1)) == REG
629 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (x, 1))
630 : NONSTRICT_REG_OK_FOR_BASE_P (XEXP (x, 1))))
631 return 1;
633 if (GET_CODE (XEXP (x, 0)) == PLUS)
635 /* 2. reg + reg + 22 bit disp. */
636 if (GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
637 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (XEXP (x, 0), 0))
638 : REG_OK_FOR_INDEX_P (XEXP (XEXP (x, 0), 0)))
639 && GET_CODE (XEXP (XEXP (x, 0), 1)) == REG
640 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (XEXP (x, 0), 1))
641 : REG_OK_FOR_INDEXED_BASE_P (XEXP (XEXP (x, 0), 1)))
642 && (RTX_SIGNED_INT_FITS_N_BITS(XEXP (x, 1), 22)))
643 return 1;
645 /* 3. reg * scale + reg + 22 bit disp. */
646 if ((GET_CODE (XEXP (XEXP (x, 0), 0)) == MULT)
647 && (GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == REG)
648 && (strict ?
649 STRICT_REG_OK_FOR_BASE_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
651 REG_OK_FOR_INDEXED_BASE_P (XEXP (XEXP (XEXP (x, 0), 0), 0)))
652 && (SCALE_FOR_INDEX_P (XEXP (XEXP (XEXP (x, 0), 0), 1)))
653 && (GET_CODE (XEXP (XEXP (x, 0), 1)) == REG)
654 && (strict ? STRICT_REG_OK_FOR_BASE_P (XEXP (XEXP (x, 0), 1)) :
655 REG_OK_FOR_INDEX_P (XEXP (XEXP (x, 0), 1)))
656 && (RTX_SIGNED_INT_FITS_N_BITS(XEXP (x, 1), 22)))
657 return 1;
661 return 0;
664 /* ROUTINES TO COMPUTE COSTS */
665 /* ------------------------- */
667 /* Return the cost of moving data of mode MODE between a register of class
668 * CLASS and memory; IN is zero if the value is to be written to memory,
669 * non-zero if it is to be read in. This cost is relative to those in
670 * REGISTER_MOVE_COST. */
673 crx_memory_move_cost (enum machine_mode mode,
674 enum reg_class class ATTRIBUTE_UNUSED,
675 int in ATTRIBUTE_UNUSED)
677 /* One LD or ST takes twice the time of a simple reg-reg move */
678 if (reg_classes_intersect_p (class, GENERAL_REGS))
680 /* printf("GENERAL_REGS LD/ST = %d\n", 4 * HARD_REGNO_NREGS (0, mode));*/
681 return 4 * HARD_REGNO_NREGS (0, mode);
683 else if (reg_classes_intersect_p (class, HILO_REGS))
685 /* HILO to memory and vice versa */
686 /* printf("HILO_REGS %s = %d\n",in ? "LD" : "ST",
687 (REGISTER_MOVE_COST(mode,
688 in ? GENERAL_REGS : HILO_REGS,
689 in ? HILO_REGS : GENERAL_REGS) + 4)
690 * HARD_REGNO_NREGS (0, mode)); */
691 return (REGISTER_MOVE_COST(mode,
692 in ? GENERAL_REGS : HILO_REGS,
693 in ? HILO_REGS : GENERAL_REGS) + 4)
694 * HARD_REGNO_NREGS (0, mode);
696 else /* default (like in i386) */
698 /* printf("ANYREGS = 100\n"); */
699 return 100;
703 /* INSTRUCTION OUTPUT */
704 /* ------------------ */
706 /* Print to FILE addr expression of the form post_inc/dec (in this case
707 * post_offset is zero) or post_inc/dec + post_offset */
709 static void
710 print_post_operand_address (FILE * file, rtx addr, int post_offset)
712 int displmnt;
714 if (GET_CODE (addr) == POST_MODIFY)
716 displmnt = INTVAL(XEXP( XEXP (addr, 1), 1));
717 if (GET_CODE (XEXP (addr, 1)) == MINUS) displmnt = (-1) * displmnt;
719 else
721 displmnt = GET_MODE_SIZE (output_memory_reference_mode);
722 /* Make the displacement negative for POST_DEC */
723 if (GET_CODE (addr) == POST_DEC) displmnt = (-1) * displmnt;
726 if (GET_CODE (XEXP (addr, 0)) != REG)
727 abort ();
729 displmnt += post_offset;
731 fprintf (file, "%d(%s)+", displmnt, reg_names[REGNO (XEXP (addr, 0))]);
734 /* Check if constant rtx contains label_ref. */
736 static rtx
737 const_and_contains_label_ref (rtx x)
739 if (!x)
740 return NULL_RTX;
742 if (GET_CODE (x) == LABEL_REF)
743 return x;
745 /* Check within enclosing const. */
746 if (GET_CODE (x) == CONST)
747 x = XEXP (x, 0);
749 if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
750 && GET_CODE (XEXP (x, 1)) == CONST_INT
751 && GET_CODE (XEXP (x, 0)) == LABEL_REF)
752 return XEXP (x, 0);
754 return NULL_RTX;
757 /* Check if rtx contains symbol_ref. */
759 static rtx
760 const_and_contains_symbol_ref (rtx x)
762 if (!x)
763 return NULL_RTX;
765 if (GET_CODE (x) == SYMBOL_REF)
766 return x;
768 /* Check within enclosing const. */
769 if (GET_CODE (x) == CONST)
770 x = XEXP (x, 0);
772 if ((GET_CODE (x) == PLUS || GET_CODE (x) == MINUS)
773 && GET_CODE (XEXP (x, 1)) == CONST_INT
774 && GET_CODE (XEXP (x, 0)) == SYMBOL_REF)
775 return XEXP (x, 0);
777 return NULL_RTX;
780 /* Check if a const_double is ok for crx store-immediate instructions */
783 crx_const_double_ok (rtx op)
785 if (GET_MODE (op) == DFmode)
787 REAL_VALUE_TYPE r;
788 long l[2];
789 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
790 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
791 return (UNSIGNED_INT_FITS_N_BITS(l[0], 4) &&
792 UNSIGNED_INT_FITS_N_BITS(l[1], 4)) ? 1 : 0;
795 if (GET_MODE (op) == SFmode)
797 REAL_VALUE_TYPE r;
798 long l;
799 REAL_VALUE_FROM_CONST_DOUBLE (r, op);
800 REAL_VALUE_TO_TARGET_SINGLE (r, l);
801 return UNSIGNED_INT_FITS_N_BITS(l, 4) ? 1 : 0;
804 return (UNSIGNED_INT_FITS_N_BITS (CONST_DOUBLE_LOW (op), 4) &&
805 UNSIGNED_INT_FITS_N_BITS (CONST_DOUBLE_HIGH (op), 4)) ? 1 : 0;
808 /* Implements the macro PRINT_OPERAND defined in crx.h. */
810 void
811 crx_print_operand (FILE * file, rtx x, int code)
813 switch (code)
815 case 'p' :
816 if (GET_CODE (x) == REG) {
817 if (GET_MODE (x) == DImode || GET_MODE (x) == DFmode)
819 int regno = REGNO (x);
820 if (regno + 1 >= SP_REGNUM) abort ();
821 fprintf (file, "{%s, %s}", reg_names[regno], reg_names[regno + 1]);
822 return;
824 else
826 if (REGNO (x) >= SP_REGNUM) abort ();
827 fprintf (file, "%s", reg_names[REGNO (x)]);
828 return;
832 case 'd' :
834 const char *crx_cmp_str;
835 switch (GET_CODE (x))
836 { /* MD: compare(reg, reg or imm) but CRX: cmp(reg or imm, reg)
837 * -> swap all non symmetric ops */
838 case EQ : crx_cmp_str = "eq"; break;
839 case NE : crx_cmp_str = "ne"; break;
840 case GT : crx_cmp_str = "lt"; break;
841 case GTU : crx_cmp_str = "lo"; break;
842 case LT : crx_cmp_str = "gt"; break;
843 case LTU : crx_cmp_str = "hi"; break;
844 case GE : crx_cmp_str = "le"; break;
845 case GEU : crx_cmp_str = "ls"; break;
846 case LE : crx_cmp_str = "ge"; break;
847 case LEU : crx_cmp_str = "hs"; break;
848 default : abort ();
850 fprintf (file, "%s", crx_cmp_str);
851 return;
854 case 'H':
855 /* Print high part of a double precision value. */
856 switch (GET_CODE (x))
858 case CONST_DOUBLE:
859 if (GET_MODE (x) == SFmode) abort ();
860 if (GET_MODE (x) == DFmode)
862 /* High part of a DF const. */
863 REAL_VALUE_TYPE r;
864 long l[2];
866 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
867 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
869 fprintf (file, "$0x%lx", l[1]);
870 return;
873 /* -- Fallthrough to handle DI consts -- */
875 case CONST_INT:
877 rtx high, low;
878 split_double (x, &low, &high);
879 putc ('$', file);
880 output_addr_const (file, high);
881 return;
884 case REG:
885 if (REGNO (x) + 1 >= FIRST_PSEUDO_REGISTER) abort ();
886 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
887 return;
889 case MEM:
890 /* Adjust memory address to high part. */
892 rtx adj_mem = x;
893 adj_mem = adjust_address (adj_mem, GET_MODE (adj_mem), 4);
895 output_memory_reference_mode = GET_MODE (adj_mem);
896 output_address (XEXP (adj_mem, 0));
897 return;
900 default:
901 abort ();
904 case 'L':
905 /* Print low part of a double precision value. */
906 switch (GET_CODE (x))
908 case CONST_DOUBLE:
909 if (GET_MODE (x) == SFmode) abort ();
910 if (GET_MODE (x) == DFmode)
912 /* High part of a DF const. */
913 REAL_VALUE_TYPE r;
914 long l[2];
916 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
917 REAL_VALUE_TO_TARGET_DOUBLE (r, l);
919 fprintf (file, "$0x%lx", l[0]);
920 return;
923 /* -- Fallthrough to handle DI consts -- */
925 case CONST_INT:
927 rtx high, low;
928 split_double (x, &low, &high);
929 putc ('$', file);
930 output_addr_const (file, low);
931 return;
934 case REG:
935 fprintf (file, "%s", reg_names[REGNO (x)]);
936 return;
938 case MEM:
939 output_memory_reference_mode = GET_MODE (x);
940 output_address (XEXP (x, 0));
941 return;
943 default:
944 abort ();
947 case 0 : /* default */
948 switch (GET_CODE(x))
950 case REG:
951 fprintf (file, "%s", reg_names[REGNO (x)]);
952 return;
954 case MEM:
955 output_memory_reference_mode = GET_MODE (x);
956 output_address (XEXP (x, 0));
957 return;
959 case CONST_DOUBLE:
961 REAL_VALUE_TYPE r;
962 long l;
964 /* Always use H and L for double precision - see above */
965 gcc_assert(GET_MODE (x) == SFmode);
967 REAL_VALUE_FROM_CONST_DOUBLE (r, x);
968 REAL_VALUE_TO_TARGET_SINGLE (r, l);
970 fprintf (file, "$0x%lx", l);
971 return;
974 default:
975 putc ('$', file);
976 output_addr_const (file, x);
977 return;
980 default:
981 output_operand_lossage ("invalid %%xn code");
984 abort ();
987 /* Implements the macro PRINT_OPERAND_ADDRESS defined in crx.h. */
989 void
990 crx_print_operand_address (FILE * file, rtx addr)
992 rtx breg = 0, ireg = 0;
993 rtx offset = 0;
994 rtx post_offset = 0;
995 rtx scale = 0;
996 int mem = 0;
998 retry:
999 switch (GET_CODE (addr))
1001 case MEM:
1002 fprintf (file, "0(");
1003 addr = XEXP (addr, 0);
1004 mem = 1;
1005 goto retry;
1006 case REG:
1007 fprintf (file, "0(%s)", reg_names[REGNO (addr)]);
1008 break;
1009 case MULT:
1010 abort ();
1011 break;
1012 case PLUS:
1013 switch (GET_CODE (XEXP (addr, 0)))
1015 case REG:
1016 if (GET_CODE (XEXP (addr, 1)) == REG)
1018 ireg = XEXP (addr, 0);
1019 breg = XEXP (addr, 1);
1021 else if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
1023 if (REG_OK_FOR_BASE_P (XEXP (addr, 0))
1024 && ((GET_CODE (XEXP (addr, 1)) == CONST_INT)
1025 || (const_and_contains_symbol_ref (XEXP (addr, 1)))
1026 || (const_and_contains_label_ref (XEXP (addr, 1)))))
1027 ireg = XEXP (addr, 0);
1028 else
1029 breg = XEXP (addr, 0);
1031 offset = XEXP (addr, 1);
1033 else
1034 abort ();
1035 break;
1036 case MULT:
1037 ireg = XEXP (XEXP (addr, 0), 0);
1038 scale = XEXP (XEXP (addr, 0), 1);
1039 breg = XEXP (addr, 1);
1040 break;
1041 case PLUS:
1042 if ((GET_CODE (XEXP (XEXP (addr, 0), 0)) == MULT)
1043 && (GET_CODE (XEXP (XEXP (XEXP (addr, 0), 0), 0)) == REG)
1044 && (SCALE_FOR_INDEX_P (XEXP (XEXP (XEXP (addr, 0), 0), 1)))
1045 && (GET_CODE (XEXP (XEXP (addr, 0), 1)) == REG)
1046 && (GET_CODE (XEXP (addr, 1)) == CONST_INT))
1048 ireg = XEXP (XEXP (XEXP (addr, 0), 0), 0);
1049 breg = XEXP (XEXP (addr, 0), 1);
1050 scale = (XEXP (XEXP (XEXP (addr, 0), 0), 1));
1051 offset = XEXP (addr, 1);
1053 else if (GET_CODE (XEXP (XEXP (addr, 0), 0)) == REG
1054 && GET_CODE (XEXP (XEXP (addr, 0), 1)) == REG
1055 && CONSTANT_ADDRESS_P (XEXP (addr, 1)))
1057 ireg = XEXP (XEXP (addr, 0), 0);
1058 breg = XEXP (XEXP (addr, 0), 1);
1059 offset = XEXP (addr, 1);
1061 else if (GET_CODE (XEXP (XEXP (addr, 0), 0)) == REG
1062 && GET_CODE (XEXP (addr, 1)) == REG
1063 && CONSTANT_ADDRESS_P (XEXP (XEXP (addr, 0), 1)))
1065 ireg = XEXP (XEXP (addr, 0), 0);
1066 breg = XEXP (addr, 1);
1067 offset = XEXP (XEXP (addr, 0), 1);
1069 else
1070 abort ();
1071 break;
1072 default:
1073 if (CONSTANT_ADDRESS_P (XEXP (addr, 1)))
1075 if (CONSTANT_ADDRESS_P (XEXP (addr, 0)))
1076 offset = addr;
1077 else if (GET_CODE (XEXP (addr, 0)) == POST_INC
1078 || GET_CODE (XEXP (addr, 0)) == POST_DEC)
1079 post_offset = XEXP (addr, 1);
1080 else
1081 abort ();
1084 break;
1087 if (scale)
1089 fprintf (file, "%ld(%s,%s,%ld)", offset ? INTVAL (offset) : 0,
1090 reg_names[REGNO (breg)], reg_names[REGNO (ireg)],
1091 INTVAL (scale));
1093 else
1095 /* If this is (POST_DEC/INC expression + post_offset) make addr =
1096 * POST_DEC/INC expression */
1097 if (post_offset != 0)
1099 addr = XEXP (addr, 0);
1100 print_post_operand_address (file, addr, INTVAL (post_offset));
1101 break;
1104 if (ireg != 0)
1106 if (offset != 0)
1108 output_addr_const (file, offset);
1109 /* Print modifier if relevant. */
1111 else
1113 fprintf (file, "0");
1115 /* Print address string */
1116 if (breg != 0)
1118 fprintf (file, "(%s,%s)", reg_names[REGNO (breg)],
1119 reg_names[REGNO (ireg)]);
1121 else
1122 fprintf (file, "(%s)", reg_names[REGNO (ireg)]);
1124 else
1126 if (offset != 0)
1128 output_addr_const (file, offset);
1130 else
1132 fprintf (file, "0");
1135 if (breg != 0)
1137 if (offset == 0)
1138 fprintf (file, "0");
1139 fprintf (file, "(%s)", reg_names[REGNO (breg)]);
1143 break;
1145 case POST_DEC:
1146 case POST_INC:
1147 case POST_MODIFY:
1148 print_post_operand_address (file, addr, 0);
1149 break;
1151 default:
1153 output_addr_const (file, addr);
1156 if (mem)
1157 fprintf (file, ")");
1161 /*****************************************************************************/
1162 /* MACHINE DESCRIPTION HELPER-FUNCTIONS */
1163 /*****************************************************************************/
1165 void crx_expand_movmem_single (rtx src, rtx srcbase, rtx dst, rtx dstbase,
1166 rtx tmp_reg, unsigned HOST_WIDE_INT *offset_p)
1168 rtx addr, mem;
1169 unsigned HOST_WIDE_INT offset = *offset_p;
1171 /* Load */
1172 addr = plus_constant (src, offset);
1173 mem = adjust_automodify_address (srcbase, SImode, addr, offset);
1174 emit_move_insn (tmp_reg, mem);
1176 /* Store */
1177 addr = plus_constant (dst, offset);
1178 mem = adjust_automodify_address (dstbase, SImode, addr, offset);
1179 emit_move_insn (mem, tmp_reg);
1181 *offset_p = offset + 4;
1185 crx_expand_movmem (rtx dstbase, rtx srcbase, rtx count_exp, rtx align_exp)
1187 unsigned HOST_WIDE_INT count = 0, offset, si_moves, i;
1188 HOST_WIDE_INT align = 0;
1190 rtx src, dst;
1191 rtx tmp_reg;
1193 if (GET_CODE (align_exp) == CONST_INT)
1194 { /* Only if aligned */
1195 align = INTVAL (align_exp);
1196 if (align & 3) return 0;
1199 if (GET_CODE (count_exp) == CONST_INT)
1200 { /* No more than 16 SImode moves */
1201 count = INTVAL (count_exp);
1202 if (count > 64) return 0;
1205 tmp_reg = gen_reg_rtx(SImode);
1207 /* Create psrs for the src and dest pointers */
1208 dst = copy_to_mode_reg (Pmode, XEXP (dstbase, 0));
1209 if (dst != XEXP (dstbase, 0))
1210 dstbase = replace_equiv_address_nv (dstbase, dst);
1211 src = copy_to_mode_reg (Pmode, XEXP (srcbase, 0));
1212 if (src != XEXP (srcbase, 0))
1213 srcbase = replace_equiv_address_nv (srcbase, src);
1215 offset = 0;
1217 /* Emit SImode moves */
1218 si_moves = count >> 2;
1219 for (i = 0; i < si_moves; i++)
1220 crx_expand_movmem_single (src, srcbase, dst, dstbase, tmp_reg, &offset);
1222 /* Special cases */
1223 if (count & 3)
1225 offset = count - 4;
1226 crx_expand_movmem_single (src, srcbase, dst, dstbase, tmp_reg, &offset);
1229 gcc_assert (offset == count);
1231 return 1;
1235 crx_expand_compare (enum rtx_code code, enum machine_mode mode)
1237 rtx op0, op1, cc_reg, ret;
1239 op0 = crx_compare_op0;
1240 op1 = crx_compare_op1;
1242 /* Emit the compare that writes into CC_REGNUM) */
1243 cc_reg = gen_rtx_REG (CCmode, CC_REGNUM);
1244 ret = gen_rtx_COMPARE (CCmode, op0, op1);
1245 emit_insn (gen_rtx_SET (VOIDmode, cc_reg, ret));
1246 /* debug_rtx (get_last_insn ()); */
1248 /* Return the rtx for using the result in CC_REGNUM */
1249 return gen_rtx_fmt_ee (code, mode, cc_reg, const0_rtx);
1252 void
1253 crx_expand_branch (enum rtx_code code, rtx label)
1255 rtx tmp = crx_expand_compare (code, VOIDmode);
1256 tmp = gen_rtx_IF_THEN_ELSE (VOIDmode, tmp,
1257 gen_rtx_LABEL_REF (VOIDmode, label),
1258 pc_rtx);
1259 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx, tmp));
1260 /* debug_rtx (get_last_insn ()); */
1263 void
1264 crx_expand_scond (enum rtx_code code, rtx dest)
1266 rtx tmp = crx_expand_compare (code, GET_MODE (dest));
1267 emit_move_insn (dest, tmp);
1268 /* debug_rtx (get_last_insn ()); */
1271 static void
1272 mpushpop_str (char *stringbuffer, const char *mnemonic, char *mask)
1274 if(strlen(mask) > 2 || crx_interrupt_function_p ()) /* needs 2-word instr. */
1275 sprintf (stringbuffer, "\n\t%s\tsp, {%s}", mnemonic, mask);
1276 else /* single word instruction */
1277 sprintf (stringbuffer, "\n\t%s\t%s", mnemonic, mask);
1280 /* Called from crx.md. The return value depends on the parameter push_or_pop:
1281 * When push_or_pop is zero -> string for push instructions of prologue.
1282 * When push_or_pop is nonzero -> string for pop/popret/retx in epilogue.
1283 * Relies on the assumptions:
1284 * 1. RA is the last register to be saved.
1285 * 2. The maximal value of the counter is MAX_COUNT. */
1287 char *
1288 crx_prepare_push_pop_string (int push_or_pop)
1290 /* j is the number of registers being saved, takes care that there won't be
1291 * more than 8 in one push/pop instruction */
1293 /* For the register mask string */
1294 static char mask_str[50];
1296 /* i is the index of save_regs[], going from 0 until last_reg_to_save */
1297 int i = 0;
1299 int ra_in_bitmask = 0;
1301 char *return_str;
1303 /* For reversing on the push instructions if there are more than one. */
1304 char *temp_str;
1306 return_str = (char *) xmalloc (120);
1307 temp_str = (char *) xmalloc (120);
1309 /* Initialize */
1310 memset (return_str, 0, 3);
1312 while (i <= last_reg_to_save)
1314 /* Prepare mask for one instruction. */
1315 mask_str[0] = 0;
1317 if (i <= SP_REGNUM)
1318 { /* Add regs unit full or SP register reached */
1319 int j = 0;
1320 while (j < MAX_COUNT && i <= SP_REGNUM)
1322 if (save_regs[i])
1324 /* TODO to use ra_in_bitmask for detecting last pop is not
1325 * smart it prevents things like: popret r5 */
1326 if (i == RETURN_ADDRESS_REGNUM) ra_in_bitmask = 1;
1327 if (j > 0) strcat (mask_str, ", ");
1328 strcat (mask_str, reg_names[i]);
1329 ++j;
1331 ++i;
1334 else
1336 /* Handle hi/lo savings */
1337 while (i <= last_reg_to_save)
1339 if (save_regs[i])
1341 strcat (mask_str, "lo, hi");
1342 i = last_reg_to_save + 1;
1343 break;
1345 ++i;
1349 if (strlen(mask_str) == 0) continue;
1351 if (push_or_pop == 1)
1353 if (crx_interrupt_function_p ())
1354 mpushpop_str (temp_str, "popx", mask_str);
1355 else
1357 if (ra_in_bitmask)
1359 mpushpop_str (temp_str, "popret", mask_str);
1360 ra_in_bitmask = 0;
1362 else mpushpop_str (temp_str, "pop", mask_str);
1365 strcat (return_str, temp_str);
1367 else
1369 /* push - We need to reverse the order of the instructions if there
1370 * are more than one. (since the pop will not be reversed in the
1371 * epilogue */
1372 if (crx_interrupt_function_p ())
1373 mpushpop_str (temp_str, "pushx", mask_str);
1374 else
1375 mpushpop_str (temp_str, "push", mask_str);
1376 strcat (temp_str, return_str);
1377 strcpy (strcat (return_str, "\t"), temp_str);
1382 if (push_or_pop == 1)
1384 /* pop */
1385 if (crx_interrupt_function_p ())
1386 strcat (return_str, "\n\tretx\n");
1388 else if (!FUNC_IS_NORETURN_P (current_function_decl)
1389 && !save_regs[RETURN_ADDRESS_REGNUM])
1390 strcat (return_str, "\n\tjump\tra\n");
1393 /* Skip the newline and the tab in the start of return_str. */
1394 return_str += 2;
1395 return return_str;
1398 /* CompactRISC CRX Architecture stack layout:
1400 0 +---------------------
1405 +==================== Sp(x)=Ap(x+1)
1406 A | Args for functions
1407 | | called by X and Dynamically
1408 | | Dynamic allocations allocated and
1409 | | (alloca, variable deallocated
1410 Stack | length arrays).
1411 grows +-------------------- Fp(x)
1412 down| | Local variables of X
1413 ward| +--------------------
1414 | | Regs saved for X-1
1415 | +==================== Sp(x-1)=Ap(x)
1416 | Args for func X
1417 | pushed by X-1
1418 +-------------------- Fp(x-1)
1425 void
1426 crx_expand_prologue (void)
1428 crx_compute_frame ();
1429 crx_compute_save_regs ();
1431 /* If there is no need in push and adjustment to sp, return. */
1432 if (size_for_adjusting_sp + sum_regs == 0)
1433 return;
1435 if (last_reg_to_save != -1)
1436 /* If there are registers to push. */
1437 emit_insn (gen_push_for_prologue (GEN_INT (sum_regs)));
1439 if (size_for_adjusting_sp > 0)
1440 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1441 GEN_INT (-(size_for_adjusting_sp))));
1443 if (frame_pointer_needed)
1444 /* Initialize the frame pointer with the value of the stack pointer
1445 * pointing now to the locals. */
1446 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
1449 /* Generate insn that updates the stack for local variables and padding for
1450 * registers we save. - Generate the appropriate return insn. */
1452 void
1453 crx_expand_epilogue (void)
1455 rtx return_reg;
1457 /* Nonzero if we need to return and pop only RA. This will generate a
1458 * different insn. This differentiate is for the peepholes for call as last
1459 * statement in function. */
1460 int only_popret_RA = (save_regs[RETURN_ADDRESS_REGNUM]
1461 && (sum_regs == UNITS_PER_WORD));
1463 /* Return register. */
1464 return_reg = gen_rtx_REG (Pmode, RETURN_ADDRESS_REGNUM);
1466 if (frame_pointer_needed)
1467 /* Restore the stack pointer with the frame pointers value */
1468 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
1470 if (size_for_adjusting_sp > 0)
1471 emit_insn (gen_addsi3 (stack_pointer_rtx, stack_pointer_rtx,
1472 GEN_INT (size_for_adjusting_sp)));
1474 if (crx_interrupt_function_p ())
1475 emit_jump_insn (gen_interrupt_return ());
1476 else if (last_reg_to_save == -1)
1477 /* Nothing to pop */
1478 /* Don't output jump for interrupt routine, only retx. */
1479 emit_jump_insn (gen_indirect_jump_return ());
1480 else if (only_popret_RA)
1481 emit_jump_insn (gen_popret_RA_return ());
1482 else
1483 emit_jump_insn (gen_pop_and_popret_return (GEN_INT (sum_regs)));