1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by Axis Communications. Written by Hans-Peter Nilsson.
6 This file is part of GCC.
8 GCC 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)
13 GCC 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.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
25 #include "coretypes.h"
29 #include "hard-reg-set.h"
31 #include "insn-config.h"
32 #include "conditions.h"
33 #include "insn-attr.h"
46 #include "target-def.h"
50 /* Usable when we have an amount to add or subtract, and want the
51 optimal size of the insn. */
52 #define ADDITIVE_SIZE_MODIFIER(size) \
53 ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
55 #define ASSERT_PLT_UNSPEC(x) \
56 CRIS_ASSERT (XINT (x, 1) == CRIS_UNSPEC_PLT \
57 && ((GET_CODE (XVECEXP (x, 0, 0)) == SYMBOL_REF) \
58 || GET_CODE (XVECEXP (x, 0, 0)) == LABEL_REF))
60 #define LOSE_AND_RETURN(msgid, x) \
63 cris_operand_lossage (msgid, x); \
67 enum cris_retinsn_type
68 { CRIS_RETINSN_UNKNOWN = 0, CRIS_RETINSN_RET, CRIS_RETINSN_JUMP };
70 /* Per-function machine data. */
71 struct machine_function GTY(())
73 int needs_return_address_on_stack;
75 /* This is the number of registers we save in the prologue due to
79 enum cris_retinsn_type return_type;
82 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
84 static char cris_output_insn_is_bound = 0;
86 /* In code for output macros, this is how we know whether e.g. constant
87 goes in code or in a static initializer. */
88 static int in_code = 0;
90 /* Fix for reg_overlap_mentioned_p. */
91 static int cris_reg_overlap_mentioned_p (rtx, rtx);
93 static void cris_print_base (rtx, FILE *);
95 static void cris_print_index (rtx, FILE *);
97 static void cris_output_addr_const (FILE *, rtx);
99 static struct machine_function * cris_init_machine_status (void);
101 static rtx cris_struct_value_rtx (tree, int);
103 static void cris_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode,
104 tree type, int *, int);
106 static int cris_initial_frame_pointer_offset (void);
108 static int saved_regs_mentioned (rtx);
110 static void cris_operand_lossage (const char *, rtx);
112 static int cris_reg_saved_in_regsave_area (unsigned int, bool);
114 static void cris_asm_output_mi_thunk
115 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
117 static void cris_file_start (void);
118 static void cris_init_libfuncs (void);
120 static bool cris_rtx_costs (rtx, int, int, int *);
121 static int cris_address_cost (rtx);
122 static bool cris_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
124 static int cris_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
126 static tree cris_md_asm_clobbers (tree, tree, tree);
128 static bool cris_handle_option (size_t, const char *, int);
130 /* This is the parsed result of the "-max-stack-stackframe=" option. If
131 it (still) is zero, then there was no such option given. */
132 int cris_max_stackframe = 0;
134 /* This is the parsed result of the "-march=" option, if given. */
135 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
137 #undef TARGET_ASM_ALIGNED_HI_OP
138 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
139 #undef TARGET_ASM_ALIGNED_SI_OP
140 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
141 #undef TARGET_ASM_ALIGNED_DI_OP
142 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
144 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
145 available in ELF. These "normal" pseudos do not have any alignment
146 constraints or side-effects. */
147 #undef TARGET_ASM_UNALIGNED_HI_OP
148 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
150 #undef TARGET_ASM_UNALIGNED_SI_OP
151 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
153 #undef TARGET_ASM_UNALIGNED_DI_OP
154 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
156 #undef TARGET_ASM_OUTPUT_MI_THUNK
157 #define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk
158 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
159 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
161 #undef TARGET_ASM_FILE_START
162 #define TARGET_ASM_FILE_START cris_file_start
164 #undef TARGET_INIT_LIBFUNCS
165 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
167 #undef TARGET_RTX_COSTS
168 #define TARGET_RTX_COSTS cris_rtx_costs
169 #undef TARGET_ADDRESS_COST
170 #define TARGET_ADDRESS_COST cris_address_cost
172 #undef TARGET_PROMOTE_FUNCTION_ARGS
173 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_true
174 #undef TARGET_STRUCT_VALUE_RTX
175 #define TARGET_STRUCT_VALUE_RTX cris_struct_value_rtx
176 #undef TARGET_SETUP_INCOMING_VARARGS
177 #define TARGET_SETUP_INCOMING_VARARGS cris_setup_incoming_varargs
178 #undef TARGET_PASS_BY_REFERENCE
179 #define TARGET_PASS_BY_REFERENCE cris_pass_by_reference
180 #undef TARGET_ARG_PARTIAL_BYTES
181 #define TARGET_ARG_PARTIAL_BYTES cris_arg_partial_bytes
182 #undef TARGET_MD_ASM_CLOBBERS
183 #define TARGET_MD_ASM_CLOBBERS cris_md_asm_clobbers
184 #undef TARGET_DEFAULT_TARGET_FLAGS
185 #define TARGET_DEFAULT_TARGET_FLAGS (TARGET_DEFAULT | CRIS_SUBTARGET_DEFAULT)
186 #undef TARGET_HANDLE_OPTION
187 #define TARGET_HANDLE_OPTION cris_handle_option
189 struct gcc_target targetm = TARGET_INITIALIZER;
191 /* Helper for cris_load_multiple_op and cris_ret_movem_op. */
194 cris_movem_load_rest_p (rtx op, int offs)
196 unsigned int reg_count = XVECLEN (op, 0) - offs;
202 unsigned int regno = 0;
204 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
205 other than (MEM reg). */
207 || GET_CODE (XVECEXP (op, 0, offs)) != SET
208 || GET_CODE (SET_DEST (XVECEXP (op, 0, offs))) != REG
209 || GET_CODE (SET_SRC (XVECEXP (op, 0, offs))) != MEM)
212 /* Check a possible post-inc indicator. */
213 if (GET_CODE (SET_SRC (XVECEXP (op, 0, offs + 1))) == PLUS)
215 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 0);
216 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, offs + 1)), 1);
222 || !REG_P (SET_DEST (XVECEXP (op, 0, offs + 1)))
223 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, offs + 1)))
224 || GET_CODE (inc) != CONST_INT
225 || INTVAL (inc) != (HOST_WIDE_INT) reg_count * 4)
232 /* FIXME: These two only for pre-v32. */
234 regno = reg_count - 1;
236 elt = XVECEXP (op, 0, offs);
237 src_addr = XEXP (SET_SRC (elt), 0);
239 if (GET_CODE (elt) != SET
240 || GET_CODE (SET_DEST (elt)) != REG
241 || GET_MODE (SET_DEST (elt)) != SImode
242 || REGNO (SET_DEST (elt)) != regno
243 || GET_CODE (SET_SRC (elt)) != MEM
244 || GET_MODE (SET_SRC (elt)) != SImode
245 || !memory_address_p (SImode, src_addr))
248 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
250 rtx elt = XVECEXP (op, 0, i);
253 if (GET_CODE (elt) != SET
254 || GET_CODE (SET_DEST (elt)) != REG
255 || GET_MODE (SET_DEST (elt)) != SImode
256 || REGNO (SET_DEST (elt)) != regno
257 || GET_CODE (SET_SRC (elt)) != MEM
258 || GET_MODE (SET_SRC (elt)) != SImode
259 || GET_CODE (XEXP (SET_SRC (elt), 0)) != PLUS
260 || ! rtx_equal_p (XEXP (XEXP (SET_SRC (elt), 0), 0), src_addr)
261 || GET_CODE (XEXP (XEXP (SET_SRC (elt), 0), 1)) != CONST_INT
262 || INTVAL (XEXP (XEXP (SET_SRC (elt), 0), 1)) != setno * 4)
269 /* Worker function for predicate for the parallel contents in a movem
273 cris_store_multiple_op_p (rtx op)
275 int reg_count = XVECLEN (op, 0);
286 /* Perform a quick check so we don't blow up below. FIXME: Adjust for
287 other than (MEM reg) and (MEM (PLUS reg const)). */
291 elt = XVECEXP (op, 0, 0);
293 if (GET_CODE (elt) != SET)
296 dest = SET_DEST (elt);
298 if (GET_CODE (SET_SRC (elt)) != REG
299 || GET_CODE (dest) != MEM)
302 dest_addr = XEXP (dest, 0);
304 /* Check a possible post-inc indicator. */
305 if (GET_CODE (SET_SRC (XVECEXP (op, 0, 1))) == PLUS)
307 rtx reg = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 0);
308 rtx inc = XEXP (SET_SRC (XVECEXP (op, 0, 1)), 1);
314 || !REG_P (SET_DEST (XVECEXP (op, 0, 1)))
315 || REGNO (reg) != REGNO (SET_DEST (XVECEXP (op, 0, 1)))
316 || GET_CODE (inc) != CONST_INT
317 /* Support increment by number of registers, and by the offset
318 of the destination, if it has the form (MEM (PLUS reg
320 || !((REG_P (dest_addr)
321 && REGNO (dest_addr) == REGNO (reg)
322 && INTVAL (inc) == (HOST_WIDE_INT) reg_count * 4)
323 || (GET_CODE (dest_addr) == PLUS
324 && REG_P (XEXP (dest_addr, 0))
325 && REGNO (XEXP (dest_addr, 0)) == REGNO (reg)
326 && GET_CODE (XEXP (dest_addr, 1)) == CONST_INT
327 && INTVAL (XEXP (dest_addr, 1)) == INTVAL (inc))))
335 /* FIXME: These two only for pre-v32. */
337 regno = reg_count - 1;
339 if (GET_CODE (elt) != SET
340 || GET_CODE (SET_SRC (elt)) != REG
341 || GET_MODE (SET_SRC (elt)) != SImode
342 || REGNO (SET_SRC (elt)) != (unsigned int) regno
343 || GET_CODE (SET_DEST (elt)) != MEM
344 || GET_MODE (SET_DEST (elt)) != SImode)
347 if (REG_P (dest_addr))
349 dest_base = dest_addr;
352 else if (GET_CODE (dest_addr) == PLUS
353 && REG_P (XEXP (dest_addr, 0))
354 && GET_CODE (XEXP (dest_addr, 1)) == CONST_INT)
356 dest_base = XEXP (dest_addr, 0);
357 offset = INTVAL (XEXP (dest_addr, 1));
362 for (setno = 1; i < XVECLEN (op, 0); setno++, i++)
364 rtx elt = XVECEXP (op, 0, i);
367 if (GET_CODE (elt) != SET
368 || GET_CODE (SET_SRC (elt)) != REG
369 || GET_MODE (SET_SRC (elt)) != SImode
370 || REGNO (SET_SRC (elt)) != (unsigned int) regno
371 || GET_CODE (SET_DEST (elt)) != MEM
372 || GET_MODE (SET_DEST (elt)) != SImode
373 || GET_CODE (XEXP (SET_DEST (elt), 0)) != PLUS
374 || ! rtx_equal_p (XEXP (XEXP (SET_DEST (elt), 0), 0), dest_base)
375 || GET_CODE (XEXP (XEXP (SET_DEST (elt), 0), 1)) != CONST_INT
376 || INTVAL (XEXP (XEXP (SET_DEST (elt), 0), 1)) != setno * 4 + offset)
383 /* The CONDITIONAL_REGISTER_USAGE worker. */
386 cris_conditional_register_usage (void)
388 /* FIXME: This isn't nice. We should be able to use that register for
389 something else if the PIC table isn't needed. */
391 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
392 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
394 if (TARGET_HAS_MUL_INSNS)
395 fixed_regs[CRIS_MOF_REGNUM] = 0;
397 /* On early versions, we must use the 16-bit condition-code register,
398 which has another name. */
399 if (cris_cpu_version < 8)
400 reg_names[CRIS_CC0_REGNUM] = "ccr";
403 /* Return current_function_uses_pic_offset_table. For use in cris.md,
404 since some generated files do not include function.h. */
407 cris_cfun_uses_pic_table (void)
409 return current_function_uses_pic_offset_table;
412 /* Given an rtx, return the text string corresponding to the CODE of X.
413 Intended for use in the assembly language output section of a
419 cris_output_insn_is_bound = 0;
420 switch (GET_CODE (x))
431 /* This function is for retrieving a part of an instruction name for
432 an operator, for immediate output. If that ever happens for
433 MULT, we need to apply TARGET_MUL_BUG in the caller. Make sure
435 internal_error ("MULT case in cris_op_str");
471 /* Used to control the sign/zero-extend character for the 'e' modifier.
473 cris_output_insn_is_bound = 1;
478 return "Unknown operator";
483 /* Emit an error message when we're in an asm, and a fatal error for
484 "normal" insns. Formatted output isn't easily implemented, since we
485 use output_operand_lossage to output the actual message and handle the
486 categorization of the error. */
489 cris_operand_lossage (const char *msgid, rtx op)
492 output_operand_lossage ("%s", msgid);
495 /* Print an index part of an address to file. */
498 cris_print_index (rtx index, FILE *file)
500 rtx inner = XEXP (index, 0);
502 /* Make the index "additive" unless we'll output a negative number, in
503 which case the sign character is free (as in free beer). */
504 if (GET_CODE (index) != CONST_INT || INTVAL (index) >= 0)
508 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
509 else if (CONSTANT_P (index))
510 cris_output_addr_const (file, index);
511 else if (GET_CODE (index) == MULT)
513 fprintf (file, "$%s.",
514 reg_names[REGNO (XEXP (index, 0))]);
516 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
518 else if (GET_CODE (index) == SIGN_EXTEND &&
519 GET_CODE (inner) == MEM)
521 rtx inner_inner = XEXP (inner, 0);
523 if (GET_CODE (inner_inner) == POST_INC)
525 fprintf (file, "[$%s+].",
526 reg_names[REGNO (XEXP (inner_inner, 0))]);
527 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
531 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
533 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
536 else if (GET_CODE (index) == MEM)
538 if (GET_CODE (inner) == POST_INC)
539 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
541 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
544 cris_operand_lossage ("unexpected index-type in cris_print_index",
548 /* Print a base rtx of an address to file. */
551 cris_print_base (rtx base, FILE *file)
554 fprintf (file, "$%s", reg_names[REGNO (base)]);
555 else if (GET_CODE (base) == POST_INC)
556 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
558 cris_operand_lossage ("unexpected base-type in cris_print_base",
562 /* Usable as a guard in expressions. */
565 cris_fatal (char *arg)
567 internal_error (arg);
569 /* We'll never get here; this is just to appease compilers. */
573 /* Return nonzero if REGNO is an ordinary register that *needs* to be
574 saved together with other registers, possibly by a MOVEM instruction,
575 or is saved for target-independent reasons. There may be
576 target-dependent reasons to save the register anyway; this is just a
577 wrapper for a complicated conditional. */
580 cris_reg_saved_in_regsave_area (unsigned int regno, bool got_really_used)
583 (((regs_ever_live[regno]
584 && !call_used_regs[regno])
585 || (regno == PIC_OFFSET_TABLE_REGNUM
587 /* It is saved anyway, if there would be a gap. */
589 && regs_ever_live[regno + 1]
590 && !call_used_regs[regno + 1]))))
591 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
592 && regno != CRIS_SRP_REGNUM)
593 || (current_function_calls_eh_return
594 && (regno == EH_RETURN_DATA_REGNO (0)
595 || regno == EH_RETURN_DATA_REGNO (1)
596 || regno == EH_RETURN_DATA_REGNO (2)
597 || regno == EH_RETURN_DATA_REGNO (3)));
600 /* Return nonzero if there are regs mentioned in the insn that are not all
601 in the call_used regs. This is part of the decision whether an insn
602 can be put in the epilogue. */
605 saved_regs_mentioned (rtx x)
611 /* Mainly stolen from refers_to_regno_p in rtlanal.c. */
619 return !call_used_regs[i];
622 /* If this is a SUBREG of a hard reg, we can see exactly which
623 registers are being modified. Otherwise, handle normally. */
624 i = REGNO (SUBREG_REG (x));
625 return !call_used_regs[i];
631 fmt = GET_RTX_FORMAT (code);
632 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
636 if (saved_regs_mentioned (XEXP (x, i)))
639 else if (fmt[i] == 'E')
642 for (j = XVECLEN (x, i) - 1; j >=0; j--)
643 if (saved_regs_mentioned (XEXP (x, i)))
651 /* The PRINT_OPERAND worker. */
654 cris_print_operand (FILE *file, rtx x, int code)
658 /* Size-strings corresponding to MULT expressions. */
659 static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
661 /* New code entries should just be added to the switch below. If
662 handling is finished, just return. If handling was just a
663 modification of the operand, the modified operand should be put in
664 "operand", and then do a break to let default handling
665 (zero-modifier) output the operand. */
670 /* Print the unsigned supplied integer as if it were signed
671 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
672 if (GET_CODE (x) != CONST_INT
673 || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
674 LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
675 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
676 INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
680 /* Print assembler code for operator. */
681 fprintf (file, "%s", cris_op_str (operand));
686 /* A movem modifier working on a parallel; output the register
690 if (GET_CODE (x) != PARALLEL)
691 LOSE_AND_RETURN ("invalid operand for 'o' modifier", x);
693 /* The second item can be (set reg (plus reg const)) to denote a
696 = (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS
698 : XVECLEN (x, 0) - 1);
700 fprintf (file, "$%s", reg_names [regno]);
706 /* A similar movem modifier; output the memory operand. */
709 if (GET_CODE (x) != PARALLEL)
710 LOSE_AND_RETURN ("invalid operand for 'O' modifier", x);
712 /* The lowest mem operand is in the first item, but perhaps it
713 needs to be output as postincremented. */
714 addr = GET_CODE (SET_SRC (XVECEXP (x, 0, 0))) == MEM
715 ? XEXP (SET_SRC (XVECEXP (x, 0, 0)), 0)
716 : XEXP (SET_DEST (XVECEXP (x, 0, 0)), 0);
718 /* The second item can be a (set reg (plus reg const)) to denote
720 if (GET_CODE (SET_SRC (XVECEXP (x, 0, 1))) == PLUS)
722 /* It's a post-increment, if the address is a naked (reg). */
724 addr = gen_rtx_POST_INC (SImode, addr);
727 /* Otherwise, it's a side-effect; RN=RN+M. */
728 fprintf (file, "[$%s=$%s%s%d]",
729 reg_names [REGNO (SET_DEST (XVECEXP (x, 0, 1)))],
730 reg_names [REGNO (XEXP (addr, 0))],
731 INTVAL (XEXP (addr, 1)) < 0 ? "" : "+",
732 (int) INTVAL (XEXP (addr, 1)));
736 output_address (addr);
741 /* Adjust a power of two to its log2. */
742 if (GET_CODE (x) != CONST_INT || exact_log2 (INTVAL (x)) < 0 )
743 LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
744 fprintf (file, "%d", exact_log2 (INTVAL (x)));
748 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
749 respectively. This modifier also terminates the inhibiting
750 effects of the 'x' modifier. */
751 cris_output_insn_is_bound = 0;
752 if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
756 if (INTVAL (x) <= 255)
758 else if (INTVAL (x) <= 65535)
768 /* For a non-integer, print the size of the operand. */
769 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
770 ? 'd' : GET_MODE (x) == HImode ? 'w'
771 : GET_MODE (x) == QImode ? 'b'
772 /* If none of the above, emit an erroneous size letter. */
778 /* Const_int: print b for -127 <= x <= 255,
779 w for -32768 <= x <= 65535, else die. */
780 if (GET_CODE (x) != CONST_INT
781 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
782 LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
783 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
787 /* Output a 'nop' if there's nothing for the delay slot.
788 This method stolen from the sparc files. */
789 if (dbr_sequence_length () == 0)
790 fputs ("\n\tnop", file);
794 /* Output directive for alignment padded with "nop" insns.
795 Optimizing for size, it's plain 4-byte alignment, otherwise we
796 align the section to a cache-line (32 bytes) and skip at max 2
797 bytes, i.e. we skip if it's the last insn on a cache-line. The
798 latter is faster by a small amount (for two test-programs 99.6%
799 and 99.9%) and larger by a small amount (ditto 100.1% and
800 100.2%). This is supposed to be the simplest yet performance-
801 wise least intrusive way to make sure the immediately following
802 (supposed) muls/mulu insn isn't located at the end of a
806 ? ".p2alignw 2,0x050f\n\t"
807 : ".p2alignw 5,0x050f,2\n\t", file);
811 /* The PIC register. */
813 internal_error ("invalid use of ':' modifier");
814 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
818 /* Print high (most significant) part of something. */
819 switch (GET_CODE (operand))
822 /* If we're having 64-bit HOST_WIDE_INTs, the whole (DImode)
823 value is kept here, and so may be other than 0 or -1. */
824 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
825 INTVAL (operand_subword (operand, 1, 0, DImode)));
829 /* High part of a long long constant. */
830 if (GET_MODE (operand) == VOIDmode)
832 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x));
836 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
839 /* Print reg + 1. Check that there's not an attempt to print
840 high-parts of registers like stack-pointer or higher. */
841 if (REGNO (operand) > STACK_POINTER_REGNUM - 2)
842 LOSE_AND_RETURN ("bad register", operand);
843 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
847 /* Adjust memory address to high part. */
849 rtx adj_mem = operand;
851 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
853 /* Adjust so we can use two SImode in DImode.
854 Calling adj_offsettable_operand will make sure it is an
855 offsettable address. Don't do this for a postincrement
856 though; it should remain as it was. */
857 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
859 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
861 output_address (XEXP (adj_mem, 0));
866 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
870 /* Strip the MEM expression. */
871 operand = XEXP (operand, 0);
875 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
876 cris_output_insn_is_bound is nonzero. */
877 if (GET_CODE (operand) != SIGN_EXTEND
878 && GET_CODE (operand) != ZERO_EXTEND
879 && GET_CODE (operand) != CONST_INT)
880 LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
882 if (cris_output_insn_is_bound)
884 cris_output_insn_is_bound = 0;
888 putc (GET_CODE (operand) == SIGN_EXTEND
889 || (GET_CODE (operand) == CONST_INT && INTVAL (operand) < 0)
894 /* Print the size letter of the inner element. We can do it by
895 calling ourselves with the 's' modifier. */
896 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
897 LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
898 cris_print_operand (file, XEXP (operand, 0), 's');
902 /* Print the least significant part of operand. */
903 if (GET_CODE (operand) == CONST_DOUBLE)
905 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
908 else if (HOST_BITS_PER_WIDE_INT > 32 && GET_CODE (operand) == CONST_INT)
910 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
911 INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
914 /* Otherwise the least significant part equals the normal part,
915 so handle it normally. */
919 /* When emitting an add for the high part of a DImode constant, we
920 want to use addq for 0 and adds.w for -1. */
921 if (GET_CODE (operand) != CONST_INT)
922 LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
923 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
927 /* If this is a GOT symbol, force it to be emitted as :GOT and
928 :GOTPLT regardless of -fpic (i.e. not as :GOT16, :GOTPLT16).
929 Avoid making this too much of a special case. */
930 if (flag_pic == 1 && CONSTANT_P (operand))
932 int flag_pic_save = flag_pic;
935 cris_output_addr_const (file, operand);
936 flag_pic = flag_pic_save;
942 /* When emitting an sub for the high part of a DImode constant, we
943 want to use subq for 0 and subs.w for -1. */
944 if (GET_CODE (operand) != CONST_INT)
945 LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
946 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
950 /* Print the operand as the index-part of an address.
951 Easiest way out is to use cris_print_index. */
952 cris_print_index (operand, file);
956 /* Print the size letter for an operand to a MULT, which must be a
957 const_int with a suitable value. */
958 if (GET_CODE (operand) != CONST_INT || INTVAL (operand) > 4)
959 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
960 fprintf (file, "%s", mults[INTVAL (operand)]);
964 /* No code, print as usual. */
968 LOSE_AND_RETURN ("invalid operand modifier letter", x);
971 /* Print an operand as without a modifier letter. */
972 switch (GET_CODE (operand))
975 if (REGNO (operand) > 15
976 && REGNO (operand) != CRIS_MOF_REGNUM
977 && REGNO (operand) != CRIS_SRP_REGNUM
978 && REGNO (operand) != CRIS_CC0_REGNUM)
979 internal_error ("internal error: bad register: %d", REGNO (operand));
980 fprintf (file, "$%s", reg_names[REGNO (operand)]);
984 output_address (XEXP (operand, 0));
988 if (GET_MODE (operand) == VOIDmode)
989 /* A long long constant. */
990 output_addr_const (file, operand);
993 /* Only single precision is allowed as plain operands the
994 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
999 /* FIXME: Perhaps check overflow of the "single". */
1000 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1001 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1003 fprintf (file, "0x%lx", l);
1010 cris_output_addr_const (file, operand);
1016 /* For a (MULT (reg X) const_int) we output "rX.S". */
1017 int i = GET_CODE (XEXP (operand, 1)) == CONST_INT
1018 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1019 rtx reg = GET_CODE (XEXP (operand, 1)) == CONST_INT
1020 ? XEXP (operand, 0) : XEXP (operand, 1);
1022 if (GET_CODE (reg) != REG
1023 || (GET_CODE (XEXP (operand, 0)) != CONST_INT
1024 && GET_CODE (XEXP (operand, 1)) != CONST_INT))
1025 LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1027 cris_print_base (reg, file);
1028 fprintf (file, ".%c",
1029 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1031 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1037 /* No need to handle all strange variants, let output_addr_const
1039 if (CONSTANT_P (operand))
1041 cris_output_addr_const (file, operand);
1045 LOSE_AND_RETURN ("unexpected operand", x);
1049 /* The PRINT_OPERAND_ADDRESS worker. */
1052 cris_print_operand_address (FILE *file, rtx x)
1054 /* All these were inside MEM:s so output indirection characters. */
1057 if (CONSTANT_ADDRESS_P (x))
1058 cris_output_addr_const (file, x);
1059 else if (BASE_OR_AUTOINCR_P (x))
1060 cris_print_base (x, file);
1061 else if (GET_CODE (x) == PLUS)
1069 cris_print_base (x1, file);
1070 cris_print_index (x2, file);
1072 else if (BASE_P (x2))
1074 cris_print_base (x2, file);
1075 cris_print_index (x1, file);
1078 LOSE_AND_RETURN ("unrecognized address", x);
1080 else if (GET_CODE (x) == MEM)
1082 /* A DIP. Output more indirection characters. */
1084 cris_print_base (XEXP (x, 0), file);
1088 LOSE_AND_RETURN ("unrecognized address", x);
1093 /* The RETURN_ADDR_RTX worker.
1094 We mark that the return address is used, either by EH or
1095 __builtin_return_address, for use by the function prologue and
1096 epilogue. FIXME: This isn't optimal; we just use the mark in the
1097 prologue and epilogue to say that the return address is to be stored
1098 in the stack frame. We could return SRP for leaf-functions and use the
1099 initial-value machinery. */
1102 cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED)
1104 cfun->machine->needs_return_address_on_stack = 1;
1106 /* The return-address is stored just above the saved frame-pointer (if
1107 present). Apparently we can't eliminate from the frame-pointer in
1108 that direction, so use the incoming args (maybe pretended) pointer. */
1110 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1114 /* Accessor used in cris.md:return because cfun->machine isn't available
1118 cris_return_address_on_stack (void)
1120 return regs_ever_live[CRIS_SRP_REGNUM]
1121 || cfun->machine->needs_return_address_on_stack;
1124 /* Accessor used in cris.md:return because cfun->machine isn't available
1128 cris_return_address_on_stack_for_return (void)
1130 return cfun->machine->return_type == CRIS_RETINSN_RET ? false
1131 : cris_return_address_on_stack ();
1134 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1135 handles FP -> SP elimination offset. */
1138 cris_initial_frame_pointer_offset (void)
1142 /* Initial offset is 0 if we don't have a frame pointer. */
1144 bool got_really_used = false;
1146 if (current_function_uses_pic_offset_table)
1148 push_topmost_sequence ();
1150 = reg_used_between_p (pic_offset_table_rtx, get_insns (),
1152 pop_topmost_sequence ();
1155 /* And 4 for each register pushed. */
1156 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1157 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1160 /* And then, last, we add the locals allocated. */
1161 offs += get_frame_size ();
1163 /* And more; the accumulated args size. */
1164 offs += current_function_outgoing_args_size;
1166 /* Then round it off, in case we use aligned stack. */
1167 if (TARGET_STACK_ALIGN)
1168 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1173 /* The INITIAL_ELIMINATION_OFFSET worker.
1174 Calculate the difference between imaginary registers such as frame
1175 pointer and the stack pointer. Used to eliminate the frame pointer
1176 and imaginary arg pointer. */
1179 cris_initial_elimination_offset (int fromreg, int toreg)
1182 = cris_initial_frame_pointer_offset ();
1184 /* We should be able to use regs_ever_live and related prologue
1185 information here, or alpha should not as well. */
1186 bool return_address_on_stack = cris_return_address_on_stack ();
1188 /* Here we act as if the frame-pointer were needed. */
1189 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1191 if (fromreg == ARG_POINTER_REGNUM
1192 && toreg == FRAME_POINTER_REGNUM)
1193 return ap_fp_offset;
1195 /* Between the frame pointer and the stack are only "normal" stack
1196 variables and saved registers. */
1197 if (fromreg == FRAME_POINTER_REGNUM
1198 && toreg == STACK_POINTER_REGNUM)
1199 return fp_sp_offset;
1201 /* We need to balance out the frame pointer here. */
1202 if (fromreg == ARG_POINTER_REGNUM
1203 && toreg == STACK_POINTER_REGNUM)
1204 return ap_fp_offset + fp_sp_offset - 4;
1209 /* Worker function for LEGITIMIZE_RELOAD_ADDRESS. */
1212 cris_reload_address_legitimized (rtx x,
1213 enum machine_mode mode ATTRIBUTE_UNUSED,
1214 int opnum ATTRIBUTE_UNUSED,
1216 int ind_levels ATTRIBUTE_UNUSED)
1218 enum reload_type type = itype;
1223 if (GET_CODE (x) != PLUS)
1227 op0p = &XEXP (x, 0);
1229 op1p = &XEXP (x, 1);
1234 if (GET_CODE (op0) == SIGN_EXTEND
1235 && GET_CODE (XEXP (op0, 0)) == MEM)
1237 rtx op00 = XEXP (op0, 0);
1238 rtx op000 = XEXP (op00, 0);
1239 rtx *op000p = &XEXP (op00, 0);
1241 if ((GET_MODE (op00) == HImode || GET_MODE (op00) == QImode)
1243 || (GET_CODE (op000) == POST_INC && REG_P (XEXP (op000, 0)))))
1245 bool something_reloaded = false;
1247 if (GET_CODE (op000) == POST_INC
1248 && REG_P (XEXP (op000, 0))
1249 && REGNO (XEXP (op000, 0)) > CRIS_LAST_GENERAL_REGISTER)
1250 /* No, this gets too complicated and is too rare to care
1251 about trying to improve on the general code Here.
1252 As the return-value is an all-or-nothing indicator, we
1253 punt on the other register too. */
1257 && REGNO (op000) > CRIS_LAST_GENERAL_REGISTER))
1259 /* The address of the inner mem is a pseudo or wrong
1260 reg: reload that. */
1261 push_reload (op000, NULL_RTX, op000p, NULL, GENERAL_REGS,
1262 GET_MODE (x), VOIDmode, 0, 0, opnum, type);
1263 something_reloaded = true;
1266 if (REGNO (op1) > CRIS_LAST_GENERAL_REGISTER)
1268 /* Base register is a pseudo or wrong reg: reload it. */
1269 push_reload (op1, NULL_RTX, op1p, NULL, GENERAL_REGS,
1270 GET_MODE (x), VOIDmode, 0, 0,
1272 something_reloaded = true;
1275 gcc_assert (something_reloaded);
1284 /* This function looks into the pattern to see how this insn affects
1287 Used when to eliminate test insns before a condition-code user,
1288 such as a "scc" insn or a conditional branch. This includes
1289 checking if the entities that cc was updated by, are changed by the
1292 Currently a jumble of the old peek-inside-the-insn and the newer
1293 check-cc-attribute methods. */
1296 cris_notice_update_cc (rtx exp, rtx insn)
1298 /* Check if user specified "-mcc-init" as a bug-workaround. FIXME:
1299 TARGET_CCINIT does not work; we must set CC_REVERSED as below.
1300 Several testcases will otherwise fail, for example
1301 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1308 /* Slowly, we're converting to using attributes to control the setting
1309 of condition-code status. */
1310 switch (get_attr_cc (insn))
1313 /* Even if it is "none", a setting may clobber a previous
1314 cc-value, so check. */
1315 if (GET_CODE (exp) == SET)
1317 if (cc_status.value1
1318 && modified_in_p (cc_status.value1, insn))
1319 cc_status.value1 = 0;
1321 if (cc_status.value2
1322 && modified_in_p (cc_status.value2, insn))
1323 cc_status.value2 = 0;
1332 /* Which means, for:
1337 CC is (reg) and (...) - unless (...) is 0, then CC does not change.
1338 CC_NO_OVERFLOW unless (...) is reg or mem.
1347 (set (reg1) (mem (bdap/biap)))
1348 (set (reg2) (bdap/biap))):
1349 CC is (reg1) and (mem (reg2))
1352 (set (mem (bdap/biap)) (reg1)) [or 0]
1353 (set (reg2) (bdap/biap))):
1356 (where reg and mem includes strict_low_parts variants thereof)
1358 For all others, assume CC is clobbered.
1359 Note that we do not have to care about setting CC_NO_OVERFLOW,
1360 since the overflow flag is set to 0 (i.e. right) for
1361 instructions where it does not have any sane sense, but where
1362 other flags have meanings. (This includes shifts; the carry is
1365 Note that there are other parallel constructs we could match,
1366 but we don't do that yet. */
1368 if (GET_CODE (exp) == SET)
1370 /* FIXME: Check when this happens. It looks like we should
1371 actually do a CC_STATUS_INIT here to be safe. */
1372 if (SET_DEST (exp) == pc_rtx)
1375 /* Record CC0 changes, so we do not have to output multiple
1377 if (SET_DEST (exp) == cc0_rtx)
1379 cc_status.value1 = SET_SRC (exp);
1380 cc_status.value2 = 0;
1382 /* Handle flags for the special btstq on one bit. */
1383 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1384 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1386 if (GET_CODE (XEXP (SET_SRC (exp), 0)) == CONST_INT)
1388 cc_status.flags = CC_INVERTED;
1390 /* A one-bit btstq. */
1391 cc_status.flags = CC_Z_IN_NOT_N;
1394 cc_status.flags = 0;
1396 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1398 if (!REG_P (XEXP (SET_SRC (exp), 0))
1399 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1400 /* For some reason gcc will not canonicalize compare
1401 operations, reversing the sign by itself if
1402 operands are in wrong order. */
1403 /* (But NOT inverted; eq is still eq.) */
1404 cc_status.flags = CC_REVERSED;
1406 /* This seems to be overlooked by gcc. FIXME: Check again.
1407 FIXME: Is it really safe? */
1409 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1410 XEXP (SET_SRC (exp), 0),
1411 XEXP (SET_SRC (exp), 1));
1415 else if (REG_P (SET_DEST (exp))
1416 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1417 && REG_P (XEXP (SET_DEST (exp), 0))))
1419 /* A register is set; normally CC is set to show that no
1420 test insn is needed. Catch the exceptions. */
1422 /* If not to cc0, then no "set"s in non-natural mode give
1424 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1425 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1427 /* ... except add:s and sub:s in DImode. */
1428 if (GET_MODE (SET_DEST (exp)) == DImode
1429 && (GET_CODE (SET_SRC (exp)) == PLUS
1430 || GET_CODE (SET_SRC (exp)) == MINUS))
1432 cc_status.flags = 0;
1433 cc_status.value1 = SET_DEST (exp);
1434 cc_status.value2 = SET_SRC (exp);
1436 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1438 cc_status.value2 = 0;
1440 /* Add and sub may set V, which gets us
1441 unoptimizable results in "gt" and "le" condition
1443 cc_status.flags |= CC_NO_OVERFLOW;
1448 else if (SET_SRC (exp) == const0_rtx)
1450 /* There's no CC0 change when clearing a register or
1451 memory. Just check for overlap. */
1452 if (cc_status.value1
1453 && modified_in_p (cc_status.value1, insn))
1454 cc_status.value1 = 0;
1456 if (cc_status.value2
1457 && modified_in_p (cc_status.value2, insn))
1458 cc_status.value2 = 0;
1464 cc_status.flags = 0;
1465 cc_status.value1 = SET_DEST (exp);
1466 cc_status.value2 = SET_SRC (exp);
1468 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1470 cc_status.value2 = 0;
1472 /* Some operations may set V, which gets us
1473 unoptimizable results in "gt" and "le" condition
1475 if (GET_CODE (SET_SRC (exp)) == PLUS
1476 || GET_CODE (SET_SRC (exp)) == MINUS
1477 || GET_CODE (SET_SRC (exp)) == NEG)
1478 cc_status.flags |= CC_NO_OVERFLOW;
1483 else if (GET_CODE (SET_DEST (exp)) == MEM
1484 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1485 && GET_CODE (XEXP (SET_DEST (exp), 0)) == MEM))
1487 /* When SET to MEM, then CC is not changed (except for
1489 if (cc_status.value1
1490 && modified_in_p (cc_status.value1, insn))
1491 cc_status.value1 = 0;
1493 if (cc_status.value2
1494 && modified_in_p (cc_status.value2, insn))
1495 cc_status.value2 = 0;
1500 else if (GET_CODE (exp) == PARALLEL)
1502 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1503 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1504 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1506 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1507 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 1)) == MEM)
1509 /* For "move.S [rx=ry+o],rz", say CC reflects
1510 value1=rz and value2=[rx] */
1511 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1513 = replace_equiv_address (XEXP (XVECEXP (exp, 0, 0), 1),
1514 XEXP (XVECEXP (exp, 0, 1), 0));
1515 cc_status.flags = 0;
1517 /* Huh? A side-effect cannot change the destination
1519 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1521 internal_error ("internal error: sideeffect-insn affecting main effect");
1524 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1525 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1526 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 0)) == MEM)
1528 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1529 say flags are not changed, except for overlap. */
1530 if (cc_status.value1
1531 && modified_in_p (cc_status.value1, insn))
1532 cc_status.value1 = 0;
1534 if (cc_status.value2
1535 && modified_in_p (cc_status.value2, insn))
1536 cc_status.value2 = 0;
1545 internal_error ("unknown cc_attr value");
1551 /* Return != 0 if the return sequence for the current function is short,
1552 like "ret" or "jump [sp+]". Prior to reloading, we can't tell if
1553 registers must be saved, so return 0 then. */
1556 cris_simple_epilogue (void)
1559 unsigned int reglimit = STACK_POINTER_REGNUM;
1560 bool got_really_used = false;
1562 if (! reload_completed
1563 || frame_pointer_needed
1564 || get_frame_size () != 0
1565 || current_function_pretend_args_size
1566 || current_function_args_size
1567 || current_function_outgoing_args_size
1568 || current_function_calls_eh_return
1570 /* If we're not supposed to emit prologue and epilogue, we must
1571 not emit return-type instructions. */
1572 || !TARGET_PROLOGUE_EPILOGUE)
1575 if (current_function_uses_pic_offset_table)
1577 push_topmost_sequence ();
1579 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
1580 pop_topmost_sequence ();
1583 /* No simple epilogue if there are saved registers. */
1584 for (regno = 0; regno < reglimit; regno++)
1585 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
1591 /* Expand a return insn (just one insn) marked as using SRP or stack
1592 slot depending on parameter ON_STACK. */
1595 cris_expand_return (bool on_stack)
1597 /* FIXME: emit a parallel with a USE for SRP or the stack-slot, to
1598 tell "ret" from "jump [sp+]". Some, but not all, other parts of
1599 GCC expect just (return) to do the right thing when optimizing, so
1600 we do that until they're fixed. Currently, all return insns in a
1601 function must be the same (not really a limiting factor) so we need
1602 to check that it doesn't change half-way through. */
1603 emit_jump_insn (gen_rtx_RETURN (VOIDmode));
1605 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_RET || !on_stack);
1606 CRIS_ASSERT (cfun->machine->return_type != CRIS_RETINSN_JUMP || on_stack);
1608 cfun->machine->return_type
1609 = on_stack ? CRIS_RETINSN_JUMP : CRIS_RETINSN_RET;
1612 /* Compute a (partial) cost for rtx X. Return true if the complete
1613 cost has been computed, and false if subexpressions should be
1614 scanned. In either case, *TOTAL contains the cost result. */
1617 cris_rtx_costs (rtx x, int code, int outer_code, int *total)
1623 HOST_WIDE_INT val = INTVAL (x);
1626 else if (val < 32 && val >= -32)
1628 /* Eight or 16 bits are a word and cycle more expensive. */
1629 else if (val <= 32767 && val >= -32768)
1631 /* A 32 bit constant (or very seldom, unsigned 16 bits) costs
1632 another word. FIXME: This isn't linear to 16 bits. */
1648 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
1651 /* Make 0.0 cheap, else test-insns will not be used. */
1656 /* Identify values that are no powers of two. Powers of 2 are
1657 taken care of already and those values should not be changed. */
1658 if (GET_CODE (XEXP (x, 1)) != CONST_INT
1659 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1661 /* If we have a multiply insn, then the cost is between
1662 1 and 2 "fast" instructions. */
1663 if (TARGET_HAS_MUL_INSNS)
1665 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
1669 /* Estimate as 4 + 4 * #ofbits. */
1670 *total = COSTS_N_INSNS (132);
1679 if (GET_CODE (XEXP (x, 1)) != CONST_INT
1680 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
1682 /* Estimate this as 4 + 8 * #of bits. */
1683 *total = COSTS_N_INSNS (260);
1689 if (GET_CODE (XEXP (x, 1)) == CONST_INT
1690 /* Two constants may actually happen before optimization. */
1691 && GET_CODE (XEXP (x, 0)) != CONST_INT
1692 && !CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
1694 *total = (rtx_cost (XEXP (x, 0), outer_code) + 2
1695 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
1700 case ZERO_EXTEND: case SIGN_EXTEND:
1701 *total = rtx_cost (XEXP (x, 0), outer_code);
1709 /* The ADDRESS_COST worker. */
1712 cris_address_cost (rtx x)
1714 /* The metric to use for the cost-macros is unclear.
1715 The metric used here is (the number of cycles needed) / 2,
1716 where we consider equal a cycle for a word of code and a cycle to
1719 /* The cheapest addressing modes get 0, since nothing extra is needed. */
1720 if (BASE_OR_AUTOINCR_P (x))
1723 /* An indirect mem must be a DIP. This means two bytes extra for code,
1724 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
1725 if (GET_CODE (x) == MEM)
1728 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
1729 an extra DIP prefix and 4 bytes of constant in most cases. */
1733 /* Handle BIAP and BDAP prefixes. */
1734 if (GET_CODE (x) == PLUS)
1736 rtx tem1 = XEXP (x, 0);
1737 rtx tem2 = XEXP (x, 1);
1739 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
1740 recognize the typical MULT which is always in tem1 because of
1741 insn canonicalization. */
1742 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
1746 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
1747 PLUS is always found in tem2. */
1748 if (GET_CODE (tem2) == CONST_INT
1749 && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
1752 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
1754 if (GET_CODE (tem2) == CONST_INT
1755 && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
1758 /* A BDAP with some other constant is 2 bytes extra. */
1759 if (CONSTANT_P (tem2))
1760 return (2 + 2 + 2) / 2;
1762 /* BDAP with something indirect should have a higher cost than
1763 BIAP with register. FIXME: Should it cost like a MEM or more? */
1764 /* Don't need to check it, it's the only one left.
1765 FIXME: There was a REG test missing, perhaps there are others.
1767 return (2 + 2 + 2) / 2;
1770 /* What else? Return a high cost. It matters only for valid
1771 addressing modes. */
1775 /* Check various objections to the side-effect. Used in the test-part
1776 of an anonymous insn describing an insn with a possible side-effect.
1777 Returns nonzero if the implied side-effect is ok.
1780 ops : An array of rtx:es. lreg, rreg, rval,
1781 The variables multop and other_op are indexes into this,
1782 or -1 if they are not applicable.
1783 lreg : The register that gets assigned in the side-effect.
1784 rreg : One register in the side-effect expression
1785 rval : The other register, or an int.
1786 multop : An integer to multiply rval with.
1787 other_op : One of the entities of the main effect,
1788 whose mode we must consider. */
1791 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
1792 int lreg, int rreg, int rval,
1793 int multop, int other_op)
1795 /* Find what value to multiply with, for rx =ry + rz * n. */
1796 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
1798 rtx reg_rtx = ops[rreg];
1799 rtx val_rtx = ops[rval];
1801 /* The operands may be swapped. Canonicalize them in reg_rtx and
1802 val_rtx, where reg_rtx always is a reg (for this constraint to
1804 if (! BASE_P (reg_rtx))
1805 reg_rtx = val_rtx, val_rtx = ops[rreg];
1807 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
1808 we have no business. */
1809 if (! BASE_P (reg_rtx))
1812 /* Don't do this when -mno-split. */
1813 if (!TARGET_SIDE_EFFECT_PREFIXES)
1816 /* The mult expression may be hidden in lreg. FIXME: Add more
1817 commentary about that. */
1818 if (GET_CODE (val_rtx) == MULT)
1820 mult = INTVAL (XEXP (val_rtx, 1));
1821 val_rtx = XEXP (val_rtx, 0);
1825 /* First check the "other operand". */
1828 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
1831 /* Check if the lvalue register is the same as the "other
1832 operand". If so, the result is undefined and we shouldn't do
1833 this. FIXME: Check again. */
1834 if ((BASE_P (ops[lreg])
1835 && BASE_P (ops[other_op])
1836 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
1837 || rtx_equal_p (ops[other_op], ops[lreg]))
1841 /* Do not accept frame_pointer_rtx as any operand. */
1842 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
1843 || ops[rval] == frame_pointer_rtx
1844 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
1848 && ! BASE_P (val_rtx))
1851 /* Do not allow rx = rx + n if a normal add or sub with same size
1853 if (rtx_equal_p (ops[lreg], reg_rtx)
1854 && GET_CODE (val_rtx) == CONST_INT
1855 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
1858 /* Check allowed cases, like [r(+)?].[bwd] and const. */
1859 if (CONSTANT_P (val_rtx))
1862 if (GET_CODE (val_rtx) == MEM
1863 && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
1866 if (GET_CODE (val_rtx) == SIGN_EXTEND
1867 && GET_CODE (XEXP (val_rtx, 0)) == MEM
1868 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
1871 /* If we got here, it's not a valid addressing mode. */
1874 else if (code == MULT
1875 || (code == PLUS && BASE_P (val_rtx)))
1877 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
1878 if (rtx_equal_p (ops[lreg], reg_rtx)
1879 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
1882 /* Do not allow bad multiply-values. */
1883 if (mult != 1 && mult != 2 && mult != 4)
1886 /* Only allow r + ... */
1887 if (! BASE_P (reg_rtx))
1890 /* If we got here, all seems ok.
1891 (All checks need to be done above). */
1895 /* If we get here, the caller got its initial tests wrong. */
1896 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
1899 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
1900 does not handle the case where the IN operand is strict_low_part; it
1901 does handle it for X. Test-case in Axis-20010516. This function takes
1902 care of that for THIS port. FIXME: strict_low_part is going away
1906 cris_reg_overlap_mentioned_p (rtx x, rtx in)
1908 /* The function reg_overlap_mentioned now handles when X is
1909 strict_low_part, but not when IN is a STRICT_LOW_PART. */
1910 if (GET_CODE (in) == STRICT_LOW_PART)
1913 return reg_overlap_mentioned_p (x, in);
1916 /* The TARGET_ASM_NAMED_SECTION worker.
1917 We just dispatch to the functions for ELF and a.out. */
1920 cris_target_asm_named_section (const char *name, unsigned int flags,
1924 default_no_named_section (name, flags, decl);
1926 default_elf_asm_named_section (name, flags, decl);
1929 /* Return TRUE iff X is a CONST valid for e.g. indexing. */
1932 cris_valid_pic_const (rtx x)
1934 gcc_assert (flag_pic);
1936 switch (GET_CODE (x))
1945 if (GET_CODE (x) != CONST)
1950 /* Handle (const (plus (unspec .. UNSPEC_GOTREL) (const_int ...))). */
1951 if (GET_CODE (x) == PLUS
1952 && GET_CODE (XEXP (x, 0)) == UNSPEC
1953 && XINT (XEXP (x, 0), 1) == CRIS_UNSPEC_GOTREL
1954 && GET_CODE (XEXP (x, 1)) == CONST_INT)
1957 if (GET_CODE (x) == UNSPEC)
1958 switch (XINT (x, 1))
1960 case CRIS_UNSPEC_PLT:
1961 case CRIS_UNSPEC_PLTGOTREAD:
1962 case CRIS_UNSPEC_GOTREAD:
1963 case CRIS_UNSPEC_GOTREL:
1969 return cris_pic_symbol_type_of (x) == cris_no_symbol;
1972 /* Helper function to find the right PIC-type symbol to generate,
1973 given the original (non-PIC) representation. */
1975 enum cris_pic_symbol_type
1976 cris_pic_symbol_type_of (rtx x)
1978 switch (GET_CODE (x))
1981 return SYMBOL_REF_LOCAL_P (x)
1982 ? cris_gotrel_symbol : cris_got_symbol;
1985 return cris_gotrel_symbol;
1988 return cris_pic_symbol_type_of (XEXP (x, 0));
1993 enum cris_pic_symbol_type t1 = cris_pic_symbol_type_of (XEXP (x, 0));
1994 enum cris_pic_symbol_type t2 = cris_pic_symbol_type_of (XEXP (x, 1));
1996 gcc_assert (t1 == cris_no_symbol || t2 == cris_no_symbol);
1998 if (t1 == cris_got_symbol || t1 == cris_got_symbol)
1999 return cris_got_symbol_needing_fixup;
2001 return t1 != cris_no_symbol ? t1 : t2;
2006 return cris_no_symbol;
2009 /* Likely an offsettability-test attempting to add a constant to
2010 a GOTREAD symbol, which can't be handled. */
2011 return cris_invalid_pic_symbol;
2014 fatal_insn ("unrecognized supposed constant", x);
2020 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2023 cris_legitimate_pic_operand (rtx x)
2025 /* Symbols are not valid PIC operands as-is; just constants. */
2026 return cris_valid_pic_const (x);
2029 /* TARGET_HANDLE_OPTION worker. We just store the values into local
2030 variables here. Checks for correct semantics are in
2031 cris_override_options. */
2034 cris_handle_option (size_t code, const char *arg ATTRIBUTE_UNUSED,
2035 int value ATTRIBUTE_UNUSED)
2043 + MASK_ALIGN_BY_32);
2046 case OPT_mno_etrax100:
2050 + MASK_ALIGN_BY_32);
2056 |= (MASK_STACK_ALIGN
2059 + MASK_ALIGN_BY_32);
2065 |= (MASK_STACK_ALIGN
2073 &= ~(MASK_STACK_ALIGN
2082 CRIS_SUBTARGET_HANDLE_OPTION(code, arg, value);
2087 /* The OVERRIDE_OPTIONS worker.
2088 As is the norm, this also parses -mfoo=bar type parameters. */
2091 cris_override_options (void)
2093 if (cris_max_stackframe_str)
2095 cris_max_stackframe = atoi (cris_max_stackframe_str);
2097 /* Do some sanity checking. */
2098 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2099 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2100 cris_max_stackframe, 0x20000000);
2103 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2104 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2105 cris_cpu_version = CRIS_CPU_SVINTO;
2106 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2107 cris_cpu_version = CRIS_CPU_ETRAX4;
2109 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2113 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2115 if (strcmp ("etrax4", cris_cpu_str) == 0)
2116 cris_cpu_version = 3;
2118 if (strcmp ("svinto", cris_cpu_str) == 0
2119 || strcmp ("etrax100", cris_cpu_str) == 0)
2120 cris_cpu_version = 8;
2122 if (strcmp ("ng", cris_cpu_str) == 0
2123 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2124 cris_cpu_version = 10;
2126 if (cris_cpu_version < 0 || cris_cpu_version > 10)
2127 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2130 /* Set the target flags. */
2131 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2132 target_flags |= MASK_ETRAX4_ADD;
2134 /* If this is Svinto or higher, align for 32 bit accesses. */
2135 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2137 |= (MASK_SVINTO | MASK_ALIGN_BY_32
2138 | MASK_STACK_ALIGN | MASK_CONST_ALIGN
2141 /* Note that we do not add new flags when it can be completely
2142 described with a macro that uses -mcpu=X. So
2143 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2149 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2151 if (strcmp ("etrax4", cris_tune_str) == 0)
2154 if (strcmp ("svinto", cris_tune_str) == 0
2155 || strcmp ("etrax100", cris_tune_str) == 0)
2158 if (strcmp ("ng", cris_tune_str) == 0
2159 || strcmp ("etrax100lx", cris_tune_str) == 0)
2162 if (cris_tune < 0 || cris_tune > 10)
2163 error ("unknown CRIS cpu version specification in -mtune= : %s",
2166 if (cris_tune >= CRIS_CPU_SVINTO)
2167 /* We have currently nothing more to tune than alignment for
2170 |= (MASK_STACK_ALIGN | MASK_CONST_ALIGN
2171 | MASK_DATA_ALIGN | MASK_ALIGN_BY_32);
2176 /* Use error rather than warning, so invalid use is easily
2177 detectable. Still change to the values we expect, to avoid
2181 error ("-fPIC and -fpic are not supported in this configuration");
2185 /* Turn off function CSE. We need to have the addresses reach the
2186 call expanders to get PLT-marked, as they could otherwise be
2187 compared against zero directly or indirectly. After visiting the
2188 call expanders they will then be cse:ed, as the call expanders
2189 force_reg the addresses, effectively forcing flag_no_function_cse
2191 flag_no_function_cse = 1;
2194 if (write_symbols == DWARF2_DEBUG && ! TARGET_ELF)
2196 warning (0, "that particular -g option is invalid with -maout and -melinux");
2197 write_symbols = DBX_DEBUG;
2200 /* Set the per-function-data initializer. */
2201 init_machine_status = cris_init_machine_status;
2204 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2207 cris_asm_output_mi_thunk (FILE *stream,
2208 tree thunkdecl ATTRIBUTE_UNUSED,
2209 HOST_WIDE_INT delta,
2210 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2214 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2215 ADDITIVE_SIZE_MODIFIER (delta), delta,
2216 reg_names[CRIS_FIRST_ARG_REG]);
2218 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2219 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2220 reg_names[CRIS_FIRST_ARG_REG]);
2224 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2226 name = (* targetm.strip_name_encoding) (name);
2227 fprintf (stream, "add.d ");
2228 assemble_name (stream, name);
2229 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2233 fprintf (stream, "jump ");
2234 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2235 fprintf (stream, "\n");
2239 /* Boilerplate emitted at start of file.
2241 NO_APP *only at file start* means faster assembly. It also means
2242 comments are not allowed. In some cases comments will be output
2243 for debugging purposes. Make sure they are allowed then.
2245 We want a .file directive only if TARGET_ELF. */
2247 cris_file_start (void)
2249 /* These expressions can vary at run time, so we cannot put
2250 them into TARGET_INITIALIZER. */
2251 targetm.file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2252 targetm.file_start_file_directive = TARGET_ELF;
2254 default_file_start ();
2257 /* Rename the function calls for integer multiply and divide. */
2259 cris_init_libfuncs (void)
2261 set_optab_libfunc (smul_optab, SImode, "__Mul");
2262 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2263 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2264 set_optab_libfunc (smod_optab, SImode, "__Mod");
2265 set_optab_libfunc (umod_optab, SImode, "__Umod");
2268 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2272 cris_init_expanders (void)
2274 /* Nothing here at the moment. */
2277 /* Zero initialization is OK for all current fields. */
2279 static struct machine_function *
2280 cris_init_machine_status (void)
2282 return ggc_alloc_cleared (sizeof (struct machine_function));
2285 /* Split a 2 word move (DI or presumably DF) into component parts.
2286 Originally a copy of gen_split_move_double in m32r.c. */
2289 cris_split_movdx (rtx *operands)
2291 enum machine_mode mode = GET_MODE (operands[0]);
2292 rtx dest = operands[0];
2293 rtx src = operands[1];
2296 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2297 longer happen; after reload there are no SUBREGs any more, and we're
2298 only called after reload. */
2299 CRIS_ASSERT (GET_CODE (dest) != SUBREG && GET_CODE (src) != SUBREG);
2302 if (GET_CODE (dest) == REG)
2304 int dregno = REGNO (dest);
2306 /* Reg-to-reg copy. */
2307 if (GET_CODE (src) == REG)
2309 int sregno = REGNO (src);
2311 int reverse = (dregno == sregno + 1);
2313 /* We normally copy the low-numbered register first. However, if
2314 the first register operand 0 is the same as the second register of
2315 operand 1, we must copy in the opposite order. */
2316 emit_insn (gen_rtx_SET (VOIDmode,
2317 operand_subword (dest, reverse, TRUE, mode),
2318 operand_subword (src, reverse, TRUE, mode)));
2320 emit_insn (gen_rtx_SET (VOIDmode,
2321 operand_subword (dest, !reverse, TRUE, mode),
2322 operand_subword (src, !reverse, TRUE, mode)));
2324 /* Constant-to-reg copy. */
2325 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
2328 split_double (src, &words[0], &words[1]);
2329 emit_insn (gen_rtx_SET (VOIDmode,
2330 operand_subword (dest, 0, TRUE, mode),
2333 emit_insn (gen_rtx_SET (VOIDmode,
2334 operand_subword (dest, 1, TRUE, mode),
2337 /* Mem-to-reg copy. */
2338 else if (GET_CODE (src) == MEM)
2340 /* If the high-address word is used in the address, we must load it
2341 last. Otherwise, load it first. */
2342 rtx addr = XEXP (src, 0);
2344 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2346 /* The original code implies that we can't do
2347 move.x [rN+],rM move.x [rN],rM+1
2348 when rN is dead, because of REG_NOTES damage. That is
2349 consistent with what I've seen, so don't try it.
2351 We have two different cases here; if the addr is POST_INC,
2352 just pass it through, otherwise add constants. */
2354 if (GET_CODE (addr) == POST_INC)
2359 /* Whenever we emit insns with post-incremented
2360 addresses ourselves, we must add a post-inc note
2362 mem = change_address (src, SImode, addr);
2364 = gen_rtx_SET (VOIDmode,
2365 operand_subword (dest, 0, TRUE, mode), mem);
2366 insn = emit_insn (insn);
2367 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2369 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2372 mem = change_address (src, SImode, addr);
2374 = gen_rtx_SET (VOIDmode,
2375 operand_subword (dest, 1, TRUE, mode), mem);
2376 insn = emit_insn (insn);
2377 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2379 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2384 /* Make sure we don't get any other addresses with
2385 embedded postincrements. They should be stopped in
2386 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2388 if (side_effects_p (addr))
2389 fatal_insn ("unexpected side-effects in address", addr);
2391 emit_insn (gen_rtx_SET
2393 operand_subword (dest, reverse, TRUE, mode),
2396 plus_constant (addr,
2397 reverse * UNITS_PER_WORD))));
2398 emit_insn (gen_rtx_SET
2400 operand_subword (dest, ! reverse, TRUE, mode),
2403 plus_constant (addr,
2409 internal_error ("Unknown src");
2411 /* Reg-to-mem copy or clear mem. */
2412 else if (GET_CODE (dest) == MEM
2413 && (GET_CODE (src) == REG
2414 || src == const0_rtx
2415 || src == CONST0_RTX (DFmode)))
2417 rtx addr = XEXP (dest, 0);
2419 if (GET_CODE (addr) == POST_INC)
2424 /* Whenever we emit insns with post-incremented addresses
2425 ourselves, we must add a post-inc note manually. */
2426 mem = change_address (dest, SImode, addr);
2428 = gen_rtx_SET (VOIDmode,
2429 mem, operand_subword (src, 0, TRUE, mode));
2430 insn = emit_insn (insn);
2431 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2433 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2436 mem = change_address (dest, SImode, addr);
2438 = gen_rtx_SET (VOIDmode,
2440 operand_subword (src, 1, TRUE, mode));
2441 insn = emit_insn (insn);
2442 if (GET_CODE (XEXP (mem, 0)) == POST_INC)
2444 = alloc_EXPR_LIST (REG_INC, XEXP (XEXP (mem, 0), 0),
2449 /* Make sure we don't get any other addresses with embedded
2450 postincrements. They should be stopped in
2451 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2452 if (side_effects_p (addr))
2453 fatal_insn ("unexpected side-effects in address", addr);
2455 emit_insn (gen_rtx_SET
2457 change_address (dest, SImode, addr),
2458 operand_subword (src, 0, TRUE, mode)));
2460 emit_insn (gen_rtx_SET
2462 change_address (dest, SImode,
2463 plus_constant (addr,
2465 operand_subword (src, 1, TRUE, mode)));
2470 internal_error ("Unknown dest");
2477 /* The expander for the prologue pattern name. */
2480 cris_expand_prologue (void)
2483 int size = get_frame_size ();
2484 /* Shorten the used name for readability. */
2485 int cfoa_size = current_function_outgoing_args_size;
2486 int last_movem_reg = -1;
2489 int return_address_on_stack = cris_return_address_on_stack ();
2490 int got_really_used = false;
2491 int n_movem_regs = 0;
2492 int pretend = current_function_pretend_args_size;
2494 /* Don't do anything if no prologues or epilogues are wanted. */
2495 if (!TARGET_PROLOGUE_EPILOGUE)
2498 CRIS_ASSERT (size >= 0);
2500 if (current_function_uses_pic_offset_table)
2502 /* A reference may have been optimized out (like the abort () in
2503 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2505 push_topmost_sequence ();
2507 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2508 pop_topmost_sequence ();
2511 /* Align the size to what's best for the CPU model. */
2512 if (TARGET_STACK_ALIGN)
2513 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2517 /* See also cris_setup_incoming_varargs where
2518 cfun->machine->stdarg_regs is set. There are other setters of
2519 current_function_pretend_args_size than stdarg handling, like
2520 for an argument passed with parts in R13 and stack. We must
2521 not store R13 into the pretend-area for that case, as GCC does
2522 that itself. "Our" store would be marked as redundant and GCC
2523 will attempt to remove it, which will then be flagged as an
2524 internal error; trying to remove a frame-related insn. */
2525 int stdarg_regs = cfun->machine->stdarg_regs;
2527 framesize += pretend;
2529 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
2531 regno--, pretend -= 4, stdarg_regs--)
2533 insn = emit_insn (gen_rtx_SET (VOIDmode,
2535 plus_constant (stack_pointer_rtx,
2537 /* FIXME: When dwarf2 frame output and unless asynchronous
2538 exceptions, make dwarf2 bundle together all stack
2539 adjustments like it does for registers between stack
2541 RTX_FRAME_RELATED_P (insn) = 1;
2543 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2544 set_mem_alias_set (mem, get_varargs_alias_set ());
2545 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2547 /* Note the absence of RTX_FRAME_RELATED_P on the above insn:
2548 the value isn't restored, so we don't want to tell dwarf2
2549 that it's been stored to stack, else EH handling info would
2553 /* For other setters of current_function_pretend_args_size, we
2554 just adjust the stack by leaving the remaining size in
2555 "pretend", handled below. */
2558 /* Save SRP if not a leaf function. */
2559 if (return_address_on_stack)
2561 insn = emit_insn (gen_rtx_SET (VOIDmode,
2563 plus_constant (stack_pointer_rtx,
2566 RTX_FRAME_RELATED_P (insn) = 1;
2568 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2569 set_mem_alias_set (mem, get_frame_alias_set ());
2570 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM));
2571 RTX_FRAME_RELATED_P (insn) = 1;
2575 /* Set up the frame pointer, if needed. */
2576 if (frame_pointer_needed)
2578 insn = emit_insn (gen_rtx_SET (VOIDmode,
2580 plus_constant (stack_pointer_rtx,
2583 RTX_FRAME_RELATED_P (insn) = 1;
2585 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2586 set_mem_alias_set (mem, get_frame_alias_set ());
2587 insn = emit_move_insn (mem, frame_pointer_rtx);
2588 RTX_FRAME_RELATED_P (insn) = 1;
2590 insn = emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
2591 RTX_FRAME_RELATED_P (insn) = 1;
2596 /* Between frame-pointer and saved registers lie the area for local
2597 variables. If we get here with "pretended" size remaining, count
2598 it into the general stack size. */
2601 /* Get a contiguous sequence of registers, starting with R0, that need
2603 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
2605 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2609 /* Check if movem may be used for registers so far. */
2610 if (regno == last_movem_reg + 1)
2611 /* Yes, update next expected register. */
2612 last_movem_reg = regno;
2615 /* We cannot use movem for all registers. We have to flush
2616 any movem:ed registers we got so far. */
2617 if (last_movem_reg != -1)
2620 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2622 /* It is a win to use a side-effect assignment for
2623 64 <= size <= 128. But side-effect on movem was
2624 not usable for CRIS v0..3. Also only do it if
2625 side-effects insns are allowed. */
2626 if ((last_movem_reg + 1) * 4 + size >= 64
2627 && (last_movem_reg + 1) * 4 + size <= 128
2628 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2629 && TARGET_SIDE_EFFECT_PREFIXES)
2632 = gen_rtx_MEM (SImode,
2633 plus_constant (stack_pointer_rtx,
2634 -(n_saved * 4 + size)));
2635 set_mem_alias_set (mem, get_frame_alias_set ());
2637 = cris_emit_movem_store (mem, GEN_INT (n_saved),
2638 -(n_saved * 4 + size),
2644 = gen_rtx_SET (VOIDmode,
2646 plus_constant (stack_pointer_rtx,
2647 -(n_saved * 4 + size)));
2648 insn = emit_insn (insn);
2649 RTX_FRAME_RELATED_P (insn) = 1;
2651 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2652 set_mem_alias_set (mem, get_frame_alias_set ());
2653 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2657 framesize += n_saved * 4 + size;
2658 last_movem_reg = -1;
2662 insn = emit_insn (gen_rtx_SET (VOIDmode,
2664 plus_constant (stack_pointer_rtx,
2666 RTX_FRAME_RELATED_P (insn) = 1;
2668 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2669 set_mem_alias_set (mem, get_frame_alias_set ());
2670 insn = emit_move_insn (mem, gen_rtx_raw_REG (SImode, regno));
2671 RTX_FRAME_RELATED_P (insn) = 1;
2673 framesize += 4 + size;
2679 /* Check after, if we could movem all registers. This is the normal case. */
2680 if (last_movem_reg != -1)
2683 = (n_movem_regs == 1) ? 1 : last_movem_reg + 1;
2685 /* Side-effect on movem was not usable for CRIS v0..3. Also only
2686 do it if side-effects insns are allowed. */
2687 if ((last_movem_reg + 1) * 4 + size >= 64
2688 && (last_movem_reg + 1) * 4 + size <= 128
2689 && (cris_cpu_version >= CRIS_CPU_SVINTO || n_saved == 1)
2690 && TARGET_SIDE_EFFECT_PREFIXES)
2693 = gen_rtx_MEM (SImode,
2694 plus_constant (stack_pointer_rtx,
2695 -(n_saved * 4 + size)));
2696 set_mem_alias_set (mem, get_frame_alias_set ());
2697 insn = cris_emit_movem_store (mem, GEN_INT (n_saved),
2698 -(n_saved * 4 + size), true);
2703 = gen_rtx_SET (VOIDmode,
2705 plus_constant (stack_pointer_rtx,
2706 -(n_saved * 4 + size)));
2707 insn = emit_insn (insn);
2708 RTX_FRAME_RELATED_P (insn) = 1;
2710 mem = gen_rtx_MEM (SImode, stack_pointer_rtx);
2711 set_mem_alias_set (mem, get_frame_alias_set ());
2712 insn = cris_emit_movem_store (mem, GEN_INT (n_saved), 0, true);
2715 framesize += n_saved * 4 + size;
2716 /* We have to put outgoing argument space after regs. */
2719 insn = emit_insn (gen_rtx_SET (VOIDmode,
2721 plus_constant (stack_pointer_rtx,
2723 RTX_FRAME_RELATED_P (insn) = 1;
2724 framesize += cfoa_size;
2727 else if ((size + cfoa_size) > 0)
2729 insn = emit_insn (gen_rtx_SET (VOIDmode,
2731 plus_constant (stack_pointer_rtx,
2732 -(cfoa_size + size))));
2733 RTX_FRAME_RELATED_P (insn) = 1;
2734 framesize += size + cfoa_size;
2737 /* Set up the PIC register, if it is used. */
2738 if (got_really_used)
2741 = gen_rtx_UNSPEC (SImode, gen_rtvec (1, const0_rtx), CRIS_UNSPEC_GOT);
2742 emit_move_insn (pic_offset_table_rtx, got);
2744 /* FIXME: This is a cover-up for flow2 messing up; it doesn't
2745 follow exceptional paths and tries to delete the GOT load as
2746 unused, if it isn't used on the non-exceptional paths. Other
2747 ports have similar or other cover-ups, or plain bugs marking
2748 the GOT register load as maybe-dead. To see this, remove the
2749 line below and try libsupc++/vec.cc or a trivial
2750 "static void y (); void x () {try {y ();} catch (...) {}}". */
2751 emit_insn (gen_rtx_USE (VOIDmode, pic_offset_table_rtx));
2754 if (cris_max_stackframe && framesize > cris_max_stackframe)
2755 warning (0, "stackframe too big: %d bytes", framesize);
2758 /* The expander for the epilogue pattern. */
2761 cris_expand_epilogue (void)
2764 int size = get_frame_size ();
2765 int last_movem_reg = -1;
2766 int argspace_offset = current_function_outgoing_args_size;
2767 int pretend = current_function_pretend_args_size;
2769 bool return_address_on_stack = cris_return_address_on_stack ();
2770 /* A reference may have been optimized out
2771 (like the abort () in fde_split in unwind-dw2-fde.c, at least 3.2.1)
2772 so check that it's still used. */
2773 int got_really_used = false;
2774 int n_movem_regs = 0;
2776 if (!TARGET_PROLOGUE_EPILOGUE)
2779 if (current_function_uses_pic_offset_table)
2781 /* A reference may have been optimized out (like the abort () in
2782 fde_split in unwind-dw2-fde.c, at least 3.2.1) so check that
2784 push_topmost_sequence ();
2786 = reg_used_between_p (pic_offset_table_rtx, get_insns (), NULL_RTX);
2787 pop_topmost_sequence ();
2790 /* Align byte count of stack frame. */
2791 if (TARGET_STACK_ALIGN)
2792 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
2794 /* Check how many saved regs we can movem. They start at r0 and must
2797 regno < FIRST_PSEUDO_REGISTER;
2799 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2803 if (regno == last_movem_reg + 1)
2804 last_movem_reg = regno;
2809 /* If there was only one register that really needed to be saved
2810 through movem, don't use movem. */
2811 if (n_movem_regs == 1)
2812 last_movem_reg = -1;
2814 /* Now emit "normal" move insns for all regs higher than the movem
2816 for (regno = FIRST_PSEUDO_REGISTER - 1;
2817 regno > last_movem_reg;
2819 if (cris_reg_saved_in_regsave_area (regno, got_really_used))
2823 if (argspace_offset)
2825 /* There is an area for outgoing parameters located before
2826 the saved registers. We have to adjust for that. */
2827 emit_insn (gen_rtx_SET (VOIDmode,
2829 plus_constant (stack_pointer_rtx,
2831 /* Make sure we only do this once. */
2832 argspace_offset = 0;
2835 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
2836 stack_pointer_rtx));
2837 set_mem_alias_set (mem, get_frame_alias_set ());
2838 insn = emit_move_insn (gen_rtx_raw_REG (SImode, regno), mem);
2840 /* Whenever we emit insns with post-incremented addresses
2841 ourselves, we must add a post-inc note manually. */
2843 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
2846 /* If we have any movem-restore, do it now. */
2847 if (last_movem_reg != -1)
2851 if (argspace_offset)
2853 emit_insn (gen_rtx_SET (VOIDmode,
2855 plus_constant (stack_pointer_rtx,
2857 argspace_offset = 0;
2860 mem = gen_rtx_MEM (SImode,
2861 gen_rtx_POST_INC (SImode, stack_pointer_rtx));
2862 set_mem_alias_set (mem, get_frame_alias_set ());
2864 = emit_insn (cris_gen_movem_load (mem,
2865 GEN_INT (last_movem_reg + 1), 0));
2866 /* Whenever we emit insns with post-incremented addresses
2867 ourselves, we must add a post-inc note manually. */
2868 if (side_effects_p (PATTERN (insn)))
2870 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
2873 /* If we don't clobber all of the allocated stack area (we've already
2874 deallocated saved registers), GCC might want to schedule loads from
2875 the stack to *after* the stack-pointer restore, which introduces an
2876 interrupt race condition. This happened for the initial-value
2877 SRP-restore for g++.dg/eh/registers1.C (noticed by inspection of
2878 other failure for that test). It also happened for the stack slot
2879 for the return value in (one version of)
2880 linux/fs/dcache.c:__d_lookup, at least with "-O2
2881 -fno-omit-frame-pointer". */
2883 /* Restore frame pointer if necessary. */
2884 if (frame_pointer_needed)
2888 emit_insn (gen_cris_frame_deallocated_barrier ());
2890 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
2891 mem = gen_rtx_MEM (SImode, gen_rtx_POST_INC (SImode,
2892 stack_pointer_rtx));
2893 set_mem_alias_set (mem, get_frame_alias_set ());
2894 insn = emit_move_insn (frame_pointer_rtx, mem);
2896 /* Whenever we emit insns with post-incremented addresses
2897 ourselves, we must add a post-inc note manually. */
2899 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
2901 else if ((size + argspace_offset) != 0)
2903 emit_insn (gen_cris_frame_deallocated_barrier ());
2905 /* If there was no frame-pointer to restore sp from, we must
2906 explicitly deallocate local variables. */
2908 /* Handle space for outgoing parameters that hasn't been handled
2910 size += argspace_offset;
2912 emit_insn (gen_rtx_SET (VOIDmode,
2914 plus_constant (stack_pointer_rtx, size)));
2917 /* If this function has no pushed register parameters
2918 (stdargs/varargs), and if it is not a leaf function, then we have
2919 the return address on the stack. */
2920 if (return_address_on_stack && pretend == 0)
2922 if (current_function_calls_eh_return)
2926 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
2927 mem = gen_rtx_MEM (SImode,
2928 gen_rtx_POST_INC (SImode,
2929 stack_pointer_rtx));
2930 set_mem_alias_set (mem, get_frame_alias_set ());
2931 insn = emit_move_insn (srpreg, mem);
2933 /* Whenever we emit insns with post-incremented addresses
2934 ourselves, we must add a post-inc note manually. */
2936 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
2938 emit_insn (gen_addsi3 (stack_pointer_rtx,
2940 gen_rtx_raw_REG (SImode,
2941 CRIS_STACKADJ_REG)));
2942 cris_expand_return (false);
2945 cris_expand_return (true);
2950 /* If we pushed some register parameters, then adjust the stack for
2954 /* If SRP is stored on the way, we need to restore it first. */
2955 if (return_address_on_stack)
2958 rtx srpreg = gen_rtx_raw_REG (SImode, CRIS_SRP_REGNUM);
2961 mem = gen_rtx_MEM (SImode,
2962 gen_rtx_POST_INC (SImode,
2963 stack_pointer_rtx));
2964 set_mem_alias_set (mem, get_frame_alias_set ());
2965 insn = emit_move_insn (srpreg, mem);
2967 /* Whenever we emit insns with post-incremented addresses
2968 ourselves, we must add a post-inc note manually. */
2970 = alloc_EXPR_LIST (REG_INC, stack_pointer_rtx, REG_NOTES (insn));
2973 emit_insn (gen_rtx_SET (VOIDmode,
2975 plus_constant (stack_pointer_rtx, pretend)));
2978 /* Perform the "physical" unwinding that the EH machinery calculated. */
2979 if (current_function_calls_eh_return)
2980 emit_insn (gen_addsi3 (stack_pointer_rtx,
2982 gen_rtx_raw_REG (SImode,
2983 CRIS_STACKADJ_REG)));
2984 cris_expand_return (false);
2987 /* Worker function for generating movem from mem for load_multiple. */
2990 cris_gen_movem_load (rtx src, rtx nregs_rtx, int nprefix)
2992 int nregs = INTVAL (nregs_rtx);
2996 rtx srcreg = XEXP (src, 0);
2997 unsigned int regno = nregs - 1;
3000 if (GET_CODE (srcreg) == POST_INC)
3001 srcreg = XEXP (srcreg, 0);
3003 CRIS_ASSERT (REG_P (srcreg));
3005 /* Don't use movem for just one insn. The insns are equivalent except
3006 for the pipeline hazard (on v32); movem does not forward the loaded
3007 registers so there's a three cycles penalty for their use. */
3009 return gen_movsi (gen_rtx_REG (SImode, 0), src);
3011 vec = rtvec_alloc (nprefix + nregs
3012 + (GET_CODE (XEXP (src, 0)) == POST_INC));
3014 if (GET_CODE (XEXP (src, 0)) == POST_INC)
3016 RTVEC_ELT (vec, nprefix + 1)
3017 = gen_rtx_SET (VOIDmode, srcreg, plus_constant (srcreg, nregs * 4));
3021 src = replace_equiv_address (src, srcreg);
3022 RTVEC_ELT (vec, nprefix)
3023 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno), src);
3026 for (i = 1; i < nregs; i++, eltno++)
3028 RTVEC_ELT (vec, nprefix + eltno)
3029 = gen_rtx_SET (VOIDmode, gen_rtx_REG (SImode, regno),
3030 adjust_address_nv (src, SImode, i * 4));
3034 return gen_rtx_PARALLEL (VOIDmode, vec);
3037 /* Worker function for generating movem to mem. If FRAME_RELATED, notes
3038 are added that the dwarf2 machinery understands. */
3041 cris_emit_movem_store (rtx dest, rtx nregs_rtx, int increment,
3044 int nregs = INTVAL (nregs_rtx);
3049 rtx destreg = XEXP (dest, 0);
3050 unsigned int regno = nregs - 1;
3053 if (GET_CODE (destreg) == POST_INC)
3054 increment += nregs * 4;
3056 if (GET_CODE (destreg) == POST_INC || GET_CODE (destreg) == PLUS)
3057 destreg = XEXP (destreg, 0);
3059 CRIS_ASSERT (REG_P (destreg));
3061 /* Don't use movem for just one insn. The insns are equivalent except
3062 for the pipeline hazard (on v32); movem does not forward the loaded
3063 registers so there's a three cycles penalty for use. */
3066 rtx mov = gen_rtx_SET (VOIDmode, dest, gen_rtx_REG (SImode, 0));
3070 insn = emit_insn (mov);
3072 RTX_FRAME_RELATED_P (insn) = 1;
3076 /* If there was a request for a side-effect, create the ordinary
3078 vec = rtvec_alloc (2);
3080 RTVEC_ELT (vec, 0) = mov;
3081 RTVEC_ELT (vec, 1) = gen_rtx_SET (VOIDmode, destreg,
3082 plus_constant (destreg, increment));
3085 RTX_FRAME_RELATED_P (mov) = 1;
3086 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3091 vec = rtvec_alloc (nregs + (increment != 0 ? 1 : 0));
3093 = gen_rtx_SET (VOIDmode,
3094 replace_equiv_address (dest,
3095 plus_constant (destreg,
3097 gen_rtx_REG (SImode, regno));
3100 /* The dwarf2 info wants this mark on each component in a parallel
3101 that's part of the prologue (though it's optional on the first
3104 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 0)) = 1;
3109 = gen_rtx_SET (VOIDmode, destreg,
3110 plus_constant (destreg,
3112 ? increment : nregs * 4));
3116 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, 1)) = 1;
3118 /* Don't call adjust_address_nv on a post-incremented address if
3120 if (GET_CODE (XEXP (dest, 0)) == POST_INC)
3121 dest = replace_equiv_address (dest, destreg);
3124 for (i = 1; i < nregs; i++, eltno++)
3126 RTVEC_ELT (vec, eltno)
3127 = gen_rtx_SET (VOIDmode, adjust_address_nv (dest, SImode, i * 4),
3128 gen_rtx_REG (SImode, regno));
3130 RTX_FRAME_RELATED_P (RTVEC_ELT (vec, eltno)) = 1;
3135 insn = emit_insn (gen_rtx_PARALLEL (VOIDmode, vec));
3137 /* Because dwarf2out.c handles the insns in a parallel as a sequence,
3138 we need to keep the stack adjustment separate, after the
3139 MEM-setters. Else the stack-adjustment in the second component of
3140 the parallel would be mishandled; the offsets for the SETs that
3141 follow it would be wrong. We prepare for this by adding a
3142 REG_FRAME_RELATED_EXPR with the MEM-setting parts in a SEQUENCE
3143 followed by the increment. Note that we have FRAME_RELATED_P on
3144 all the SETs, including the original stack adjustment SET in the
3150 rtx seq = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (nregs + 1));
3151 XVECEXP (seq, 0, 0) = XVECEXP (PATTERN (insn), 0, 0);
3152 for (i = 1; i < nregs; i++)
3153 XVECEXP (seq, 0, i) = XVECEXP (PATTERN (insn), 0, i + 1);
3154 XVECEXP (seq, 0, nregs) = XVECEXP (PATTERN (insn), 0, 1);
3156 = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR, seq,
3160 RTX_FRAME_RELATED_P (insn) = 1;
3166 /* Worker function for expanding the address for PIC function calls. */
3169 cris_expand_pic_call_address (rtx *opp)
3173 gcc_assert (MEM_P (op));
3176 /* It might be that code can be generated that jumps to 0 (or to a
3177 specific address). Don't die on that. (There is a
3179 if (CONSTANT_ADDRESS_P (op) && GET_CODE (op) != CONST_INT)
3181 enum cris_pic_symbol_type t = cris_pic_symbol_type_of (op);
3183 CRIS_ASSERT (!no_new_pseudos);
3185 /* For local symbols (non-PLT), just get the plain symbol
3186 reference into a register. For symbols that can be PLT, make
3188 if (t == cris_gotrel_symbol)
3189 op = force_reg (Pmode, op);
3190 else if (t == cris_got_symbol)
3192 if (TARGET_AVOID_GOTPLT)
3194 /* Change a "jsr sym" into (allocate register rM, rO)
3195 "move.d (const (unspec [sym] CRIS_UNSPEC_PLT)),rM"
3196 "add.d rPIC,rM,rO", "jsr rO". */
3198 gcc_assert (! no_new_pseudos);
3199 current_function_uses_pic_offset_table = 1;
3200 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op), CRIS_UNSPEC_PLT);
3201 rm = gen_reg_rtx (Pmode);
3202 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3203 ro = gen_reg_rtx (Pmode);
3204 if (expand_binop (Pmode, add_optab, rm,
3205 pic_offset_table_rtx,
3206 ro, 0, OPTAB_LIB_WIDEN) != ro)
3207 internal_error ("expand_binop failed in movsi got");
3212 /* Change a "jsr sym" into (allocate register rM, rO)
3213 "move.d (const (unspec [sym] CRIS_UNSPEC_PLTGOT)),rM"
3214 "add.d rPIC,rM,rO" "jsr [rO]" with the memory access
3215 marked as not trapping and not aliasing. No "move.d
3216 [rO],rP" as that would invite to re-use of a value
3217 that should not be reused. FIXME: Need a peephole2
3218 for cases when this is cse:d from the call, to change
3219 back to just get the PLT entry address, so we don't
3220 resolve the same symbol over and over (the memory
3221 access of the PLTGOT isn't constant). */
3222 rtx tem, mem, rm, ro;
3224 gcc_assert (! no_new_pseudos);
3225 current_function_uses_pic_offset_table = 1;
3226 tem = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, op),
3227 CRIS_UNSPEC_PLTGOTREAD);
3228 rm = gen_reg_rtx (Pmode);
3229 emit_move_insn (rm, gen_rtx_CONST (Pmode, tem));
3230 ro = gen_reg_rtx (Pmode);
3231 if (expand_binop (Pmode, add_optab, rm,
3232 pic_offset_table_rtx,
3233 ro, 0, OPTAB_LIB_WIDEN) != ro)
3234 internal_error ("expand_binop failed in movsi got");
3235 mem = gen_rtx_MEM (Pmode, ro);
3237 /* This MEM doesn't alias anything. Whether it aliases
3238 other same symbols is unimportant. */
3239 set_mem_alias_set (mem, new_alias_set ());
3240 MEM_NOTRAP_P (mem) = 1;
3245 /* Can't possibly get a GOT-needing-fixup for a function-call,
3247 fatal_insn ("Unidentifiable call op", op);
3249 *opp = replace_equiv_address (*opp, op);
3253 /* Use from within code, from e.g. PRINT_OPERAND and
3254 PRINT_OPERAND_ADDRESS. Macros used in output_addr_const need to emit
3255 different things depending on whether code operand or constant is
3259 cris_output_addr_const (FILE *file, rtx x)
3262 output_addr_const (file, x);
3266 /* Worker function for ASM_OUTPUT_SYMBOL_REF. */
3269 cris_asm_output_symbol_ref (FILE *file, rtx x)
3271 gcc_assert (GET_CODE (x) == SYMBOL_REF);
3273 if (flag_pic && in_code > 0)
3275 const char *origstr = XSTR (x, 0);
3277 str = (* targetm.strip_name_encoding) (origstr);
3278 assemble_name (file, str);
3281 if (! current_function_uses_pic_offset_table)
3282 output_operand_lossage ("PIC register isn't set up");
3285 assemble_name (file, XSTR (x, 0));
3288 /* Worker function for ASM_OUTPUT_LABEL_REF. */
3291 cris_asm_output_label_ref (FILE *file, char *buf)
3293 if (flag_pic && in_code > 0)
3295 assemble_name (file, buf);
3298 if (! current_function_uses_pic_offset_table)
3299 internal_error ("emitting PIC operand, but PIC register isn't set up");
3302 assemble_name (file, buf);
3305 /* Worker function for OUTPUT_ADDR_CONST_EXTRA. */
3308 cris_output_addr_const_extra (FILE *file, rtx xconst)
3310 switch (GET_CODE (xconst))
3315 x = XVECEXP (xconst, 0, 0);
3316 CRIS_ASSERT (GET_CODE (x) == SYMBOL_REF
3317 || GET_CODE (x) == LABEL_REF
3318 || GET_CODE (x) == CONST);
3319 output_addr_const (file, x);
3320 switch (XINT (xconst, 1))
3322 case CRIS_UNSPEC_PLT:
3323 fprintf (file, ":PLTG");
3326 case CRIS_UNSPEC_GOTREL:
3327 fprintf (file, ":GOTOFF");
3330 case CRIS_UNSPEC_GOTREAD:
3332 fprintf (file, ":GOT16");
3334 fprintf (file, ":GOT");
3337 case CRIS_UNSPEC_PLTGOTREAD:
3339 fprintf (file, CRIS_GOTPLT_SUFFIX "16");
3341 fprintf (file, CRIS_GOTPLT_SUFFIX);
3354 /* Worker function for TARGET_STRUCT_VALUE_RTX. */
3357 cris_struct_value_rtx (tree fntype ATTRIBUTE_UNUSED,
3358 int incoming ATTRIBUTE_UNUSED)
3360 return gen_rtx_REG (Pmode, CRIS_STRUCT_VALUE_REGNUM);