* target.h (asm_out.byte_op, asm_out.aligned_op, asm_out.unaligned_op,
[official-gcc.git] / gcc / config / cris / cris.c
blob8d2afa82d0617f5ad53f3cc803168bcb23d99a0b
1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Axis Communications. Written by Hans-Peter Nilsson.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "rtl.h"
25 #include "regs.h"
26 #include "hard-reg-set.h"
27 #include "real.h"
28 #include "insn-config.h"
29 #include "conditions.h"
30 #include "insn-attr.h"
31 #include "flags.h"
32 #include "tree.h"
33 #include "expr.h"
34 #include "except.h"
35 #include "function.h"
36 #include "toplev.h"
37 #include "recog.h"
38 #include "tm_p.h"
39 #include "debug.h"
40 #include "output.h"
41 #include "target.h"
42 #include "target-def.h"
44 /* Usable when we have an amount to add or subtract, and want the
45 optimal size of the insn. */
46 #define ADDITIVE_SIZE_MODIFIER(size) \
47 ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
49 #define ASSERT_PLT_UNSPEC(x) \
50 do \
51 { \
52 if (XEXP (x, 1) != NULL_RTX \
53 || (GET_CODE (XVECEXP (x, 0, 0)) != SYMBOL_REF \
54 && GET_CODE (XVECEXP (x, 0, 0)) != LABEL_REF)) \
55 abort (); \
56 } while (0)
58 #define LOSE_AND_RETURN(msg, x) \
59 do \
60 { \
61 cris_operand_lossage (msg, x); \
62 return; \
63 } while (0)
65 /* Per-function machine data. */
66 struct machine_function
68 int needs_return_address_on_stack;
71 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
72 pattern. */
73 static char cris_output_insn_is_bound = 0;
75 /* This one suppresses printing out the "rPIC+" in
76 "rPIC+sym:GOTOFF+offset" when doing PIC. For a PLT symbol, it
77 suppresses outputting it as [rPIC+sym:GOTPLT] and outputs similarly
78 just the "sym:GOTOFF" part. */
79 static int cris_pic_sympart_only = 0;
81 /* Fix for reg_overlap_mentioned_p. */
82 static int cris_reg_overlap_mentioned_p PARAMS ((rtx, rtx));
84 static void cris_print_base PARAMS ((rtx, FILE *));
86 static void cris_print_index PARAMS ((rtx, FILE *));
88 static void cris_init_machine_status PARAMS ((struct function *));
90 static int cris_initial_frame_pointer_offset PARAMS ((void));
92 static int saved_regs_mentioned PARAMS ((rtx));
94 static void cris_target_asm_function_prologue
95 PARAMS ((FILE *, HOST_WIDE_INT));
97 static void cris_target_asm_function_epilogue
98 PARAMS ((FILE *, HOST_WIDE_INT));
100 static void cris_operand_lossage PARAMS ((const char *, rtx));
102 /* The function cris_target_asm_function_epilogue puts the last insn to
103 output here. It always fits; there won't be a symbol operand. Used in
104 delay_slots_for_epilogue and function_epilogue. */
105 static char save_last[80];
107 /* This is the argument from the "-max-stack-stackframe=" option. */
108 const char *cris_max_stackframe_str;
110 /* This is the argument from the "-march=" option. */
111 const char *cris_cpu_str;
113 /* This is the argument from the "-mtune=" option. */
114 const char *cris_tune_str;
116 /* This is the argument from the "-melinux-stacksize=" option. */
117 const char *cris_elinux_stacksize_str;
119 /* This is the parsed result of the "-max-stack-stackframe=" option. If
120 it (still) is zero, then there was no such option given. */
121 int cris_max_stackframe = 0;
123 /* This is the parsed result of the "-march=" option, if given. */
124 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
126 #undef TARGET_ASM_ALIGNED_HI_OP
127 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
128 #undef TARGET_ASM_ALIGNED_SI_OP
129 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
130 #undef TARGET_ASM_ALIGNED_DI_OP
131 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
133 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
134 available in ELF. These "normal" pseudos do not have any alignment
135 constraints or side-effects. */
136 #undef TARGET_ASM_UNALIGNED_HI_OP
137 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
139 #undef TARGET_ASM_UNALIGNED_SI_OP
140 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
142 #undef TARGET_ASM_UNALIGNED_DI_OP
143 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
145 #undef TARGET_ASM_FUNCTION_PROLOGUE
146 #define TARGET_ASM_FUNCTION_PROLOGUE cris_target_asm_function_prologue
148 #undef TARGET_ASM_FUNCTION_EPILOGUE
149 #define TARGET_ASM_FUNCTION_EPILOGUE cris_target_asm_function_epilogue
151 struct gcc_target targetm = TARGET_INITIALIZER;
153 /* Predicate functions. */
155 /* This checks a part of an address, the one that is not a plain register
156 for an addressing mode using BDAP.
157 Allowed operands is either:
158 a) a register
159 b) a CONST operand (but not a symbol when generating PIC)
160 c) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
163 cris_bdap_operand (op, mode)
164 rtx op;
165 enum machine_mode mode;
167 register enum rtx_code code = GET_CODE (op);
169 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
170 return 0;
172 /* Just return whether this is a simple register or constant. */
173 if (register_operand (op, mode)
174 || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
175 return 1;
177 /* Is it a [r] or possibly a [r+]? */
178 if (code == MEM)
180 rtx tem = XEXP (op, 0);
182 if (mode == SImode
183 && (register_operand (tem, SImode)
184 || (GET_CODE (tem) == POST_INC
185 && register_operand (XEXP (tem, 0), SImode))))
186 return 1;
187 else
188 return 0;
191 /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)? */
192 if (code == SIGN_EXTEND)
194 rtx tem = XEXP (op, 0);
196 if (GET_CODE (tem) != MEM)
197 return 0;
199 tem = XEXP (tem, 0);
200 if (mode == SImode
201 && (register_operand (tem, SImode)
202 || (GET_CODE (tem) == POST_INC
203 && register_operand (XEXP (tem, 0), SImode))))
204 return 1;
205 else
206 return 0;
209 return 0;
212 /* This is similar to cris_bdap_operand:
213 It checks a part of an address, the one that is not a plain register
214 for an addressing mode using BDAP *or* BIAP.
215 Allowed operands is either:
216 a) a register
217 b) a CONST operand (but not a symbol when generating PIC)
218 c) a mult of (1, 2 or 4) and a register
219 d) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
222 cris_bdap_biap_operand (op, mode)
223 rtx op;
224 enum machine_mode mode;
226 register enum rtx_code code = GET_CODE (op);
227 rtx reg;
228 rtx val;
230 /* Check for bdap operand. */
231 if (cris_bdap_operand (op, mode))
232 return 1;
234 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
235 return 0;
237 /* Check that we're looking at a BIAP operand. */
238 if (code != MULT)
239 return 0;
241 /* Canonicalize register and multiplicand. */
242 if (GET_CODE (XEXP (op, 0)) == CONST_INT)
244 val = XEXP (op, 0);
245 reg = XEXP (op, 1);
247 else
249 val = XEXP (op, 1);
250 reg = XEXP (op, 0);
253 /* Check that the operands are correct after canonicalization. */
254 if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
255 return 0;
257 /* Check that the multiplicand has a valid value. */
258 if ((code == MULT
259 && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
260 return 1;
262 return 0;
265 /* Check if MODE is same as mode for X, and X is PLUS, MINUS, IOR or
266 AND or UMIN. */
269 cris_orthogonal_operator (x, mode)
270 rtx x;
271 enum machine_mode mode;
273 enum rtx_code code = GET_CODE (x);
275 if (mode == VOIDmode)
276 mode = GET_MODE (x);
278 return (GET_MODE (x) == mode
279 && (code == PLUS || code == MINUS
280 || code == IOR || code == AND || code == UMIN));
283 /* Check if MODE is same as mode for X, and X is PLUS, IOR or AND or
284 UMIN. */
287 cris_commutative_orth_op (x, mode)
288 rtx x;
289 enum machine_mode mode;
291 enum rtx_code code = GET_CODE (x);
293 if (mode == VOIDmode)
294 mode = GET_MODE (x);
296 return (GET_MODE (x) == mode &&
297 (code == PLUS
298 || code == IOR || code == AND || code == UMIN));
301 /* Check if MODE is same as mode for X, and X is PLUS or MINUS or UMIN. */
304 cris_operand_extend_operator (x, mode)
305 rtx x;
306 enum machine_mode mode;
308 enum rtx_code code = GET_CODE (x);
310 if (mode == VOIDmode)
311 mode = GET_MODE (x);
313 return (GET_MODE (x) == mode
314 && (code == PLUS || code == MINUS || code == UMIN));
317 /* Check to see if MODE is same as mode for X, and X is SIGN_EXTEND or
318 ZERO_EXTEND. */
321 cris_extend_operator (x, mode)
322 rtx x;
323 enum machine_mode mode;
325 enum rtx_code code = GET_CODE (x);
327 if (mode == VOIDmode)
328 mode = GET_MODE (x);
330 return
331 (GET_MODE (x) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
334 /* Check to see if MODE is same as mode for X, and X is PLUS or BOUND. */
337 cris_plus_or_bound_operator (x, mode)
338 rtx x;
339 enum machine_mode mode;
341 enum rtx_code code = GET_CODE (x);
343 if (mode == VOIDmode)
344 mode = GET_MODE (x);
346 return
347 (GET_MODE (x) == mode && (code == UMIN || code == PLUS));
350 /* Since with -fPIC, not all symbols are valid PIC symbols or indeed
351 general_operands, we have to have a predicate that matches it for the
352 "movsi" expander. */
355 cris_general_operand_or_symbol (op, mode)
356 rtx op;
357 enum machine_mode mode;
359 return general_operand (op, mode)
360 || (CONSTANT_P (op) && cris_symbol (op));
363 /* Since a PIC symbol without a GOT entry is not a general_operand, we
364 have to have a predicate that matches it. We use this in the expanded
365 "movsi" anonymous pattern for PIC symbols. */
368 cris_general_operand_or_gotless_symbol (op, mode)
369 rtx op;
370 enum machine_mode mode;
372 return general_operand (op, mode)
373 || (CONSTANT_P (op) && cris_gotless_symbol (op));
376 /* Since a PLT symbol is not a general_operand, we have to have a
377 predicate that matches it when we need it. We use this in the expanded
378 "call" and "call_value" anonymous patterns. */
381 cris_general_operand_or_plt_symbol (op, mode)
382 rtx op;
383 enum machine_mode mode;
385 return general_operand (op, mode)
386 || (GET_CODE (op) == CONST
387 && GET_CODE (XEXP (op, 0)) == UNSPEC
388 && !TARGET_AVOID_GOTPLT);
391 /* This matches a (MEM (general_operand)) or
392 (MEM (cris_general_operand_or_symbol)). The second one isn't a valid
393 memory_operand, so we need this predicate to recognize call
394 destinations before we change them to a PLT operand (by wrapping in
395 UNSPEC 0). */
398 cris_mem_call_operand (op, mode)
399 rtx op;
400 enum machine_mode mode;
402 rtx xmem;
404 if (GET_CODE (op) != MEM)
405 return 0;
407 if (memory_operand (op, mode))
408 return 1;
410 xmem = XEXP (op, 0);
412 return cris_general_operand_or_symbol (xmem, GET_MODE (op));
415 /* The CONDITIONAL_REGISTER_USAGE worker. */
417 void
418 cris_conditional_register_usage ()
420 /* FIXME: This isn't nice. We should be able to use that register for
421 something else if the PIC table isn't needed. */
422 if (flag_pic)
423 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
424 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
427 /* Return current_function_uses_pic_offset_table. For use in cris.md,
428 since some generated files do not include function.h. */
431 cris_cfun_uses_pic_table ()
433 return current_function_uses_pic_offset_table;
436 /* Given an rtx, return the text string corresponding to the CODE of X.
437 Intended for use in the assembly language output section of a
438 define_insn. */
440 const char *
441 cris_op_str (x)
442 rtx x;
444 cris_output_insn_is_bound = 0;
445 switch (GET_CODE (x))
447 case PLUS:
448 return "add";
449 break;
451 case MINUS:
452 return "sub";
453 break;
455 case MULT:
456 return "mul";
457 break;
459 case DIV:
460 return "div";
461 break;
463 case AND:
464 return "and";
465 break;
467 case IOR:
468 return "or";
469 break;
471 case XOR:
472 return "xor";
473 break;
475 case NOT:
476 return "not";
477 break;
479 case ASHIFT:
480 return "lsl";
481 break;
483 case LSHIFTRT:
484 return "lsr";
485 break;
487 case ASHIFTRT:
488 return "asr";
489 break;
491 case UMIN:
492 /* Used to control the sign/zero-extend character for the 'e' modifier.
493 BOUND has none. */
494 cris_output_insn_is_bound = 1;
495 return "bound";
496 break;
498 default:
499 return "Unknown operator";
500 break;
504 /* Emit an error message when we're in an asm, and a fatal error for
505 "normal" insns. Formatted output isn't easily implemented, since we
506 use output_operand_lossage to output the actual message and handle the
507 categorization of the error. */
509 static void
510 cris_operand_lossage (msg, op)
511 const char *msg;
512 rtx op;
514 debug_rtx (op);
515 output_operand_lossage (msg);
518 /* Print an index part of an address to file. */
520 static void
521 cris_print_index (index, file)
522 rtx index;
523 FILE * file;
525 rtx inner = XEXP (index, 0);
527 /* Make the index "additive" unless we'll output a negative number, in
528 which case the sign character is free (as in free beer). */
529 if (GET_CODE (index) != CONST_INT || INTVAL (index) >= 0)
530 putc ('+', file);
532 if (REG_P (index))
533 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
534 else if (CONSTANT_P (index))
535 cris_output_addr_const (file, index);
536 else if (GET_CODE (index) == MULT)
538 fprintf (file, "$%s.",
539 reg_names[REGNO (XEXP (index, 0))]);
541 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
543 else if (GET_CODE (index) == SIGN_EXTEND &&
544 GET_CODE (inner) == MEM)
546 rtx inner_inner = XEXP (inner, 0);
548 if (GET_CODE (inner_inner) == POST_INC)
550 fprintf (file, "[$%s+].",
551 reg_names[REGNO (XEXP (inner_inner, 0))]);
552 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
554 else
556 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
558 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
561 else if (GET_CODE (index) == MEM)
563 if (GET_CODE (inner) == POST_INC)
564 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
565 else
566 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
568 else
569 cris_operand_lossage ("unexpected index-type in cris_print_index",
570 index);
573 /* Print a base rtx of an address to file. */
575 static void
576 cris_print_base (base, file)
577 rtx base;
578 FILE *file;
580 if (REG_P (base))
581 fprintf (file, "$%s", reg_names[REGNO (base)]);
582 else if (GET_CODE (base) == POST_INC)
583 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
584 else
585 cris_operand_lossage ("unexpected base-type in cris_print_base",
586 base);
589 /* Usable as a guard in expressions. */
592 cris_fatal (arg)
593 char *arg;
595 internal_error (arg);
597 /* We'll never get here; this is just to appease compilers. */
598 return 0;
601 /* Textual function prologue. */
603 static void
604 cris_target_asm_function_prologue (file, size)
605 FILE *file;
606 HOST_WIDE_INT size;
608 int regno;
610 /* Shorten the used name for readability. */
611 int cfoa_size = current_function_outgoing_args_size;
612 int last_movem_reg = -1;
613 int doing_dwarf = dwarf2out_do_frame ();
614 int framesize;
615 int faked_args_size = 0;
616 int cfa_write_offset = 0;
617 char *cfa_label = NULL;
618 int return_address_on_stack
619 = regs_ever_live[CRIS_SRP_REGNUM]
620 || cfun->machine->needs_return_address_on_stack != 0;
622 /* Don't do anything if no prologues or epilogues are wanted. */
623 if (!TARGET_PROLOGUE_EPILOGUE)
624 return;
626 if (size < 0)
627 abort ();
629 /* Align the size to what's best for the CPU model. */
630 if (TARGET_STACK_ALIGN)
631 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
633 if (current_function_pretend_args_size)
635 int pretend = current_function_pretend_args_size;
636 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
637 pretend > 0;
638 regno--, pretend -= 4)
640 fprintf (file, "\tpush $%s\n", reg_names[regno]);
641 faked_args_size += 4;
645 framesize = faked_args_size;
647 if (doing_dwarf)
649 /* FIXME: Slightly redundant calculation, as we do the same in
650 pieces below. This offset must be the total adjustment of the
651 stack-pointer. We can then def_cfa call at the end of this
652 function with the current implementation of execute_cfa_insn, but
653 that wouldn't really be clean. */
655 int cfa_offset
656 = faked_args_size
657 + (return_address_on_stack ? 4 : 0)
658 + (frame_pointer_needed ? 4 : 0);
660 int cfa_reg;
662 if (frame_pointer_needed)
663 cfa_reg = FRAME_POINTER_REGNUM;
664 else
666 cfa_reg = STACK_POINTER_REGNUM;
667 cfa_offset += cris_initial_frame_pointer_offset ();
670 cfa_label = dwarf2out_cfi_label ();
671 dwarf2out_def_cfa (cfa_label, cfa_reg, cfa_offset);
673 cfa_write_offset = - faked_args_size - 4;
676 /* Save SRP if not a leaf function. */
677 if (return_address_on_stack)
679 fprintf (file, "\tPush $srp\n");
680 framesize += 4;
682 if (doing_dwarf)
684 dwarf2out_return_save (cfa_label, cfa_write_offset);
685 cfa_write_offset -= 4;
689 /* Set up frame pointer if needed. */
690 if (frame_pointer_needed)
692 fprintf (file, "\tpush $%s\n\tmove.d $sp,$%s\n",
693 reg_names[FRAME_POINTER_REGNUM],
694 reg_names[FRAME_POINTER_REGNUM]);
695 framesize += 4;
697 if (doing_dwarf)
699 dwarf2out_reg_save (cfa_label, FRAME_POINTER_REGNUM,
700 cfa_write_offset);
701 cfa_write_offset -= 4;
705 /* Local vars are located above saved regs. */
706 cfa_write_offset -= size;
708 /* Get a contiguous sequence of registers, starting with r0, that need
709 to be saved. */
710 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
712 if ((((regs_ever_live[regno]
713 && !call_used_regs[regno])
714 || (regno == PIC_OFFSET_TABLE_REGNUM
715 && (current_function_uses_pic_offset_table
716 /* It is saved anyway, if there would be a gap. */
717 || (flag_pic
718 && regs_ever_live[regno + 1]
719 && !call_used_regs[regno + 1]))))
720 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
721 && regno != CRIS_SRP_REGNUM)
722 || (current_function_calls_eh_return
723 && (regno == EH_RETURN_DATA_REGNO (0)
724 || regno == EH_RETURN_DATA_REGNO (1)
725 || regno == EH_RETURN_DATA_REGNO (2)
726 || regno == EH_RETURN_DATA_REGNO (3))))
728 /* Check if movem may be used for registers so far. */
729 if (regno == last_movem_reg + 1)
730 /* Yes, update next expected register. */
731 last_movem_reg++;
732 else
734 /* We cannot use movem for all registers. We have to flush
735 any movem:ed registers we got so far. */
736 if (last_movem_reg != -1)
738 /* It is a win to use a side-effect assignment for
739 64 <= size <= 128. But side-effect on movem was
740 not usable for CRIS v0..3. Also only do it if
741 side-effects insns are allowed. */
742 if ((last_movem_reg + 1) * 4 + size >= 64
743 && (last_movem_reg + 1) * 4 + size <= 128
744 && cris_cpu_version >= CRIS_CPU_SVINTO
745 && TARGET_SIDE_EFFECT_PREFIXES)
746 fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
747 reg_names[last_movem_reg],
748 (last_movem_reg + 1) * 4 + size);
749 else
751 /* Avoid printing multiple subsequent sub:s for sp. */
752 fprintf (file, "\tsub%s %d,$sp\n",
753 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1)
754 * 4 + size),
755 (last_movem_reg + 1) * 4 + size);
757 fprintf (file, "\tmovem $%s,[$sp]\n",
758 reg_names[last_movem_reg]);
761 framesize += (last_movem_reg + 1) * 4 + size;
763 if (TARGET_PDEBUG)
764 fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
765 size,
766 last_movem_reg + 1,
767 (last_movem_reg + 1) * 4,
768 current_function_args_size);
770 last_movem_reg = -1;
771 size = 0;
773 else if (size > 0)
775 /* Local vars on stack, but there are no movem:s.
776 Just allocate space. */
777 fprintf (file, "\tSub%s %d,$sp\n",
778 ADDITIVE_SIZE_MODIFIER (size),
779 size);
780 framesize += size;
781 size = 0;
784 fprintf (file, "\tPush $%s\n", reg_names[regno]);
785 framesize += 4;
788 if (doing_dwarf)
790 /* Registers are stored lowest numbered at highest address,
791 which matches the loop order; we just need to update the
792 write-offset. */
793 dwarf2out_reg_save (cfa_label, regno, cfa_write_offset);
794 cfa_write_offset -= 4;
799 /* Check after, if we can movem all registers. This is the normal
800 case. */
801 if (last_movem_reg != -1)
803 /* Side-effect assignment on movem was not supported for CRIS v0..3,
804 and don't do it if we're asked not to.
806 The movem is already accounted for, for unwind. */
808 if ((last_movem_reg + 1) * 4 + size >= 64
809 && (last_movem_reg + 1) * 4 + size <= 128
810 && cris_cpu_version >= CRIS_CPU_SVINTO
811 && TARGET_SIDE_EFFECT_PREFIXES)
812 fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
813 reg_names[last_movem_reg],
814 (last_movem_reg+1) * 4 + size);
815 else
817 /* Avoid printing multiple subsequent sub:s for sp. FIXME:
818 Clean up the conditional expression. */
819 fprintf (file, "\tsub%s %d,$sp\n",
820 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1) * 4 + size),
821 (last_movem_reg + 1) * 4 + size);
822 /* To be compatible with v0..v3 means we do not use an assignment
823 addressing mode with movem. We normally don't need that
824 anyway. It would only be slightly more efficient for 64..128
825 bytes frame size. */
826 fprintf (file, "\tmovem $%s,[$sp]\n", reg_names[last_movem_reg]);
829 framesize += (last_movem_reg + 1) * 4 + size;
831 if (TARGET_PDEBUG)
832 fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
833 size,
834 last_movem_reg + 1,
835 (last_movem_reg + 1) * 4,
836 current_function_args_size);
838 /* We have to put outgoing argument space after regs. */
839 if (cfoa_size)
841 /* This does not need to be accounted for, for unwind. */
843 fprintf (file, "\tSub%s %d,$sp\n",
844 ADDITIVE_SIZE_MODIFIER (cfoa_size),
845 cfoa_size);
846 framesize += cfoa_size;
849 else if ((size + cfoa_size) > 0)
851 /* This does not need to be accounted for, for unwind. */
853 /* Local vars on stack, and we could not use movem. Add a sub here. */
854 fprintf (file, "\tSub%s %d,$sp\n",
855 ADDITIVE_SIZE_MODIFIER (size + cfoa_size),
856 cfoa_size + size);
857 framesize += size + cfoa_size;
860 /* Set up the PIC register. */
861 if (current_function_uses_pic_offset_table)
862 asm_fprintf (file, "\tmove.d $pc,$%s\n\tsub.d .:GOTOFF,$%s\n",
863 reg_names[PIC_OFFSET_TABLE_REGNUM],
864 reg_names[PIC_OFFSET_TABLE_REGNUM]);
866 if (TARGET_PDEBUG)
867 fprintf (file,
868 "; parm #%d @ %d; frame %d, FP-SP is %d; leaf: %s%s; fp %s, outg: %d arg %d\n",
869 CRIS_MAX_ARGS_IN_REGS + 1, FIRST_PARM_OFFSET (0),
870 get_frame_size (),
871 cris_initial_frame_pointer_offset (),
872 leaf_function_p () ? "yes" : "no",
873 return_address_on_stack ? "no" :"yes",
874 frame_pointer_needed ? "yes" : "no",
875 cfoa_size, current_function_args_size);
877 if (cris_max_stackframe && framesize > cris_max_stackframe)
878 warning ("stackframe too big: %d bytes", framesize);
881 /* Return nonzero if there are regs mentioned in the insn that are not all
882 in the call_used regs. This is part of the decision whether an insn
883 can be put in the epilogue. */
885 static int
886 saved_regs_mentioned (x)
887 rtx x;
889 int i;
890 const char *fmt;
891 RTX_CODE code;
893 /* Mainly stolen from refers_to_regno_p in rtlanal.c. */
895 code = GET_CODE (x);
897 switch (code)
899 case REG:
900 i = REGNO (x);
901 return !call_used_regs[i];
903 case SUBREG:
904 /* If this is a SUBREG of a hard reg, we can see exactly which
905 registers are being modified. Otherwise, handle normally. */
906 i = REGNO (SUBREG_REG (x));
907 return !call_used_regs[i];
909 default:
913 fmt = GET_RTX_FORMAT (code);
914 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
916 if (fmt[i] == 'e')
918 if (saved_regs_mentioned (XEXP (x, i)))
919 return 1;
921 else if (fmt[i] == 'E')
923 int j;
924 for (j = XVECLEN (x, i) - 1; j >=0; j--)
925 if (saved_regs_mentioned (XEXP (x, i)))
926 return 1;
930 return 0;
933 /* Figure out if the insn may be put in the epilogue. */
936 cris_eligible_for_epilogue_delay (insn)
937 rtx insn;
939 /* First of all, it must be as slottable as for a delayed branch insn. */
940 if (get_attr_slottable (insn) != SLOTTABLE_YES)
941 return 0;
943 /* It must not refer to the stack pointer (may be valid for some cases
944 that I can't think of). */
945 if (reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)))
946 return 0;
948 /* The frame pointer will be restored in the epilogue, before the
949 "ret", so it can't be referred to. */
950 if (frame_pointer_needed
951 && reg_mentioned_p (frame_pointer_rtx, PATTERN (insn)))
952 return 0;
954 /* All saved regs are restored before the delayed insn.
955 This means that we cannot have any instructions that mention the
956 registers that are restored by the epilogue. */
957 if (saved_regs_mentioned (PATTERN (insn)))
958 return 0;
960 /* It seems to be ok. */
961 return 1;
964 /* Return the number of delay-slots in the epilogue: return 1 if it
965 contains "ret", else 0. */
968 cris_delay_slots_for_epilogue ()
970 /* Check if we use a return insn, which we only do for leaf functions.
971 Else there is no slot to fill. */
972 if (regs_ever_live[CRIS_SRP_REGNUM]
973 || cfun->machine->needs_return_address_on_stack != 0)
974 return 0;
976 /* By calling function_epilogue with the same parameters as from gcc
977 we can get info about if the epilogue can fill the delay-slot by itself.
978 If it is filled from the epilogue, then the corresponding string
979 is in save_last.
980 This depends on that the "size" argument to function_epilogue
981 always is get_frame_size.
982 FIXME: Kludgy. At least make it a separate function that is not
983 misnamed or abuses the stream parameter. */
984 cris_target_asm_function_epilogue (NULL, get_frame_size ());
986 if (*save_last)
987 return 1;
988 return 0;
991 /* Textual function epilogue. When file is NULL, it serves doubly as
992 a test for whether the epilogue can fill any "ret" delay-slots by
993 itself by storing the delay insn in save_last. */
995 static void
996 cris_target_asm_function_epilogue (file, size)
997 FILE *file;
998 HOST_WIDE_INT size;
1000 int regno;
1001 int last_movem_reg = -1;
1002 rtx insn = get_last_insn ();
1003 int argspace_offset = current_function_outgoing_args_size;
1004 int pretend = current_function_pretend_args_size;
1005 int return_address_on_stack
1006 = regs_ever_live[CRIS_SRP_REGNUM]
1007 || cfun->machine->needs_return_address_on_stack != 0;
1009 save_last[0] = 0;
1011 if (file && !TARGET_PROLOGUE_EPILOGUE)
1012 return;
1014 if (TARGET_PDEBUG && file)
1015 fprintf (file, ";;\n");
1017 /* Align byte count of stack frame. */
1018 if (TARGET_STACK_ALIGN)
1019 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
1021 /* If the last insn was a BARRIER, we don't have to write any code,
1022 then all returns were covered by "return" insns. */
1023 if (GET_CODE (insn) == NOTE)
1024 insn = prev_nonnote_insn (insn);
1025 if (insn
1026 && (GET_CODE (insn) == BARRIER
1027 /* We must make sure that the insn really is a "return" and
1028 not a conditional branch. Try to match the return exactly,
1029 and if it doesn't match, assume it is a conditional branch
1030 (and output an epilogue). */
1031 || (GET_CODE (insn) == JUMP_INSN
1032 && GET_CODE (PATTERN (insn)) == RETURN)))
1034 if (TARGET_PDEBUG && file)
1035 fprintf (file, ";;;;;\n");
1036 return;
1039 /* Check how many saved regs we can movem. They start at r0 and must
1040 be contiguous. */
1041 for (regno = 0;
1042 regno < FIRST_PSEUDO_REGISTER;
1043 regno++)
1044 if ((((regs_ever_live[regno]
1045 && !call_used_regs[regno])
1046 || (regno == PIC_OFFSET_TABLE_REGNUM
1047 && (current_function_uses_pic_offset_table
1048 /* It is saved anyway, if there would be a gap. */
1049 || (flag_pic
1050 && regs_ever_live[regno + 1]
1051 && !call_used_regs[regno + 1]))))
1052 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1053 && regno != CRIS_SRP_REGNUM)
1054 || (current_function_calls_eh_return
1055 && (regno == EH_RETURN_DATA_REGNO (0)
1056 || regno == EH_RETURN_DATA_REGNO (1)
1057 || regno == EH_RETURN_DATA_REGNO (2)
1058 || regno == EH_RETURN_DATA_REGNO (3))))
1061 if (regno == last_movem_reg + 1)
1062 last_movem_reg++;
1063 else
1064 break;
1067 for (regno = FIRST_PSEUDO_REGISTER - 1;
1068 regno > last_movem_reg;
1069 regno--)
1070 if ((((regs_ever_live[regno]
1071 && !call_used_regs[regno])
1072 || (regno == PIC_OFFSET_TABLE_REGNUM
1073 && (current_function_uses_pic_offset_table
1074 /* It is saved anyway, if there would be a gap. */
1075 || (flag_pic
1076 && regs_ever_live[regno + 1]
1077 && !call_used_regs[regno + 1]))))
1078 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1079 && regno != CRIS_SRP_REGNUM)
1080 || (current_function_calls_eh_return
1081 && (regno == EH_RETURN_DATA_REGNO (0)
1082 || regno == EH_RETURN_DATA_REGNO (1)
1083 || regno == EH_RETURN_DATA_REGNO (2)
1084 || regno == EH_RETURN_DATA_REGNO (3))))
1086 if (argspace_offset)
1088 /* There is an area for outgoing parameters located before
1089 the saved registers. We have to adjust for that. */
1090 if (file)
1091 fprintf (file, "\tAdd%s %d,$sp\n",
1092 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1093 argspace_offset);
1095 /* Make sure we only do this once. */
1096 argspace_offset = 0;
1099 /* Flush previous non-movem:ed registers. */
1100 if (*save_last && file)
1101 fprintf (file, save_last);
1102 sprintf (save_last, "\tPop $%s\n", reg_names[regno]);
1105 if (last_movem_reg != -1)
1107 if (argspace_offset)
1109 /* Adjust for the outgoing parameters area, if that's not
1110 handled yet. */
1111 if (*save_last && file)
1113 fprintf (file, save_last);
1114 *save_last = 0;
1117 if (file)
1118 fprintf (file, "\tAdd%s %d,$sp\n",
1119 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1120 argspace_offset);
1121 argspace_offset = 0;
1123 /* Flush previous non-movem:ed registers. */
1124 else if (*save_last && file)
1125 fprintf (file, save_last);
1126 sprintf (save_last, "\tmovem [$sp+],$%s\n", reg_names[last_movem_reg]);
1129 /* Restore frame pointer if necessary. */
1130 if (frame_pointer_needed)
1132 if (*save_last && file)
1133 fprintf (file, save_last);
1135 if (file)
1136 fprintf (file, "\tmove.d $%s,$sp\n",
1137 reg_names[FRAME_POINTER_REGNUM]);
1138 sprintf (save_last, "\tPop $%s\n",
1139 reg_names[FRAME_POINTER_REGNUM]);
1141 else
1143 /* If there was no frame-pointer to restore sp from, we must
1144 explicitly deallocate local variables. */
1146 /* Handle space for outgoing parameters that hasn't been handled
1147 yet. */
1148 size += argspace_offset;
1150 if (size)
1152 if (*save_last && file)
1153 fprintf (file, save_last);
1155 sprintf (save_last, "\tadd%s %d,$sp\n",
1156 ADDITIVE_SIZE_MODIFIER (size), size);
1159 /* If the size was not in the range for a "quick", we must flush
1160 it here. */
1161 if (size > 63)
1163 if (file)
1164 fprintf (file, save_last);
1165 *save_last = 0;
1169 /* If this function has no pushed register parameters
1170 (stdargs/varargs), and if it is not a leaf function, then we can
1171 just jump-return here. */
1172 if (return_address_on_stack && pretend == 0)
1174 if (*save_last && file)
1175 fprintf (file, save_last);
1176 *save_last = 0;
1178 if (file)
1180 if (current_function_calls_eh_return)
1182 /* The installed EH-return address is in *this* frame, so we
1183 need to pop it before we return. */
1184 fprintf (file, "\tpop $srp\n");
1185 fprintf (file, "\tret\n");
1186 fprintf (file, "\tadd.d $%s,$sp\n", reg_names[CRIS_STACKADJ_REG]);
1188 else
1189 fprintf (file, "\tJump [$sp+]\n");
1191 /* Do a sanity check to avoid generating invalid code. */
1192 if (current_function_epilogue_delay_list)
1193 internal_error ("allocated but unused delay list in epilogue");
1195 return;
1198 /* Rather than add current_function_calls_eh_return conditions
1199 everywhere in the following code (and not be able to test it
1200 thoroughly), assert the assumption that all usage of
1201 __builtin_eh_return are handled above. */
1202 if (current_function_calls_eh_return)
1203 internal_error ("unexpected function type needing stack adjustment for\
1204 __builtin_eh_return");
1206 /* If we pushed some register parameters, then adjust the stack for
1207 them. */
1208 if (pretend)
1210 /* Since srp is stored on the way, we need to restore it first. */
1211 if (return_address_on_stack)
1213 if (*save_last && file)
1214 fprintf (file, save_last);
1215 *save_last = 0;
1217 if (file)
1218 fprintf (file, "\tpop $srp\n");
1221 if (*save_last && file)
1222 fprintf (file, save_last);
1224 sprintf (save_last, "\tadd%s %d,$sp\n",
1225 ADDITIVE_SIZE_MODIFIER (pretend), pretend);
1228 /* Here's where we have a delay-slot we need to fill. */
1229 if (file && current_function_epilogue_delay_list)
1231 /* If gcc has allocated an insn for the epilogue delay slot, but
1232 things were arranged so we now thought we could do it
1233 ourselves, don't forget to flush that insn. */
1234 if (*save_last)
1235 fprintf (file, save_last);
1237 fprintf (file, "\tRet\n");
1239 /* Output the delay-slot-insn the mandated way. */
1240 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1241 file, 1, -2, 1);
1243 else if (file)
1245 fprintf (file, "\tRet\n");
1247 /* If the GCC did not do it, we have to use whatever insn we have,
1248 or a nop. */
1249 if (*save_last)
1250 fprintf (file, save_last);
1251 else
1252 fprintf (file, "\tnOp\n");
1256 /* The PRINT_OPERAND worker. */
1258 void
1259 cris_print_operand (file, x, code)
1260 FILE *file;
1261 rtx x;
1262 int code;
1264 rtx operand = x;
1266 /* Size-strings corresponding to MULT expressions. */
1267 static const char *mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
1269 /* New code entries should just be added to the switch below. If
1270 handling is finished, just return. If handling was just a
1271 modification of the operand, the modified operand should be put in
1272 "operand", and then do a break to let default handling
1273 (zero-modifier) output the operand. */
1275 switch (code)
1277 case 'b':
1278 /* Print the unsigned supplied integer as if it was signed
1279 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
1280 if (GET_CODE (x) != CONST_INT
1281 || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
1282 LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
1283 fprintf (file, "%d", INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
1284 return;
1286 case 'x':
1287 /* Print assembler code for operator. */
1288 fprintf (file, "%s", cris_op_str (operand));
1289 return;
1291 case 'v':
1292 /* Print the operand without the PIC register. */
1293 if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1294 LOSE_AND_RETURN ("invalid operand for 'v' modifier", x);
1295 cris_pic_sympart_only++;
1296 cris_output_addr_const (file, x);
1297 cris_pic_sympart_only--;
1298 return;
1300 case 'P':
1301 /* Print the PIC register. Applied to a GOT-less PIC symbol for
1302 sanity. */
1303 if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1304 LOSE_AND_RETURN ("invalid operand for 'P' modifier", x);
1305 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
1306 return;
1308 case 'p':
1309 /* Adjust a power of two to its log2. */
1310 if (GET_CODE (x) != CONST_INT || exact_log2 (INTVAL (x)) < 0 )
1311 LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
1312 fprintf (file, "%d", exact_log2 (INTVAL (x)));
1313 return;
1315 case 's':
1316 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
1317 respectively. This modifier also terminates the inhibiting
1318 effects of the 'x' modifier. */
1319 cris_output_insn_is_bound = 0;
1320 if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
1322 if (INTVAL (x) >= 0)
1324 if (INTVAL (x) <= 255)
1325 putc ('b', file);
1326 else if (INTVAL (x) <= 65535)
1327 putc ('w', file);
1328 else
1329 putc ('d', file);
1331 else
1332 putc ('d', file);
1333 return;
1336 /* For a non-integer, print the size of the operand. */
1337 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
1338 ? 'd' : GET_MODE (x) == HImode ? 'w'
1339 : GET_MODE (x) == QImode ? 'b'
1340 /* If none of the above, emit an erroneous size letter. */
1341 : 'X',
1342 file);
1343 return;
1345 case 'z':
1346 /* Const_int: print b for -127 <= x <= 255,
1347 w for -32768 <= x <= 65535, else abort. */
1348 if (GET_CODE (x) != CONST_INT
1349 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
1350 LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
1351 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
1352 return;
1354 case '#':
1355 /* Output a 'nop' if there's nothing for the delay slot.
1356 This method stolen from the sparc files. */
1357 if (dbr_sequence_length () == 0)
1358 fputs ("\n\tnop", file);
1359 return;
1361 case 'H':
1362 /* Print high (most significant) part of something. */
1363 switch (GET_CODE (operand))
1365 case CONST_INT:
1366 /* Sign-extension from a normal int to a long long. */
1367 fprintf (file, INTVAL (operand) < 0 ? "-1" : "0");
1368 return;
1370 case CONST_DOUBLE:
1371 /* High part of a long long constant. */
1372 if (GET_MODE (operand) == VOIDmode)
1374 fprintf (file, "0x%x", CONST_DOUBLE_HIGH (x));
1375 return;
1377 else
1378 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1380 case REG:
1381 /* Print reg + 1. Check that there's not an attempt to print
1382 high-parts of registers like stack-pointer or higher. */
1383 if (REGNO (operand) > STACK_POINTER_REGNUM - 2)
1384 LOSE_AND_RETURN ("bad register", operand);
1385 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
1386 return;
1388 case MEM:
1389 /* Adjust memory address to high part. */
1391 rtx adj_mem = operand;
1392 int size
1393 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
1395 /* Adjust so we can use two SImode in DImode.
1396 Calling adj_offsettable_operand will make sure it is an
1397 offsettable address. Don't do this for a postincrement
1398 though; it should remain as it was. */
1399 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
1400 adj_mem
1401 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
1403 output_address (XEXP (adj_mem, 0));
1404 return;
1407 default:
1408 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1411 case 'L':
1412 /* Strip the MEM expression. */
1413 operand = XEXP (operand, 0);
1414 break;
1416 case 'e':
1417 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
1418 cris_output_insn_is_bound is nonzero. */
1419 if (GET_CODE (operand) != SIGN_EXTEND
1420 && GET_CODE (operand) != ZERO_EXTEND
1421 && GET_CODE (operand) != CONST_INT)
1422 LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
1424 if (cris_output_insn_is_bound)
1426 cris_output_insn_is_bound = 0;
1427 return;
1430 putc (GET_CODE (operand) == SIGN_EXTEND
1431 || (GET_CODE (operand) == CONST_INT && INTVAL (operand) < 0)
1432 ? 's' : 'u', file);
1433 return;
1435 case 'm':
1436 /* Print the size letter of the inner element. We can do it by
1437 calling ourselves with the 's' modifier. */
1438 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
1439 LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
1440 cris_print_operand (file, XEXP (operand, 0), 's');
1441 return;
1443 case 'M':
1444 /* Print the least significant part of operand. */
1445 if (GET_CODE (operand) == CONST_DOUBLE)
1447 fprintf (file, "0x%x", CONST_DOUBLE_LOW (x));
1448 return;
1450 /* If not a CONST_DOUBLE, the least significant part equals the
1451 normal part, so handle it normally. */
1452 break;
1454 case 'A':
1455 /* When emitting an add for the high part of a DImode constant, we
1456 want to use addq for 0 and adds.w for -1. */
1457 if (GET_CODE (operand) != CONST_INT)
1458 LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
1459 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
1460 return;
1462 case 'D':
1463 /* When emitting an sub for the high part of a DImode constant, we
1464 want to use subq for 0 and subs.w for -1. */
1465 if (GET_CODE (operand) != CONST_INT)
1466 LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
1467 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
1468 return;
1470 case 'S':
1471 /* Print the operand as the index-part of an address.
1472 Easiest way out is to use cris_print_index. */
1473 cris_print_index (operand, file);
1474 return;
1476 case 'T':
1477 /* Print the size letter for an operand to a MULT, which must be a
1478 const_int with a suitable value. */
1479 if (GET_CODE (operand) != CONST_INT || INTVAL (operand) > 4)
1480 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
1481 fprintf (file, "%s", mults[INTVAL (operand)]);
1482 return;
1484 case 0:
1485 /* No code, print as usual. */
1486 break;
1488 default:
1489 LOSE_AND_RETURN ("invalid operand modifier letter", x);
1492 /* Print an operand as without a modifier letter. */
1493 switch (GET_CODE (operand))
1495 case REG:
1496 if (REGNO (operand) > 15)
1497 internal_error ("internal error: bad register: %d", REGNO (operand));
1498 fprintf (file, "$%s", reg_names[REGNO (operand)]);
1499 return;
1501 case MEM:
1502 output_address (XEXP (operand, 0));
1503 return;
1505 case CONST_DOUBLE:
1506 if (GET_MODE (operand) == VOIDmode)
1507 /* A long long constant. */
1508 output_addr_const (file, operand);
1509 else
1511 /* Only single precision is allowed as plain operands the
1512 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
1513 documented. */
1514 REAL_VALUE_TYPE r;
1515 long l;
1517 /* FIXME: Perhaps check overflow of the "single". */
1518 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1519 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1521 fprintf (file, "0x%lx", l);
1523 return;
1525 case UNSPEC:
1526 ASSERT_PLT_UNSPEC (operand);
1527 /* Fall through. */
1529 case CONST:
1530 cris_output_addr_const (file, operand);
1531 return;
1533 case MULT:
1534 case ASHIFT:
1536 /* For a (MULT (reg X) const_int) we output "rX.S". */
1537 int i = GET_CODE (XEXP (operand, 1)) == CONST_INT
1538 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1539 rtx reg = GET_CODE (XEXP (operand, 1)) == CONST_INT
1540 ? XEXP (operand, 0) : XEXP (operand, 1);
1542 if (GET_CODE (reg) != REG
1543 || (GET_CODE (XEXP (operand, 0)) != CONST_INT
1544 && GET_CODE (XEXP (operand, 1)) != CONST_INT))
1545 LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1547 cris_print_base (reg, file);
1548 fprintf (file, ".%c",
1549 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1550 : i == 4 ? 'd'
1551 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1552 : 'd');
1553 return;
1556 default:
1557 /* No need to handle all strange variants, let output_addr_const
1558 do it for us. */
1559 if (CONSTANT_P (operand))
1561 cris_output_addr_const (file, operand);
1562 return;
1565 LOSE_AND_RETURN ("unexpected operand", x);
1569 /* The PRINT_OPERAND_ADDRESS worker. */
1571 void
1572 cris_print_operand_address (file, x)
1573 FILE *file;
1574 rtx x;
1576 /* All these were inside MEM:s so output indirection characters. */
1577 putc ('[', file);
1579 if (CONSTANT_ADDRESS_P (x))
1580 cris_output_addr_const (file, x);
1581 else if (BASE_OR_AUTOINCR_P (x))
1582 cris_print_base (x, file);
1583 else if (GET_CODE (x) == PLUS)
1585 rtx x1, x2;
1587 x1 = XEXP (x, 0);
1588 x2 = XEXP (x, 1);
1589 if (BASE_P (x1))
1591 cris_print_base (x1, file);
1592 cris_print_index (x2, file);
1594 else if (BASE_P (x2))
1596 cris_print_base (x2, file);
1597 cris_print_index (x1, file);
1599 else
1600 LOSE_AND_RETURN ("unrecognized address", x);
1602 else if (GET_CODE (x) == MEM)
1604 /* A DIP. Output more indirection characters. */
1605 putc ('[', file);
1606 cris_print_base (XEXP (x, 0), file);
1607 putc (']', file);
1609 else
1610 LOSE_AND_RETURN ("unrecognized address", x);
1612 putc (']', file);
1615 /* The RETURN_ADDR_RTX worker.
1616 We mark that the return address is used, either by EH or
1617 __builtin_return_address, for use by the function prologue and
1618 epilogue. FIXME: This isn't optimal; we just use the mark in the
1619 prologue and epilogue to say that the return address is to be stored
1620 in the stack frame. We could return SRP for leaf-functions and use the
1621 initial-value machinery. */
1624 cris_return_addr_rtx (count, frameaddr)
1625 int count;
1626 rtx frameaddr ATTRIBUTE_UNUSED;
1628 cfun->machine->needs_return_address_on_stack = 1;
1630 /* The return-address is stored just above the saved frame-pointer (if
1631 present). Apparently we can't eliminate from the frame-pointer in
1632 that direction, so use the incoming args (maybe pretended) pointer. */
1633 return count == 0
1634 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1635 : NULL_RTX;
1638 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1639 handles FP -> SP elimination offset. */
1641 static int
1642 cris_initial_frame_pointer_offset ()
1644 int regno;
1646 /* Initial offset is 0 if we don't have a frame pointer. */
1647 int offs = 0;
1649 /* And 4 for each register pushed. */
1650 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1651 if ((((regs_ever_live[regno]
1652 && !call_used_regs[regno])
1653 || (regno == PIC_OFFSET_TABLE_REGNUM
1654 && (current_function_uses_pic_offset_table
1655 /* It is saved anyway, if there would be a gap. */
1656 || (flag_pic
1657 && regs_ever_live[regno + 1]
1658 && !call_used_regs[regno + 1]))))
1659 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1660 && regno != CRIS_SRP_REGNUM)
1661 || (current_function_calls_eh_return
1662 && (regno == EH_RETURN_DATA_REGNO (0)
1663 || regno == EH_RETURN_DATA_REGNO (1)
1664 || regno == EH_RETURN_DATA_REGNO (2)
1665 || regno == EH_RETURN_DATA_REGNO (3))))
1666 offs += 4;
1668 /* And then, last, we add the locals allocated. */
1669 offs += get_frame_size ();
1671 /* And more; the accumulated args size. */
1672 offs += current_function_outgoing_args_size;
1674 /* Then round it off, in case we use aligned stack. */
1675 if (TARGET_STACK_ALIGN)
1676 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1678 return offs;
1681 /* The INITIAL_ELIMINATION_OFFSET worker.
1682 Calculate the difference between imaginary registers such as frame
1683 pointer and the stack pointer. Used to eliminate the frame pointer
1684 and imaginary arg pointer. */
1687 cris_initial_elimination_offset (fromreg, toreg)
1688 int fromreg;
1689 int toreg;
1691 int fp_sp_offset
1692 = cris_initial_frame_pointer_offset ();
1694 /* We should be able to use regs_ever_live and related prologue
1695 information here, or alpha should not as well. */
1696 int return_address_on_stack
1697 = regs_ever_live[CRIS_SRP_REGNUM]
1698 || cfun->machine->needs_return_address_on_stack != 0;
1700 /* Here we act as if the frame-pointer is needed. */
1701 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1703 if (fromreg == ARG_POINTER_REGNUM
1704 && toreg == FRAME_POINTER_REGNUM)
1705 return ap_fp_offset;
1707 /* Between the frame pointer and the stack are only "normal" stack
1708 variables and saved registers. */
1709 if (fromreg == FRAME_POINTER_REGNUM
1710 && toreg == STACK_POINTER_REGNUM)
1711 return fp_sp_offset;
1713 /* We need to balance out the frame pointer here. */
1714 if (fromreg == ARG_POINTER_REGNUM
1715 && toreg == STACK_POINTER_REGNUM)
1716 return ap_fp_offset + fp_sp_offset - 4;
1718 abort ();
1721 /* This function looks into the pattern to see how this insn affects
1722 condition codes.
1724 Used when to eliminate test insns before a condition-code user,
1725 such as a "scc" insn or a conditional branch. This includes
1726 checking if the entities that cc was updated by, are changed by the
1727 operation.
1729 Currently a jumble of the old peek-inside-the-insn and the newer
1730 check-cc-attribute methods. */
1732 void
1733 cris_notice_update_cc (exp, insn)
1734 rtx exp;
1735 rtx insn;
1737 /* Check if user specified "-mcc-init" as a bug-workaround. FIXME:
1738 TARGET_CCINIT does not work; we must set CC_REVERSED as below.
1739 Several test-cases will otherwise fail, for example
1740 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1741 if (TARGET_CCINIT)
1743 CC_STATUS_INIT;
1744 return;
1747 /* Slowly, we're converting to using attributes to control the setting
1748 of condition-code status. */
1749 switch (get_attr_cc (insn))
1751 case CC_NONE:
1752 /* Even if it is "none", a setting may clobber a previous
1753 cc-value, so check. */
1754 if (GET_CODE (exp) == SET)
1756 if (cc_status.value1
1757 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1758 cc_status.value1))
1759 cc_status.value1 = 0;
1761 if (cc_status.value2
1762 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1763 cc_status.value2))
1764 cc_status.value2 = 0;
1766 return;
1768 case CC_CLOBBER:
1769 CC_STATUS_INIT;
1770 break;
1772 case CC_NORMAL:
1773 /* Which means, for:
1774 (set (cc0) (...)):
1775 CC is (...).
1777 (set (reg) (...)):
1778 CC is (reg) and (...) - unless (...) is 0, then CC does not change.
1779 CC_NO_OVERFLOW unless (...) is reg or mem.
1781 (set (mem) (...)):
1782 CC does not change.
1784 (set (pc) (...)):
1785 CC does not change.
1787 (parallel
1788 (set (reg1) (mem (bdap/biap)))
1789 (set (reg2) (bdap/biap))):
1790 CC is (reg1) and (mem (reg2))
1792 (parallel
1793 (set (mem (bdap/biap)) (reg1)) [or 0]
1794 (set (reg2) (bdap/biap))):
1795 CC does not change.
1797 (where reg and mem includes strict_low_parts variants thereof)
1799 For all others, assume CC is clobbered.
1800 Note that we do not have to care about setting CC_NO_OVERFLOW,
1801 since the overflow flag is set to 0 (i.e. right) for
1802 instructions where it does not have any sane sense, but where
1803 other flags have meanings. (This includes shifts; the carry is
1804 not set by them).
1806 Note that there are other parallel constructs we could match,
1807 but we don't do that yet. */
1809 if (GET_CODE (exp) == SET)
1811 /* FIXME: Check when this happens. It looks like we should
1812 actually do a CC_STATUS_INIT here to be safe. */
1813 if (SET_DEST (exp) == pc_rtx)
1814 return;
1816 /* Record CC0 changes, so we do not have to output multiple
1817 test insns. */
1818 if (SET_DEST (exp) == cc0_rtx)
1820 cc_status.value1 = SET_SRC (exp);
1821 cc_status.value2 = 0;
1823 /* Handle flags for the special btstq on one bit. */
1824 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1825 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1827 if (GET_CODE (XEXP (SET_SRC (exp), 0)) == CONST_INT)
1828 /* Using cmpq. */
1829 cc_status.flags = CC_INVERTED;
1830 else
1831 /* A one-bit btstq. */
1832 cc_status.flags = CC_Z_IN_NOT_N;
1834 else
1835 cc_status.flags = 0;
1837 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1839 if (!REG_P (XEXP (SET_SRC (exp), 0))
1840 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1841 /* For some reason gcc will not canonicalize compare
1842 operations, reversing the sign by itself if
1843 operands are in wrong order. */
1844 /* (But NOT inverted; eq is still eq.) */
1845 cc_status.flags = CC_REVERSED;
1847 /* This seems to be overlooked by gcc. FIXME: Check again.
1848 FIXME: Is it really safe? */
1849 cc_status.value2
1850 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1851 XEXP (SET_SRC (exp), 0),
1852 XEXP (SET_SRC (exp), 1));
1854 return;
1856 else if (REG_P (SET_DEST (exp))
1857 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1858 && REG_P (XEXP (SET_DEST (exp), 0))))
1860 /* A register is set; normally CC is set to show that no
1861 test insn is needed. Catch the exceptions. */
1863 /* If not to cc0, then no "set"s in non-natural mode give
1864 ok cc0... */
1865 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1866 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1868 /* ... except add:s and sub:s in DImode. */
1869 if (GET_MODE (SET_DEST (exp)) == DImode
1870 && (GET_CODE (SET_SRC (exp)) == PLUS
1871 || GET_CODE (SET_SRC (exp)) == MINUS))
1873 cc_status.flags = 0;
1874 cc_status.value1 = SET_DEST (exp);
1875 cc_status.value2 = SET_SRC (exp);
1877 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1878 cc_status.value2))
1879 cc_status.value2 = 0;
1881 /* Add and sub may set V, which gets us
1882 unoptimizable results in "gt" and "le" condition
1883 codes. */
1884 cc_status.flags |= CC_NO_OVERFLOW;
1886 return;
1889 else if (SET_SRC (exp) == const0_rtx)
1891 /* There's no CC0 change when clearing a register or
1892 memory. Just check for overlap. */
1893 if ((cc_status.value1
1894 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1895 cc_status.value1)))
1896 cc_status.value1 = 0;
1898 if ((cc_status.value2
1899 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1900 cc_status.value2)))
1901 cc_status.value2 = 0;
1903 return;
1905 else
1907 cc_status.flags = 0;
1908 cc_status.value1 = SET_DEST (exp);
1909 cc_status.value2 = SET_SRC (exp);
1911 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1912 cc_status.value2))
1913 cc_status.value2 = 0;
1915 /* Some operations may set V, which gets us
1916 unoptimizable results in "gt" and "le" condition
1917 codes. */
1918 if (GET_CODE (SET_SRC (exp)) == PLUS
1919 || GET_CODE (SET_SRC (exp)) == MINUS
1920 || GET_CODE (SET_SRC (exp)) == NEG)
1921 cc_status.flags |= CC_NO_OVERFLOW;
1923 return;
1926 else if (GET_CODE (SET_DEST (exp)) == MEM
1927 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1928 && GET_CODE (XEXP (SET_DEST (exp), 0)) == MEM))
1930 /* When SET to MEM, then CC is not changed (except for
1931 overlap). */
1932 if ((cc_status.value1
1933 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1934 cc_status.value1)))
1935 cc_status.value1 = 0;
1937 if ((cc_status.value2
1938 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1939 cc_status.value2)))
1940 cc_status.value2 = 0;
1942 return;
1945 else if (GET_CODE (exp) == PARALLEL)
1947 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1948 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1949 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1951 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1952 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 1)) == MEM)
1954 /* For "move.S [rx=ry+o],rz", say CC reflects
1955 value1=rz and value2=[rx] */
1956 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1957 cc_status.value2
1958 = gen_rtx_MEM (GET_MODE (XEXP (XVECEXP (exp, 0, 0), 0)),
1959 XEXP (XVECEXP (exp, 0, 1), 0));
1960 cc_status.flags = 0;
1962 /* Huh? A side-effect cannot change the destination
1963 register. */
1964 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1965 cc_status.value2))
1966 internal_error ("internal error: sideeffect-insn affecting main effect");
1967 return;
1969 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1970 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1971 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 0)) == MEM)
1973 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1974 say flags are not changed, except for overlap. */
1975 if (cc_status.value1
1976 && cris_reg_overlap_mentioned_p (XEXP
1977 (XVECEXP
1978 (exp, 0, 0), 0),
1979 cc_status.value1))
1980 cc_status.value1 = 0;
1982 if (cc_status.value1
1983 && cris_reg_overlap_mentioned_p (XEXP
1984 (XVECEXP
1985 (exp, 0, 1), 0),
1986 cc_status.value1))
1987 cc_status.value1 = 0;
1989 if (cc_status.value2
1990 && cris_reg_overlap_mentioned_p (XEXP
1991 (XVECEXP
1992 (exp, 0, 0), 0),
1993 cc_status.value2))
1994 cc_status.value2 = 0;
1996 if (cc_status.value2
1997 && cris_reg_overlap_mentioned_p (XEXP
1998 (XVECEXP
1999 (exp, 0, 1), 0),
2000 cc_status.value2))
2001 cc_status.value2 = 0;
2003 return;
2007 break;
2009 default:
2010 /* Unknown cc_attr value. */
2011 abort ();
2014 CC_STATUS_INIT;
2017 /* Return != 0 if the return sequence for the current function is short,
2018 like "ret" or "jump [sp+]". Prior to reloading, we can't tell how
2019 many registers must be saved, so return 0 then. */
2022 cris_simple_epilogue ()
2024 int regno;
2025 int reglimit = STACK_POINTER_REGNUM;
2026 int lastreg = -1;
2028 if (! reload_completed
2029 || frame_pointer_needed
2030 || get_frame_size () != 0
2031 || current_function_pretend_args_size
2032 || current_function_args_size
2033 || current_function_outgoing_args_size
2034 || current_function_calls_eh_return
2036 /* If we're not supposed to emit prologue and epilogue, we must
2037 not emit return-type instructions. */
2038 || !TARGET_PROLOGUE_EPILOGUE)
2039 return 0;
2041 /* We allow a "movem [sp+],rN" to sit in front if the "jump [sp+]" or
2042 in the delay-slot of the "ret". */
2043 for (regno = 0; regno < reglimit; regno++)
2044 if ((regs_ever_live[regno] && ! call_used_regs[regno])
2045 || (regno == PIC_OFFSET_TABLE_REGNUM
2046 && (current_function_uses_pic_offset_table
2047 /* It is saved anyway, if there would be a gap. */
2048 || (flag_pic
2049 && regs_ever_live[regno + 1]
2050 && !call_used_regs[regno + 1]))))
2052 if (lastreg != regno - 1)
2053 return 0;
2054 lastreg = regno;
2057 return 1;
2060 /* The ADDRESS_COST worker. */
2063 cris_address_cost (x)
2064 rtx x;
2066 /* The metric to use for the cost-macros is unclear.
2067 The metric used here is (the number of cycles needed) / 2,
2068 where we consider equal a cycle for a word of code and a cycle to
2069 read memory. */
2071 /* The cheapest addressing modes get 0, since nothing extra is needed. */
2072 if (BASE_OR_AUTOINCR_P (x))
2073 return 0;
2075 /* An indirect mem must be a DIP. This means two bytes extra for code,
2076 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
2077 if (GET_CODE (x) == MEM)
2078 return (2 + 4) / 2;
2080 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
2081 an extra DIP prefix and 4 bytes of constant in most cases.
2082 For PIC and a symbol with a GOT entry, we double the cost since we
2083 add a [rPIC+...] offset. A GOT-less symbol uses a BDAP prefix
2084 equivalent to the DIP prefix for non-PIC, hence the same cost. */
2085 if (CONSTANT_P (x))
2086 return flag_pic && cris_got_symbol (x) ? 2 * (2 + 4) / 2 : (2 + 4) / 2;
2088 /* Handle BIAP and BDAP prefixes. */
2089 if (GET_CODE (x) == PLUS)
2091 rtx tem1 = XEXP (x, 0);
2092 rtx tem2 = XEXP (x, 1);
2094 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
2095 recognize the typical MULT which is always in tem1 because of
2096 insn canonicalization. */
2097 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
2098 || REG_P (tem1))
2099 return 2 / 2;
2101 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
2102 PLUS is always found in tem2. */
2103 if (GET_CODE (tem2) == CONST_INT
2104 && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
2105 return 2 / 2;
2107 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2108 bytes. */
2109 if (GET_CODE (tem2) == CONST_INT
2110 && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
2111 return (2 + 2) / 2;
2113 /* A BDAP with some other constant is 2 bytes extra. */
2114 if (CONSTANT_P (tem2))
2115 return (2 + 2 + 2) / 2;
2117 /* BDAP with something indirect should have a higher cost than
2118 BIAP with register. FIXME: Should it cost like a MEM or more? */
2119 /* Don't need to check it, it's the only one left.
2120 FIXME: There was a REG test missing, perhaps there are others.
2121 Think more. */
2122 return (2 + 2 + 2) / 2;
2125 /* What else? Return a high cost. It matters only for valid
2126 addressing modes. */
2127 return 10;
2130 /* Check various objections to the side-effect. Used in the test-part
2131 of an anonymous insn describing an insn with a possible side-effect.
2132 Returns nonzero if the implied side-effect is ok.
2134 code : PLUS or MULT
2135 ops : An array of rtx:es. lreg, rreg, rval,
2136 The variables multop and other_op are indexes into this,
2137 or -1 if they are not applicable.
2138 lreg : The register that gets assigned in the side-effect.
2139 rreg : One register in the side-effect expression
2140 rval : The other register, or an int.
2141 multop : An integer to multiply rval with.
2142 other_op : One of the entities of the main effect,
2143 whose mode we must consider. */
2146 cris_side_effect_mode_ok (code, ops, lreg, rreg, rval, multop, other_op)
2147 enum rtx_code code;
2148 rtx *ops;
2149 int lreg, rreg, rval, multop, other_op;
2151 /* Find what value to multiply with, for rx =ry + rz * n. */
2152 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2154 rtx reg_rtx = ops[rreg];
2155 rtx val_rtx = ops[rval];
2157 /* The operands may be swapped. Canonicalize them in reg_rtx and
2158 val_rtx, where reg_rtx always is a reg (for this constraint to
2159 match). */
2160 if (! BASE_P (reg_rtx))
2161 reg_rtx = val_rtx, val_rtx = ops[rreg];
2163 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
2164 we have no business. */
2165 if (! BASE_P (reg_rtx))
2166 return 0;
2168 /* Don't do this when -mno-split. */
2169 if (!TARGET_SIDE_EFFECT_PREFIXES)
2170 return 0;
2172 /* The mult expression may be hidden in lreg. FIXME: Add more
2173 commentary about that. */
2174 if (GET_CODE (val_rtx) == MULT)
2176 mult = INTVAL (XEXP (val_rtx, 1));
2177 val_rtx = XEXP (val_rtx, 0);
2178 code = MULT;
2181 /* First check the "other operand". */
2182 if (other_op >= 0)
2184 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2185 return 0;
2187 /* Check if the lvalue register is the same as the "other
2188 operand". If so, the result is undefined and we shouldn't do
2189 this. FIXME: Check again. */
2190 if ((BASE_P (ops[lreg])
2191 && BASE_P (ops[other_op])
2192 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2193 || rtx_equal_p (ops[other_op], ops[lreg]))
2194 return 0;
2197 /* Do not accept frame_pointer_rtx as any operand. */
2198 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2199 || ops[rval] == frame_pointer_rtx
2200 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2201 return 0;
2203 if (code == PLUS
2204 && ! BASE_P (val_rtx))
2207 /* Do not allow rx = rx + n if a normal add or sub with same size
2208 would do. */
2209 if (rtx_equal_p (ops[lreg], reg_rtx)
2210 && GET_CODE (val_rtx) == CONST_INT
2211 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2212 return 0;
2214 /* Check allowed cases, like [r(+)?].[bwd] and const.
2215 A symbol is not allowed with PIC. */
2216 if (CONSTANT_P (val_rtx))
2217 return flag_pic == 0 || cris_symbol (val_rtx) == 0;
2219 if (GET_CODE (val_rtx) == MEM
2220 && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2221 return 1;
2223 if (GET_CODE (val_rtx) == SIGN_EXTEND
2224 && GET_CODE (XEXP (val_rtx, 0)) == MEM
2225 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2226 return 1;
2228 /* If we got here, it's not a valid addressing mode. */
2229 return 0;
2231 else if (code == MULT
2232 || (code == PLUS && BASE_P (val_rtx)))
2234 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2235 if (rtx_equal_p (ops[lreg], reg_rtx)
2236 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2237 return 0;
2239 /* Do not allow bad multiply-values. */
2240 if (mult != 1 && mult != 2 && mult != 4)
2241 return 0;
2243 /* Only allow r + ... */
2244 if (! BASE_P (reg_rtx))
2245 return 0;
2247 /* If we got here, all seems ok.
2248 (All checks need to be done above). */
2249 return 1;
2252 /* If we get here, the caller got its initial tests wrong. */
2253 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2256 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2257 does not handle the case where the IN operand is strict_low_part; it
2258 does handle it for X. Test-case in Axis-20010516. This function takes
2259 care of that for THIS port. FIXME: strict_low_part is going away
2260 anyway. */
2262 static int
2263 cris_reg_overlap_mentioned_p (x, in)
2264 rtx x, in;
2266 /* The function reg_overlap_mentioned now handles when X is
2267 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2268 if (GET_CODE (in) == STRICT_LOW_PART)
2269 in = XEXP (in, 0);
2271 return reg_overlap_mentioned_p (x, in);
2274 /* The TARGET_ASM_NAMED_SECTION worker.
2275 We just dispatch to the functions for ELF and a.out. */
2277 void
2278 cris_target_asm_named_section (name, flags)
2279 const char *name;
2280 unsigned int flags;
2282 if (! TARGET_ELF)
2283 default_no_named_section (name, flags);
2284 else
2285 default_elf_asm_named_section (name, flags);
2288 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2291 cris_legitimate_pic_operand (x)
2292 rtx x;
2294 /* The PIC representation of a symbol with a GOT entry will be (for
2295 example; relocations differ):
2296 sym => [rPIC+sym:GOT]
2297 and for a GOT-less symbol it will be (for example, relocation differ):
2298 sym => rPIC+sym:GOTOFF
2299 so only a symbol with a GOT is by itself a valid operand, and it
2300 can't be a sum of a symbol and an offset. */
2301 return ! cris_symbol (x) || cris_got_symbol (x);
2304 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2305 CONSTANT_P. */
2308 cris_symbol (x)
2309 rtx x;
2311 switch (GET_CODE (x))
2313 case SYMBOL_REF:
2314 case LABEL_REF:
2315 return 1;
2317 case UNSPEC:
2318 /* A PLT reference. */
2319 ASSERT_PLT_UNSPEC (x);
2320 return 1;
2322 case CONST:
2323 return cris_symbol (XEXP (x, 0));
2325 case PLUS:
2326 case MINUS:
2327 return cris_symbol (XEXP (x, 0)) || cris_symbol (XEXP (x, 1));
2329 case CONST_INT:
2330 case CONST_DOUBLE:
2331 case CONSTANT_P_RTX:
2332 return 0;
2334 default:
2335 fatal_insn ("unrecognized supposed constant", x);
2338 return 1;
2341 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2342 CONSTANT_P, and the symbol does not need a GOT entry. Also set
2343 current_function_uses_pic_offset_table if we're generating PIC and ever
2344 see something that would need one. */
2347 cris_gotless_symbol (x)
2348 rtx x;
2350 switch (GET_CODE (x))
2352 case UNSPEC:
2353 ASSERT_PLT_UNSPEC (x);
2354 return 1;
2356 case SYMBOL_REF:
2357 if (flag_pic && cfun != NULL)
2358 current_function_uses_pic_offset_table = 1;
2359 return SYMBOL_REF_FLAG (x);
2361 case LABEL_REF:
2362 /* We don't set current_function_uses_pic_offset_table for
2363 LABEL_REF:s in here, since they are almost always originating
2364 from some branch. The only time it does not come from a label is
2365 when GCC does something like __builtin_setjmp. Then we get the
2366 LABEL_REF from the movsi expander, so we mark it there as a
2367 special case. */
2368 return 1;
2370 case CONST:
2371 return cris_gotless_symbol (XEXP (x, 0));
2373 case PLUS:
2374 case MINUS:
2376 int x0 = cris_gotless_symbol (XEXP (x, 0)) != 0;
2377 int x1 = cris_gotless_symbol (XEXP (x, 1)) != 0;
2379 /* One and only one of them must be a local symbol. Neither must
2380 be some other, more general kind of symbol. */
2381 return
2382 (x0 ^ x1)
2383 && ! (x0 == 0 && cris_symbol (XEXP (x, 0)))
2384 && ! (x1 == 0 && cris_symbol (XEXP (x, 1)));
2387 case CONST_INT:
2388 case CONST_DOUBLE:
2389 case CONSTANT_P_RTX:
2390 return 0;
2392 default:
2393 fatal_insn ("unrecognized supposed constant", x);
2396 return 1;
2399 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2400 CONSTANT_P, and the symbol needs a GOT entry. */
2403 cris_got_symbol (x)
2404 rtx x;
2406 switch (GET_CODE (x))
2408 case UNSPEC:
2409 ASSERT_PLT_UNSPEC (x);
2410 return 0;
2412 case SYMBOL_REF:
2413 if (flag_pic && cfun != NULL)
2414 current_function_uses_pic_offset_table = 1;
2415 return ! SYMBOL_REF_FLAG (x);
2417 case CONST:
2418 return cris_got_symbol (XEXP (x, 0));
2420 case LABEL_REF:
2421 /* A LABEL_REF is never visible as a symbol outside the local
2422 function. */
2423 case PLUS:
2424 case MINUS:
2425 /* Nope, can't access the GOT for "symbol + offset". */
2426 return 0;
2428 case CONST_INT:
2429 case CONST_DOUBLE:
2430 case CONSTANT_P_RTX:
2431 return 0;
2433 default:
2434 fatal_insn ("unrecognized supposed constant in cris_global_pic_symbol",
2438 return 1;
2441 /* The OVERRIDE_OPTIONS worker.
2442 As is the norm, this also parses -mfoo=bar type parameters. */
2444 void
2445 cris_override_options ()
2447 if (cris_max_stackframe_str)
2449 cris_max_stackframe = atoi (cris_max_stackframe_str);
2451 /* Do some sanity checking. */
2452 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2453 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2454 cris_max_stackframe, 0x20000000);
2457 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2458 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2459 cris_cpu_version = CRIS_CPU_SVINTO;
2460 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2461 cris_cpu_version = CRIS_CPU_ETRAX4;
2463 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2464 if (cris_cpu_str)
2466 cris_cpu_version
2467 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2469 if (strcmp ("etrax4", cris_cpu_str) == 0)
2470 cris_cpu_version = 3;
2472 if (strcmp ("svinto", cris_cpu_str) == 0
2473 || strcmp ("etrax100", cris_cpu_str) == 0)
2474 cris_cpu_version = 8;
2476 if (strcmp ("ng", cris_cpu_str) == 0
2477 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2478 cris_cpu_version = 10;
2480 if (cris_cpu_version < 0 || cris_cpu_version > 10)
2481 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2482 cris_cpu_str);
2484 /* Set the target flags. */
2485 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2486 target_flags |= TARGET_MASK_ETRAX4_ADD;
2488 /* If this is Svinto or higher, align for 32 bit accesses. */
2489 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2490 target_flags
2491 |= (TARGET_MASK_SVINTO | TARGET_MASK_ALIGN_BY_32
2492 | TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2493 | TARGET_MASK_DATA_ALIGN);
2495 /* Note that we do not add new flags when it can be completely
2496 described with a macro that uses -mcpu=X. So
2497 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2500 if (cris_tune_str)
2502 int cris_tune
2503 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2505 if (strcmp ("etrax4", cris_tune_str) == 0)
2506 cris_tune = 3;
2508 if (strcmp ("svinto", cris_tune_str) == 0
2509 || strcmp ("etrax100", cris_tune_str) == 0)
2510 cris_tune = 8;
2512 if (strcmp ("ng", cris_tune_str) == 0
2513 || strcmp ("etrax100lx", cris_tune_str) == 0)
2514 cris_tune = 10;
2516 if (cris_tune < 0 || cris_tune > 10)
2517 error ("unknown CRIS cpu version specification in -mtune= : %s",
2518 cris_tune_str);
2520 if (cris_tune >= CRIS_CPU_SVINTO)
2521 /* We have currently nothing more to tune than alignment for
2522 memory accesses. */
2523 target_flags
2524 |= (TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2525 | TARGET_MASK_DATA_ALIGN | TARGET_MASK_ALIGN_BY_32);
2528 if (flag_pic)
2530 /* Use error rather than warning, so invalid use is easily
2531 detectable. Still change to the values we expect, to avoid
2532 further errors. */
2533 if (! TARGET_LINUX)
2535 error ("-fPIC not supported in this configuration");
2536 flag_pic = 0;
2539 /* Turn off function CSE. We need to have the addresses reach the
2540 call expanders to get PLT-marked, as they could otherwise be
2541 compared against zero directly or indirectly. After visiting the
2542 call expanders they will then be cse:ed, as the call expanders
2543 force_reg the addresses, effectively forcing flag_no_function_cse
2544 to 0. */
2545 flag_no_function_cse = 1;
2548 if ((write_symbols == DWARF_DEBUG
2549 || write_symbols == DWARF2_DEBUG) && ! TARGET_ELF)
2551 warning ("that particular -g option is invalid with -maout and -melinux");
2552 write_symbols = DBX_DEBUG;
2555 /* Set the per-function-data initializer. */
2556 init_machine_status = cris_init_machine_status;
2559 /* The ASM_OUTPUT_MI_THUNK worker. */
2561 void
2562 cris_asm_output_mi_thunk (stream, thunkdecl, delta, funcdecl)
2563 FILE *stream;
2564 tree thunkdecl ATTRIBUTE_UNUSED;
2565 int delta;
2566 tree funcdecl;
2568 if (delta > 0)
2569 asm_fprintf (stream, "\tadd%s %d,$%s\n",
2570 ADDITIVE_SIZE_MODIFIER (delta), delta,
2571 reg_names[CRIS_FIRST_ARG_REG]);
2572 else if (delta < 0)
2573 asm_fprintf (stream, "\tsub%s %d,$%s\n",
2574 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2575 reg_names[CRIS_FIRST_ARG_REG]);
2577 if (flag_pic)
2579 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2581 STRIP_NAME_ENCODING (name, name);
2582 fprintf (stream, "add.d ");
2583 assemble_name (stream, name);
2584 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2586 else
2588 fprintf (stream, "jump ");
2589 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2590 fprintf (stream, "\n");
2594 /* The EXPAND_BUILTIN_VA_ARG worker. This is modified from the
2595 "standard" implementation of va_arg: read the value from the current
2596 address and increment by the size of one or two registers. The
2597 important difference for CRIS is that if the type is
2598 pass-by-reference, then perform an indirection. */
2601 cris_expand_builtin_va_arg (valist, type)
2602 tree valist;
2603 tree type;
2605 tree addr_tree, t;
2606 rtx addr;
2607 enum machine_mode mode = TYPE_MODE (type);
2608 int passed_size;
2610 /* Get AP. */
2611 addr_tree = valist;
2613 /* Check if the type is passed by value or by reference. */
2614 if (MUST_PASS_IN_STACK (mode, type)
2615 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8)
2617 tree type_ptr = build_pointer_type (type);
2618 addr_tree = build1 (INDIRECT_REF, type_ptr, addr_tree);
2619 passed_size = 4;
2621 else
2622 passed_size = (CRIS_FUNCTION_ARG_SIZE (mode, type) > 4) ? 8 : 4;
2624 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2625 addr = copy_to_reg (addr);
2627 /* Compute new value for AP. */
2628 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2629 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2630 build_int_2 (passed_size, 0)));
2631 TREE_SIDE_EFFECTS (t) = 1;
2632 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2634 return addr;
2637 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2638 mark functions. */
2640 void
2641 cris_init_expanders ()
2643 /* Nothing here at the moment. */
2646 /* Zero initialization is OK for all current fields. */
2648 static void
2649 cris_init_machine_status (p)
2650 struct function *p;
2652 p->machine = xcalloc (1, sizeof (struct machine_function));
2655 /* Split a 2 word move (DI or presumably DF) into component parts.
2656 Originally a copy of gen_split_move_double in m32r.c. */
2659 cris_split_movdx (operands)
2660 rtx *operands;
2662 enum machine_mode mode = GET_MODE (operands[0]);
2663 rtx dest = operands[0];
2664 rtx src = operands[1];
2665 rtx val;
2667 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2668 longer happen; after reload there are no SUBREGs any more, and we're
2669 only called after reload. */
2670 if (GET_CODE (dest) == SUBREG || GET_CODE (src) == SUBREG)
2671 abort ();
2673 start_sequence ();
2674 if (GET_CODE (dest) == REG)
2676 int dregno = REGNO (dest);
2678 /* Reg-to-reg copy. */
2679 if (GET_CODE (src) == REG)
2681 int sregno = REGNO (src);
2683 int reverse = (dregno == sregno + 1);
2685 /* We normally copy the low-numbered register first. However, if
2686 the first register operand 0 is the same as the second register of
2687 operand 1, we must copy in the opposite order. */
2688 emit_insn (gen_rtx_SET (VOIDmode,
2689 operand_subword (dest, reverse, TRUE, mode),
2690 operand_subword (src, reverse, TRUE, mode)));
2692 emit_insn (gen_rtx_SET (VOIDmode,
2693 operand_subword (dest, !reverse, TRUE, mode),
2694 operand_subword (src, !reverse, TRUE, mode)));
2696 /* Constant-to-reg copy. */
2697 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
2699 rtx words[2];
2700 split_double (src, &words[0], &words[1]);
2701 emit_insn (gen_rtx_SET (VOIDmode,
2702 operand_subword (dest, 0, TRUE, mode),
2703 words[0]));
2705 emit_insn (gen_rtx_SET (VOIDmode,
2706 operand_subword (dest, 1, TRUE, mode),
2707 words[1]));
2709 /* Mem-to-reg copy. */
2710 else if (GET_CODE (src) == MEM)
2712 /* If the high-address word is used in the address, we must load it
2713 last. Otherwise, load it first. */
2714 rtx addr = XEXP (src, 0);
2715 int reverse
2716 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2718 /* The original code imples that we can't do
2719 move.x [rN+],rM move.x [rN],rM+1
2720 when rN is dead, because of REG_NOTES damage. That is
2721 consistent with what I've seen, so don't try it.
2723 We have two different cases here; if the addr is POST_INC,
2724 just pass it through, otherwise add constants. */
2726 if (GET_CODE (addr) == POST_INC)
2728 emit_insn (gen_rtx_SET (VOIDmode,
2729 operand_subword (dest, 0, TRUE, mode),
2730 change_address (src, SImode, addr)));
2731 emit_insn (gen_rtx_SET (VOIDmode,
2732 operand_subword (dest, 1, TRUE, mode),
2733 change_address (src, SImode, addr)));
2735 else
2737 /* Make sure we don't get any other addresses with
2738 embedded postincrements. They should be stopped in
2739 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2740 safety. */
2741 if (side_effects_p (addr))
2742 fatal_insn ("unexpected side-effects in address", addr);
2744 emit_insn (gen_rtx_SET
2745 (VOIDmode,
2746 operand_subword (dest, reverse, TRUE, mode),
2747 change_address
2748 (src, SImode,
2749 plus_constant (addr,
2750 reverse * UNITS_PER_WORD))));
2751 emit_insn (gen_rtx_SET
2752 (VOIDmode,
2753 operand_subword (dest, ! reverse, TRUE, mode),
2754 change_address
2755 (src, SImode,
2756 plus_constant (addr,
2757 (! reverse) *
2758 UNITS_PER_WORD))));
2761 else
2762 abort ();
2764 /* Reg-to-mem copy or clear mem. */
2765 else if (GET_CODE (dest) == MEM
2766 && (GET_CODE (src) == REG
2767 || src == const0_rtx
2768 || src == CONST0_RTX (DFmode)))
2770 rtx addr = XEXP (dest, 0);
2772 if (GET_CODE (addr) == POST_INC)
2774 emit_insn (gen_rtx_SET (VOIDmode,
2775 change_address (dest, SImode, addr),
2776 operand_subword (src, 0, TRUE, mode)));
2777 emit_insn (gen_rtx_SET (VOIDmode,
2778 change_address (dest, SImode, addr),
2779 operand_subword (src, 1, TRUE, mode)));
2781 else
2783 /* Make sure we don't get any other addresses with embedded
2784 postincrements. They should be stopped in
2785 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2786 if (side_effects_p (addr))
2787 fatal_insn ("unexpected side-effects in address", addr);
2789 emit_insn (gen_rtx_SET
2790 (VOIDmode,
2791 change_address (dest, SImode, addr),
2792 operand_subword (src, 0, TRUE, mode)));
2794 emit_insn (gen_rtx_SET
2795 (VOIDmode,
2796 change_address (dest, SImode,
2797 plus_constant (addr,
2798 UNITS_PER_WORD)),
2799 operand_subword (src, 1, TRUE, mode)));
2803 else
2804 abort ();
2806 val = gen_sequence ();
2807 end_sequence ();
2808 return val;
2811 /* This is in essence a copy of output_addr_const altered to output
2812 symbolic operands as PIC.
2814 FIXME: Add hooks similar to ASM_OUTPUT_SYMBOL_REF to get this effect in
2815 the "real" output_addr_const. All we need is one for LABEL_REF (and
2816 one for CODE_LABEL?). */
2818 void
2819 cris_output_addr_const (file, x)
2820 FILE *file;
2821 rtx x;
2823 int is_plt = 0;
2825 restart:
2826 switch (GET_CODE (x))
2828 case UNSPEC:
2829 ASSERT_PLT_UNSPEC (x);
2830 x = XVECEXP (x, 0, 0);
2831 is_plt = 1;
2833 /* Fall through. */
2834 case SYMBOL_REF:
2835 if (flag_pic)
2837 const char *origstr = XSTR (x, 0);
2838 const char *str;
2840 STRIP_NAME_ENCODING (str, origstr);
2842 if (is_plt)
2844 if (cris_pic_sympart_only)
2846 assemble_name (file, str);
2847 fprintf (file, ":PLTG");
2849 else
2851 if (TARGET_AVOID_GOTPLT)
2852 /* We shouldn't get here. */
2853 abort ();
2855 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2856 assemble_name (file, XSTR (x, 0));
2858 if (flag_pic == 1)
2859 fprintf (file, ":GOTPLT16]");
2860 else
2861 fprintf (file, ":GOTPLT]");
2864 else if (cris_gotless_symbol (x))
2866 if (! cris_pic_sympart_only)
2867 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2868 assemble_name (file, str);
2869 fprintf (file, ":GOTOFF");
2871 else if (cris_got_symbol (x))
2873 if (cris_pic_sympart_only)
2874 abort ();
2875 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2876 assemble_name (file, XSTR (x, 0));
2878 if (flag_pic == 1)
2879 fprintf (file, ":GOT16]");
2880 else
2881 fprintf (file, ":GOT]");
2883 else
2884 LOSE_AND_RETURN ("unexpected PIC symbol", x);
2886 /* Sanity check. */
2887 if (! current_function_uses_pic_offset_table)
2888 output_operand_lossage ("PIC register isn't set up");
2890 else
2891 assemble_name (file, XSTR (x, 0));
2892 break;
2894 case LABEL_REF:
2895 /* If we get one of those here, it should be dressed as PIC. Branch
2896 labels are normally output with the 'l' specifier, which means it
2897 will go directly to output_asm_label and not end up here. */
2898 if (GET_CODE (XEXP (x, 0)) != CODE_LABEL
2899 && (GET_CODE (XEXP (x, 0)) != NOTE
2900 || NOTE_LINE_NUMBER (XEXP (x, 0)) != NOTE_INSN_DELETED_LABEL))
2901 fatal_insn ("unexpected address expression", x);
2903 if (flag_pic)
2905 if (cris_gotless_symbol (x))
2907 if (! cris_pic_sympart_only)
2908 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2909 cris_output_addr_const (file, XEXP (x, 0));
2911 fprintf (file, ":GOTOFF");
2913 else
2914 /* Labels are never marked as global symbols. */
2915 fatal_insn ("unexpected PIC symbol", x);
2917 /* Sanity check. */
2918 if (! current_function_uses_pic_offset_table)
2919 internal_error ("emitting PIC operand, but PIC register isn't set up");
2920 break;
2923 output_addr_const (file, x);
2924 break;
2926 case NOTE:
2927 if (NOTE_LINE_NUMBER (x) != NOTE_INSN_DELETED_LABEL)
2928 fatal_insn ("unexpected NOTE as addr_const:", x);
2929 case CODE_LABEL:
2930 case CONST_INT:
2931 case CONST_DOUBLE:
2932 case ZERO_EXTEND:
2933 case SIGN_EXTEND:
2934 output_addr_const (file, x);
2935 break;
2937 case CONST:
2938 /* This used to output parentheses around the expression,
2939 but that does not work on the 386 (either ATT or BSD assembler). */
2940 cris_output_addr_const (file, XEXP (x, 0));
2941 break;
2943 case PLUS:
2944 /* Some assemblers need integer constants to appear last (eg masm). */
2945 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2947 cris_output_addr_const (file, XEXP (x, 1));
2948 if (INTVAL (XEXP (x, 0)) >= 0)
2949 fprintf (file, "+");
2950 output_addr_const (file, XEXP (x, 0));
2952 else
2954 cris_output_addr_const (file, XEXP (x, 0));
2955 if (GET_CODE (XEXP (x, 1)) != CONST_INT
2956 || INTVAL (XEXP (x, 1)) >= 0)
2957 fprintf (file, "+");
2958 cris_output_addr_const (file, XEXP (x, 1));
2960 break;
2962 case MINUS:
2963 /* Avoid outputting things like x-x or x+5-x,
2964 since some assemblers can't handle that. */
2965 x = simplify_subtraction (x);
2966 if (GET_CODE (x) != MINUS)
2967 goto restart;
2969 cris_output_addr_const (file, XEXP (x, 0));
2970 fprintf (file, "-");
2971 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
2972 && INTVAL (XEXP (x, 1)) < 0)
2973 || GET_CODE (XEXP (x, 1)) != CONST_INT)
2975 fprintf (file, "%s", targetm.asm_out.open_paren);
2976 cris_output_addr_const (file, XEXP (x, 1));
2977 fprintf (file, "%s", targetm.asm_out.close_paren);
2979 else
2980 output_addr_const (file, XEXP (x, 1));
2981 break;
2983 default:
2984 LOSE_AND_RETURN ("unexpected address expression", x);
2988 /* The ENCODE_SECTION_INFO worker. Code-in whether we can get away
2989 without a GOT entry (needed for externally visible objects but not for
2990 functions) into SYMBOL_REF_FLAG and add the PLT suffix for global
2991 functions. */
2993 void
2994 cris_encode_section_info (exp)
2995 tree exp;
2997 if (flag_pic)
2999 if (DECL_P (exp))
3001 if (TREE_CODE (exp) == FUNCTION_DECL
3002 && (TREE_PUBLIC (exp) || DECL_WEAK (exp)))
3003 SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0)) = 0;
3004 else
3005 SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0))
3006 = ! TREE_PUBLIC (exp) && ! DECL_WEAK (exp);
3008 else
3009 /* Others are local entities. */
3010 SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (exp), 0)) = 1;
3014 #if 0
3015 /* Various small functions to replace macros. Only called from a
3016 debugger. They might collide with gcc functions or system functions,
3017 so only emit them when '#if 1' above. */
3019 enum rtx_code Get_code PARAMS ((rtx));
3021 enum rtx_code
3022 Get_code (x)
3023 rtx x;
3025 return GET_CODE (x);
3028 const char *Get_mode PARAMS ((rtx));
3030 const char *
3031 Get_mode (x)
3032 rtx x;
3034 return GET_MODE_NAME (GET_MODE (x));
3037 rtx Xexp PARAMS ((rtx, int));
3040 Xexp (x, n)
3041 rtx x;
3042 int n;
3044 return XEXP (x, n);
3047 rtx Xvecexp PARAMS ((rtx, int, int));
3050 Xvecexp (x, n, m)
3051 rtx x;
3052 int n;
3054 return XVECEXP (x, n, m);
3057 int Get_rtx_len PARAMS ((rtx));
3060 Get_rtx_len (x)
3061 rtx x;
3063 return GET_RTX_LENGTH (GET_CODE (x));
3066 /* Use upper-case to distinguish from local variables that are sometimes
3067 called next_insn and prev_insn. */
3069 rtx Next_insn PARAMS ((rtx));
3072 Next_insn (insn)
3073 rtx insn;
3075 return NEXT_INSN (insn);
3078 rtx Prev_insn PARAMS ((rtx));
3081 Prev_insn (insn)
3082 rtx insn;
3084 return PREV_INSN (insn);
3086 #endif
3089 * Local variables:
3090 * eval: (c-set-style "gnu")
3091 * indent-tabs-mode: t
3092 * End: