* cris.h (EH_RETURN_DATA_REGNO): Fix unsigned>=0 warning.
[official-gcc.git] / gcc / config / cris / cris.c
blob668811ee010d01dcc44c0e6b3418955cd2db2391
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 "output.h"
31 #include "insn-attr.h"
32 #include "flags.h"
33 #include "tree.h"
34 #include "expr.h"
35 #include "except.h"
36 #include "function.h"
37 #include "toplev.h"
38 #include "recog.h"
39 #include "tm_p.h"
40 #include "debug.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 /* Per-function machine data. */
59 struct machine_function
61 int needs_return_address_on_stack;
64 /* Fix for reg_overlap_mentioned_p. */
65 static int cris_reg_overlap_mentioned_p PARAMS ((rtx, rtx));
67 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
68 pattern. */
69 static char cris_output_insn_is_bound = 0;
71 /* This one suppresses printing out the "rPIC+" in
72 "rPIC+sym:GOTOFF+offset" when doing PIC. For a PLT symbol, it
73 suppresses outputting it as [rPIC+sym:GOTPLT] and outputs similarly
74 just the "sym:GOTOFF" part. */
75 static int cris_pic_sympart_only = 0;
77 static void
78 cris_print_base PARAMS ((rtx, FILE *));
80 static void
81 cris_print_index PARAMS ((rtx, FILE *));
83 static void
84 cris_init_machine_status PARAMS ((struct function *));
86 static int
87 cris_initial_frame_pointer_offset PARAMS ((void));
89 static int
90 saved_regs_mentioned PARAMS ((rtx));
92 static void cris_target_asm_function_prologue
93 PARAMS ((FILE *, HOST_WIDE_INT));
94 static void cris_target_asm_function_epilogue
95 PARAMS ((FILE *, HOST_WIDE_INT));
97 /* The function cris_target_asm_function_epilogue puts the last insn to
98 output here. Used in delay_slots_for_epilogue and function_epilogue. */
99 static char save_last[80];
101 /* This is the argument from the "-max-stack-stackframe=" option. */
102 const char *cris_max_stackframe_str;
104 /* This is the argument from the "-march=" option. */
105 const char *cris_cpu_str;
107 /* This is the argument from the "-mtune=" option. */
108 const char *cris_tune_str;
110 /* This is the argument from the "-melinux-stacksize=" option. */
111 const char *cris_elinux_stacksize_str;
113 /* This is the parsed result of the "-max-stack-stackframe=" option. If
114 it (still) is zero, then there was no such option given. */
115 int cris_max_stackframe = 0;
117 /* This is the parsed result of the "-march=" option, if given. */
118 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
120 #undef TARGET_ASM_FUNCTION_PROLOGUE
121 #define TARGET_ASM_FUNCTION_PROLOGUE cris_target_asm_function_prologue
123 #undef TARGET_ASM_FUNCTION_EPILOGUE
124 #define TARGET_ASM_FUNCTION_EPILOGUE cris_target_asm_function_epilogue
126 struct gcc_target targetm = TARGET_INITIALIZER;
128 /* Predicate functions. */
130 /* This checks a part of an address, the one that is not a plain register
131 for an addressing mode using BDAP.
132 Allowed operands is either:
133 a) a register
134 b) a CONST operand (but not a symbol when generating PIC)
135 c) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
138 cris_bdap_operand (op, mode)
139 rtx op;
140 enum machine_mode mode;
142 register enum rtx_code code = GET_CODE (op);
144 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
145 return 0;
147 /* Just return whether this is a simple register or constant. */
148 if (register_operand (op, mode)
149 || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
150 return 1;
152 /* Is it a [r] or possibly a [r+]? */
153 if (code == MEM)
155 rtx tem = XEXP (op, 0);
157 if (mode == SImode
158 && (register_operand (tem, SImode)
159 || (GET_CODE (tem) == POST_INC
160 && register_operand (XEXP (tem, 0), SImode))))
161 return 1;
162 else
163 return 0;
166 /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)? */
167 if (code == SIGN_EXTEND)
169 rtx tem = XEXP (op, 0);
171 if (GET_CODE (tem) != MEM)
172 return 0;
174 tem = XEXP (tem, 0);
175 if (mode == SImode
176 && (register_operand (tem, SImode)
177 || (GET_CODE (tem) == POST_INC
178 && register_operand (XEXP (tem, 0), SImode))))
179 return 1;
180 else
181 return 0;
184 return 0;
187 /* This is similar to cris_bdap_operand:
188 It checks a part of an address, the one that is not a plain register
189 for an addressing mode using BDAP *or* BIAP.
190 Allowed operands is either:
191 a) a register
192 b) a CONST operand (but not a symbol when generating PIC)
193 c) a mult of (1, 2 or 4) and a register
194 d) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
197 cris_bdap_biap_operand (op, mode)
198 rtx op;
199 enum machine_mode mode;
201 register enum rtx_code code = GET_CODE (op);
202 rtx reg;
203 rtx val;
205 /* Check for bdap operand. */
206 if (cris_bdap_operand (op, mode))
207 return 1;
209 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
210 return 0;
212 /* Check that we're looking at a BIAP operand. */
213 if (code != MULT)
214 return 0;
216 /* Canonicalize register and multiplicand. */
217 if (GET_CODE (XEXP (op, 0)) == CONST_INT)
219 val = XEXP (op, 0);
220 reg = XEXP (op, 1);
222 else
224 val = XEXP (op, 1);
225 reg = XEXP (op, 0);
228 /* Check that the operands are correct after canonicalization. */
229 if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
230 return 0;
232 /* Check that the multiplicand has a valid value. */
233 if ((code == MULT
234 && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
235 return 1;
237 return 0;
240 /* Check if MODE is same as mode for X, and X is PLUS, MINUS, IOR or
241 AND or UMIN. */
244 cris_orthogonal_operator (x, mode)
245 rtx x;
246 enum machine_mode mode;
248 enum rtx_code code = GET_CODE (x);
250 if (mode == VOIDmode)
251 mode = GET_MODE (x);
253 return (GET_MODE (x) == mode
254 && (code == PLUS || code == MINUS
255 || code == IOR || code == AND || code == UMIN));
258 /* Check if MODE is same as mode for X, and X is PLUS, IOR or AND or
259 UMIN. */
262 cris_commutative_orth_op (x, mode)
263 rtx x;
264 enum machine_mode mode;
266 enum rtx_code code = GET_CODE (x);
268 if (mode == VOIDmode)
269 mode = GET_MODE (x);
271 return (GET_MODE (x) == mode &&
272 (code == PLUS
273 || code == IOR || code == AND || code == UMIN));
276 /* Check if MODE is same as mode for X, and X is PLUS or MINUS or UMIN. */
279 cris_operand_extend_operator (x, mode)
280 rtx x;
281 enum machine_mode mode;
283 enum rtx_code code = GET_CODE (x);
285 if (mode == VOIDmode)
286 mode = GET_MODE (x);
288 return (GET_MODE (x) == mode
289 && (code == PLUS || code == MINUS || code == UMIN));
292 /* Check to see if MODE is same as mode for X, and X is SIGN_EXTEND or
293 ZERO_EXTEND. */
296 cris_extend_operator (x, mode)
297 rtx x;
298 enum machine_mode mode;
300 enum rtx_code code = GET_CODE (x);
302 if (mode == VOIDmode)
303 mode = GET_MODE (x);
305 return
306 (GET_MODE (x) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
309 /* Check to see if MODE is same as mode for X, and X is PLUS or BOUND. */
312 cris_plus_or_bound_operator (x, mode)
313 rtx x;
314 enum machine_mode mode;
316 enum rtx_code code = GET_CODE (x);
318 if (mode == VOIDmode)
319 mode = GET_MODE (x);
321 return
322 (GET_MODE (x) == mode && (code == UMIN || code == PLUS));
325 /* Since with -fPIC, not all symbols are valid PIC symbols or indeed
326 general_operands, we have to have a predicate that matches it for the
327 "movsi" expander. */
330 cris_general_operand_or_symbol (op, mode)
331 rtx op;
332 enum machine_mode mode;
334 return general_operand (op, mode)
335 || (CONSTANT_P (op) && cris_symbol (op));
338 /* Since a PIC symbol without a GOT entry is not a general_operand, we
339 have to have a predicate that matches it. We use this in the expanded
340 "movsi" anonymous pattern for PIC symbols. */
343 cris_general_operand_or_gotless_symbol (op, mode)
344 rtx op;
345 enum machine_mode mode;
347 return general_operand (op, mode)
348 || (CONSTANT_P (op) && cris_gotless_symbol (op));
351 /* Since a PLT symbol is not a general_operand, we have to have a
352 predicate that matches it when we need it. We use this in the expanded
353 "call" and "call_value" anonymous patterns. */
356 cris_general_operand_or_plt_symbol (op, mode)
357 rtx op;
358 enum machine_mode mode;
360 return general_operand (op, mode)
361 || (GET_CODE (op) == CONST
362 && GET_CODE (XEXP (op, 0)) == UNSPEC
363 && !TARGET_AVOID_GOTPLT);
366 /* This matches a (MEM (general_operand)) or
367 (MEM (cris_general_operand_or_symbol)). The second one isn't a valid
368 memory_operand, so we need this predicate to recognize call
369 destinations before we change them to a PLT operand (by wrapping in
370 UNSPEC 0). */
373 cris_mem_call_operand (op, mode)
374 rtx op;
375 enum machine_mode mode;
377 rtx xmem;
379 if (GET_CODE (op) != MEM)
380 return 0;
382 if (memory_operand (op, mode))
383 return 1;
385 xmem = XEXP (op, 0);
387 return cris_general_operand_or_symbol (xmem, GET_MODE (op));
390 /* The CONDITIONAL_REGISTER_USAGE worker. */
392 void
393 cris_conditional_register_usage ()
395 /* FIXME: This isn't nice. We should be able to use that register for
396 something else if the PIC table isn't needed. */
397 if (flag_pic)
398 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
399 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
402 /* Return current_function_uses_pic_offset_table. For use in cris.md,
403 since some generated files do not include function.h. */
406 cris_cfun_uses_pic_table ()
408 return current_function_uses_pic_offset_table;
411 /* Given an rtx, return the text string corresponding to the CODE of X.
412 Intended for use in the assembly language output section of a
413 define_insn. */
415 const char *
416 cris_op_str (x)
417 rtx x;
419 cris_output_insn_is_bound = 0;
420 switch (GET_CODE (x))
422 case PLUS:
423 return "add";
424 break;
426 case MINUS:
427 return "sub";
428 break;
430 case MULT:
431 return "mul";
432 break;
434 case DIV:
435 return "div";
436 break;
438 case AND:
439 return "and";
440 break;
442 case IOR:
443 return "or";
444 break;
446 case XOR:
447 return "xor";
448 break;
450 case NOT:
451 return "not";
452 break;
454 case ASHIFT:
455 return "lsl";
456 break;
458 case LSHIFTRT:
459 return "lsr";
460 break;
462 case ASHIFTRT:
463 return "asr";
464 break;
466 case UMIN:
467 /* Used to control the sign/zero-extend character for the 'e' modifier.
468 BOUND has none. */
469 cris_output_insn_is_bound = 1;
470 return "bound";
471 break;
473 default:
474 return "Unknown operator";
475 break;
479 /* Print an index part of an address to file. */
481 static void
482 cris_print_index (index, file)
483 rtx index;
484 FILE * file;
486 rtx inner = XEXP (index, 0);
488 /* Make the index "additive" unless we'll output a negative number, in
489 which case the sign character is free (as in free beer). */
490 if (GET_CODE (index) != CONST_INT || INTVAL (index) >= 0)
491 putc ('+', file);
493 if (REG_P (index))
494 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
495 else if (CONSTANT_P (index))
496 cris_output_addr_const (file, index);
497 else if (GET_CODE (index) == MULT)
499 fprintf (file, "$%s.",
500 reg_names[REGNO (XEXP (index, 0))]);
502 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
504 else if (GET_CODE (index) == SIGN_EXTEND &&
505 GET_CODE (inner) == MEM)
507 rtx inner_inner = XEXP (inner, 0);
509 if (GET_CODE (inner_inner) == POST_INC)
511 fprintf (file, "[$%s+].",
512 reg_names[REGNO (XEXP (inner_inner, 0))]);
513 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
515 else
517 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
519 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
522 else if (GET_CODE (index) == MEM)
524 if (GET_CODE (inner) == POST_INC)
525 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
526 else
527 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
529 else
530 fatal_insn ("Unexpected index-type in cris_print_index", index);
533 /* Print a base rtx of an address to file. */
535 static void
536 cris_print_base (base, file)
537 rtx base;
538 FILE *file;
540 if (REG_P (base))
541 fprintf (file, "$%s", reg_names[REGNO (base)]);
542 else if (GET_CODE (base) == POST_INC)
543 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
544 else
545 fatal_insn ("Unexpected base-type in cris_print_base", base);
548 /* Usable as a guard in expressions. */
551 cris_fatal (arg)
552 char *arg;
554 internal_error (arg);
556 /* We'll never get here; this is just to appease compilers. */
557 return 0;
560 /* Textual function prologue. */
562 static void
563 cris_target_asm_function_prologue (file, size)
564 FILE *file;
565 HOST_WIDE_INT size;
567 int regno;
569 /* Shorten the used name for readability. */
570 int cfoa_size = current_function_outgoing_args_size;
571 int last_movem_reg = -1;
572 int doing_dwarf = dwarf2out_do_frame ();
573 int framesize;
574 int faked_args_size = 0;
575 int cfa_write_offset = 0;
576 char *cfa_label = NULL;
577 int return_address_on_stack
578 = regs_ever_live[CRIS_SRP_REGNUM]
579 || cfun->machine->needs_return_address_on_stack != 0;
581 /* Don't do anything if no prologues or epilogues are wanted. */
582 if (!TARGET_PROLOGUE_EPILOGUE)
583 return;
585 if (size < 0)
586 abort ();
588 /* Align the size to what's best for the CPU model. */
589 if (TARGET_STACK_ALIGN)
590 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
592 if (current_function_pretend_args_size)
594 int pretend = current_function_pretend_args_size;
595 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
596 pretend > 0;
597 regno--, pretend -= 4)
599 fprintf (file, "\tpush $%s\n", reg_names[regno]);
600 faked_args_size += 4;
604 framesize = faked_args_size;
606 if (doing_dwarf)
608 /* FIXME: Slightly redundant calculation, as we do the same in
609 pieces below. This offset must be the total adjustment of the
610 stack-pointer. We can then def_cfa call at the end of this
611 function with the current implementation of execute_cfa_insn, but
612 that wouldn't really be clean. */
614 int cfa_offset
615 = faked_args_size
616 + (return_address_on_stack ? 4 : 0)
617 + (frame_pointer_needed ? 4 : 0);
619 int cfa_reg;
621 if (frame_pointer_needed)
622 cfa_reg = FRAME_POINTER_REGNUM;
623 else
625 cfa_reg = STACK_POINTER_REGNUM;
626 cfa_offset += cris_initial_frame_pointer_offset ();
629 cfa_label = dwarf2out_cfi_label ();
630 dwarf2out_def_cfa (cfa_label, cfa_reg, cfa_offset);
632 cfa_write_offset = - faked_args_size - 4;
635 /* Save SRP if not a leaf function. */
636 if (return_address_on_stack)
638 fprintf (file, "\tPush $srp\n");
639 framesize += 4;
641 if (doing_dwarf)
643 dwarf2out_return_save (cfa_label, cfa_write_offset);
644 cfa_write_offset -= 4;
648 /* Set up frame pointer if needed. */
649 if (frame_pointer_needed)
651 fprintf (file, "\tpush $%s\n\tmove.d $sp,$%s\n",
652 reg_names[FRAME_POINTER_REGNUM],
653 reg_names[FRAME_POINTER_REGNUM]);
654 framesize += 4;
656 if (doing_dwarf)
658 dwarf2out_reg_save (cfa_label, FRAME_POINTER_REGNUM,
659 cfa_write_offset);
660 cfa_write_offset -= 4;
664 /* Local vars are located above saved regs. */
665 cfa_write_offset -= size;
667 /* Get a contiguous sequence of registers, starting with r0, that need
668 to be saved. */
669 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
671 if ((((regs_ever_live[regno]
672 && !call_used_regs[regno])
673 || (regno == PIC_OFFSET_TABLE_REGNUM
674 && (current_function_uses_pic_offset_table
675 /* It is saved anyway, if there would be a gap. */
676 || (flag_pic
677 && regs_ever_live[regno + 1]
678 && !call_used_regs[regno + 1]))))
679 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
680 && regno != CRIS_SRP_REGNUM)
681 || (current_function_calls_eh_return
682 && (regno == EH_RETURN_DATA_REGNO (0)
683 || regno == EH_RETURN_DATA_REGNO (1)
684 || regno == EH_RETURN_DATA_REGNO (2)
685 || regno == EH_RETURN_DATA_REGNO (3))))
687 /* Check if movem may be used for registers so far. */
688 if (regno == last_movem_reg + 1)
689 /* Yes, update next expected register. */
690 last_movem_reg++;
691 else
693 /* We cannot use movem for all registers. We have to flush
694 any movem:ed registers we got so far. */
695 if (last_movem_reg != -1)
697 /* It is a win to use a side-effect assignment for
698 64 <= size <= 128. But side-effect on movem was
699 not usable for CRIS v0..3. Also only do it if
700 side-effects insns are allowed. */
701 if ((last_movem_reg + 1) * 4 + size >= 64
702 && (last_movem_reg + 1) * 4 + size <= 128
703 && cris_cpu_version >= CRIS_CPU_SVINTO
704 && TARGET_SIDE_EFFECT_PREFIXES)
705 fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
706 reg_names[last_movem_reg],
707 (last_movem_reg + 1) * 4 + size);
708 else
710 /* Avoid printing multiple subsequent sub:s for sp. */
711 fprintf (file, "\tsub%s %d,$sp\n",
712 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1)
713 * 4 + size),
714 (last_movem_reg + 1) * 4 + size);
716 fprintf (file, "\tmovem $%s,[$sp]\n",
717 reg_names[last_movem_reg]);
720 framesize += (last_movem_reg + 1) * 4 + size;
722 if (TARGET_PDEBUG)
723 fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
724 size,
725 last_movem_reg + 1,
726 (last_movem_reg + 1) * 4,
727 current_function_args_size);
729 last_movem_reg = -1;
730 size = 0;
732 else if (size > 0)
734 /* Local vars on stack, but there are no movem:s.
735 Just allocate space. */
736 fprintf (file, "\tSub%s %d,$sp\n",
737 ADDITIVE_SIZE_MODIFIER (size),
738 size);
739 framesize += size;
740 size = 0;
743 fprintf (file, "\tPush $%s\n", reg_names[regno]);
744 framesize += 4;
747 if (doing_dwarf)
749 /* Registers are stored lowest numbered at highest address,
750 which matches the loop order; we just need to update the
751 write-offset. */
752 dwarf2out_reg_save (cfa_label, regno, cfa_write_offset);
753 cfa_write_offset -= 4;
758 /* Check after, if we can movem all registers. This is the normal
759 case. */
760 if (last_movem_reg != -1)
762 /* Side-effect assignment on movem was not supported for CRIS v0..3,
763 and don't do it if we're asked not to.
765 The movem is already accounted for, for unwind. */
767 if ((last_movem_reg + 1) * 4 + size >= 64
768 && (last_movem_reg + 1) * 4 + size <= 128
769 && cris_cpu_version >= CRIS_CPU_SVINTO
770 && TARGET_SIDE_EFFECT_PREFIXES)
771 fprintf (file, "\tmovem $%s,[$sp=$sp-%d]\n",
772 reg_names[last_movem_reg],
773 (last_movem_reg+1) * 4 + size);
774 else
776 /* Avoid printing multiple subsequent sub:s for sp. FIXME:
777 Clean up the conditional expression. */
778 fprintf (file, "\tsub%s %d,$sp\n",
779 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1) * 4 + size),
780 (last_movem_reg + 1) * 4 + size);
781 /* To be compatible with v0..v3 means we do not use an assignment
782 addressing mode with movem. We normally don't need that
783 anyway. It would only be slightly more efficient for 64..128
784 bytes frame size. */
785 fprintf (file, "\tmovem $%s,[$sp]\n", reg_names[last_movem_reg]);
788 framesize += (last_movem_reg + 1) * 4 + size;
790 if (TARGET_PDEBUG)
791 fprintf (file, "; frame %d, #regs %d, bytes %d args %d\n",
792 size,
793 last_movem_reg + 1,
794 (last_movem_reg + 1) * 4,
795 current_function_args_size);
797 /* We have to put outgoing argument space after regs. */
798 if (cfoa_size)
800 /* This does not need to be accounted for, for unwind. */
802 fprintf (file, "\tSub%s %d,$sp\n",
803 ADDITIVE_SIZE_MODIFIER (cfoa_size),
804 cfoa_size);
805 framesize += cfoa_size;
808 else if ((size + cfoa_size) > 0)
810 /* This does not need to be accounted for, for unwind. */
812 /* Local vars on stack, and we could not use movem. Add a sub here. */
813 fprintf (file, "\tSub%s %d,$sp\n",
814 ADDITIVE_SIZE_MODIFIER (size + cfoa_size),
815 cfoa_size + size);
816 framesize += size + cfoa_size;
819 /* Set up the PIC register. */
820 if (current_function_uses_pic_offset_table)
821 asm_fprintf (file, "\tmove.d $pc,$%s\n\tsub.d .:GOTOFF,$%s\n",
822 reg_names[PIC_OFFSET_TABLE_REGNUM],
823 reg_names[PIC_OFFSET_TABLE_REGNUM]);
825 if (TARGET_PDEBUG)
826 fprintf (file,
827 "; parm #%d @ %d; frame %d, FP-SP is %d; leaf: %s%s; fp %s, outg: %d arg %d\n",
828 CRIS_MAX_ARGS_IN_REGS + 1, FIRST_PARM_OFFSET (0),
829 get_frame_size (),
830 cris_initial_frame_pointer_offset (),
831 leaf_function_p () ? "yes" : "no",
832 return_address_on_stack ? "no" :"yes",
833 frame_pointer_needed ? "yes" : "no",
834 cfoa_size, current_function_args_size);
836 if (cris_max_stackframe && framesize > cris_max_stackframe)
837 warning ("Stackframe too big: %d bytes", framesize);
840 /* Return nonzero if there are regs mentioned in the insn that are not all
841 in the call_used regs. This is part of the decision whether an insn
842 can be put in the epilogue. */
844 static int
845 saved_regs_mentioned (x)
846 rtx x;
848 int i;
849 const char *fmt;
850 RTX_CODE code;
852 /* Mainly stolen from refers_to_regno_p in rtlanal.c. */
854 code = GET_CODE (x);
856 switch (code)
858 case REG:
859 i = REGNO (x);
860 return !call_used_regs[i];
862 case SUBREG:
863 /* If this is a SUBREG of a hard reg, we can see exactly which
864 registers are being modified. Otherwise, handle normally. */
865 i = REGNO (SUBREG_REG (x));
866 return !call_used_regs[i];
868 default:
872 fmt = GET_RTX_FORMAT (code);
873 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
875 if (fmt[i] == 'e')
877 if (saved_regs_mentioned (XEXP (x, i)))
878 return 1;
880 else if (fmt[i] == 'E')
882 int j;
883 for (j = XVECLEN (x, i) - 1; j >=0; j--)
884 if (saved_regs_mentioned (XEXP (x, i)))
885 return 1;
889 return 0;
892 /* Figure out if the insn may be put in the epilogue. */
895 cris_eligible_for_epilogue_delay (insn)
896 rtx insn;
898 /* First of all, it must be as slottable as for a delayed branch insn. */
899 if (get_attr_slottable (insn) != SLOTTABLE_YES)
900 return 0;
902 /* It must not refer to the stack pointer (may be valid for some cases
903 that I can't think of). */
904 if (reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)))
905 return 0;
907 /* The frame pointer will be restored in the epilogue, before the
908 "ret", so it can't be referred to. */
909 if (frame_pointer_needed
910 && reg_mentioned_p (frame_pointer_rtx, PATTERN (insn)))
911 return 0;
913 /* All saved regs are restored before the delayed insn.
914 This means that we cannot have any instructions that mention the
915 registers that are restored by the epilogue. */
916 if (saved_regs_mentioned (PATTERN (insn)))
917 return 0;
919 /* It seems to be ok. */
920 return 1;
923 /* Return the number of delay-slots in the epilogue: return 1 if it
924 contains "ret", else 0. */
927 cris_delay_slots_for_epilogue ()
929 /* Check if we use a return insn, which we only do for leaf functions.
930 Else there is no slot to fill. */
931 if (regs_ever_live[CRIS_SRP_REGNUM]
932 || cfun->machine->needs_return_address_on_stack != 0)
933 return 0;
935 /* By calling function_epilogue with the same parameters as from gcc
936 we can get info about if the epilogue can fill the delay-slot by itself.
937 If it is filled from the epilogue, then the corresponding string
938 is in save_last.
939 This depends on that the "size" argument to function_epilogue
940 always is get_frame_size.
941 FIXME: Kludgy. At least make it a separate function that is not
942 misnamed or abuses the stream parameter. */
943 cris_target_asm_function_epilogue (NULL, get_frame_size ());
945 if (*save_last)
946 return 1;
947 return 0;
950 /* Textual function epilogue. When file is NULL, it serves doubly as
951 a test for whether the epilogue can fill any "ret" delay-slots by
952 itself by storing the delay insn in save_last. */
954 static void
955 cris_target_asm_function_epilogue (file, size)
956 FILE *file;
957 HOST_WIDE_INT size;
959 int regno;
960 int last_movem_reg = -1;
961 rtx insn = get_last_insn ();
962 int argspace_offset = current_function_outgoing_args_size;
963 int pretend = current_function_pretend_args_size;
964 int return_address_on_stack
965 = regs_ever_live[CRIS_SRP_REGNUM]
966 || cfun->machine->needs_return_address_on_stack != 0;
968 save_last[0] = 0;
970 if (file && !TARGET_PROLOGUE_EPILOGUE)
971 return;
973 if (TARGET_PDEBUG && file)
974 fprintf (file, ";;\n");
976 /* Align byte count of stack frame. */
977 if (TARGET_STACK_ALIGN)
978 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
980 /* If the last insn was a BARRIER, we don't have to write any code,
981 then all returns were covered by "return" insns. */
982 if (GET_CODE (insn) == NOTE)
983 insn = prev_nonnote_insn (insn);
984 if (insn
985 && (GET_CODE (insn) == BARRIER
986 /* We must make sure that the insn really is a "return" and
987 not a conditional branch. Try to match the return exactly,
988 and if it doesn't match, assume it is a conditional branch
989 (and output an epilogue). */
990 || (GET_CODE (insn) == JUMP_INSN
991 && GET_CODE (PATTERN (insn)) == RETURN)))
993 if (TARGET_PDEBUG && file)
994 fprintf (file, ";;;;;\n");
995 return;
998 /* Check how many saved regs we can movem. They start at r0 and must
999 be contiguous. */
1000 for (regno = 0;
1001 regno < FIRST_PSEUDO_REGISTER;
1002 regno++)
1003 if ((((regs_ever_live[regno]
1004 && !call_used_regs[regno])
1005 || (regno == PIC_OFFSET_TABLE_REGNUM
1006 && (current_function_uses_pic_offset_table
1007 /* It is saved anyway, if there would be a gap. */
1008 || (flag_pic
1009 && regs_ever_live[regno + 1]
1010 && !call_used_regs[regno + 1]))))
1011 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1012 && regno != CRIS_SRP_REGNUM)
1013 || (current_function_calls_eh_return
1014 && (regno == EH_RETURN_DATA_REGNO (0)
1015 || regno == EH_RETURN_DATA_REGNO (1)
1016 || regno == EH_RETURN_DATA_REGNO (2)
1017 || regno == EH_RETURN_DATA_REGNO (3))))
1020 if (regno == last_movem_reg + 1)
1021 last_movem_reg++;
1022 else
1023 break;
1026 for (regno = FIRST_PSEUDO_REGISTER - 1;
1027 regno > last_movem_reg;
1028 regno--)
1029 if ((((regs_ever_live[regno]
1030 && !call_used_regs[regno])
1031 || (regno == PIC_OFFSET_TABLE_REGNUM
1032 && (current_function_uses_pic_offset_table
1033 /* It is saved anyway, if there would be a gap. */
1034 || (flag_pic
1035 && regs_ever_live[regno + 1]
1036 && !call_used_regs[regno + 1]))))
1037 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1038 && regno != CRIS_SRP_REGNUM)
1039 || (current_function_calls_eh_return
1040 && (regno == EH_RETURN_DATA_REGNO (0)
1041 || regno == EH_RETURN_DATA_REGNO (1)
1042 || regno == EH_RETURN_DATA_REGNO (2)
1043 || regno == EH_RETURN_DATA_REGNO (3))))
1045 if (argspace_offset)
1047 /* There is an area for outgoing parameters located before
1048 the saved registers. We have to adjust for that. */
1049 if (file)
1050 fprintf (file, "\tAdd%s %d,$sp\n",
1051 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1052 argspace_offset);
1054 /* Make sure we only do this once. */
1055 argspace_offset = 0;
1058 /* Flush previous non-movem:ed registers. */
1059 if (*save_last && file)
1060 fprintf (file, save_last);
1061 sprintf (save_last, "\tPop $%s\n", reg_names[regno]);
1064 if (last_movem_reg != -1)
1066 if (argspace_offset)
1068 /* Adjust for the outgoing parameters area, if that's not
1069 handled yet. */
1070 if (*save_last && file)
1072 fprintf (file, save_last);
1073 *save_last = 0;
1076 if (file)
1077 fprintf (file, "\tAdd%s %d,$sp\n",
1078 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1079 argspace_offset);
1080 argspace_offset = 0;
1082 /* Flush previous non-movem:ed registers. */
1083 else if (*save_last && file)
1084 fprintf (file, save_last);
1085 sprintf (save_last, "\tmovem [$sp+],$%s\n", reg_names[last_movem_reg]);
1088 /* Restore frame pointer if necessary. */
1089 if (frame_pointer_needed)
1091 if (*save_last && file)
1092 fprintf (file, save_last);
1094 if (file)
1095 fprintf (file, "\tmove.d $%s,$sp\n",
1096 reg_names[FRAME_POINTER_REGNUM]);
1097 sprintf (save_last, "\tPop $%s\n",
1098 reg_names[FRAME_POINTER_REGNUM]);
1100 else
1102 /* If there was no frame-pointer to restore sp from, we must
1103 explicitly deallocate local variables. */
1105 /* Handle space for outgoing parameters that hasn't been handled
1106 yet. */
1107 size += argspace_offset;
1109 if (size)
1111 if (*save_last && file)
1112 fprintf (file, save_last);
1114 sprintf (save_last, "\tadd%s %d,$sp\n",
1115 ADDITIVE_SIZE_MODIFIER (size), size);
1118 /* If the size was not in the range for a "quick", we must flush
1119 it here. */
1120 if (size > 63)
1122 if (file)
1123 fprintf (file, save_last);
1124 *save_last = 0;
1128 /* If this function has no pushed register parameters
1129 (stdargs/varargs), and if it is not a leaf function, then we can
1130 just jump-return here. */
1131 if (return_address_on_stack && pretend == 0)
1133 if (*save_last && file)
1134 fprintf (file, save_last);
1135 *save_last = 0;
1137 if (file)
1139 if (current_function_calls_eh_return)
1141 /* The installed EH-return address is in *this* frame, so we
1142 need to pop it before we return. */
1143 fprintf (file, "\tpop $srp\n");
1144 fprintf (file, "\tret\n");
1145 fprintf (file, "\tadd.d $%s,$sp\n", reg_names[CRIS_STACKADJ_REG]);
1147 else
1148 fprintf (file, "\tJump [$sp+]\n");
1150 /* Do a sanity check to avoid generating invalid code. */
1151 if (current_function_epilogue_delay_list)
1152 internal_error ("Allocated but unused delay list in epilogue");
1154 return;
1157 /* Rather than add current_function_calls_eh_return conditions
1158 everywhere in the following code (and not be able to test it
1159 thoroughly), assert the assumption that all usage of
1160 __builtin_eh_return are handled above. */
1161 if (current_function_calls_eh_return)
1162 internal_error ("Unexpected function type needing stack adjustment for\
1163 __builtin_eh_return");
1165 /* If we pushed some register parameters, then adjust the stack for
1166 them. */
1167 if (pretend)
1169 /* Since srp is stored on the way, we need to restore it first. */
1170 if (return_address_on_stack)
1172 if (*save_last && file)
1173 fprintf (file, save_last);
1174 *save_last = 0;
1176 if (file)
1177 fprintf (file, "\tpop $srp\n");
1180 if (*save_last && file)
1181 fprintf (file, save_last);
1183 sprintf (save_last, "\tadd%s %d,$sp\n",
1184 ADDITIVE_SIZE_MODIFIER (pretend), pretend);
1187 /* Here's where we have a delay-slot we need to fill. */
1188 if (file && current_function_epilogue_delay_list)
1190 /* If gcc has allocated an insn for the epilogue delay slot, but
1191 things were arranged so we now thought we could do it
1192 ourselves, don't forget to flush that insn. */
1193 if (*save_last)
1194 fprintf (file, save_last);
1196 fprintf (file, "\tRet\n");
1198 /* Output the delay-slot-insn the mandated way. */
1199 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1200 file, 1, -2, 1);
1202 else if (file)
1204 fprintf (file, "\tRet\n");
1206 /* If the GCC did not do it, we have to use whatever insn we have,
1207 or a nop. */
1208 if (*save_last)
1209 fprintf (file, save_last);
1210 else
1211 fprintf (file, "\tnOp\n");
1215 /* The PRINT_OPERAND worker. */
1217 void
1218 cris_print_operand (file, x, code)
1219 FILE *file;
1220 rtx x;
1221 int code;
1223 rtx operand = x;
1225 /* Size-strings corresponding to MULT expressions. */
1226 static const char *mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
1228 /* New code entries should just be added to the switch below. If
1229 handling is finished, just return. If handling was just a
1230 modification of the operand, the modified operand should be put in
1231 "operand", and then do a break to let default handling
1232 (zero-modifier) output the operand. */
1234 switch (code)
1236 case 'b':
1237 /* Print the unsigned supplied integer as if it was signed
1238 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
1239 if (GET_CODE (x) != CONST_INT
1240 || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
1241 fatal_insn ("Internal: Invalid operand with 'b'", x);
1242 fprintf (file, "%d", INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
1243 return;
1245 case 'x':
1246 /* Print assembler code for operator. */
1247 fprintf (file, "%s", cris_op_str (operand));
1248 return;
1250 case 'v':
1251 /* Print the operand without the PIC register. */
1252 if (! flag_pic || ! cris_gotless_symbol (x))
1253 fatal_insn ("Internal: Invalid operand with 'v'", x);
1254 cris_pic_sympart_only++;
1255 cris_output_addr_const (file, x);
1256 cris_pic_sympart_only--;
1257 return;
1259 case 'P':
1260 /* Print the PIC register. Applied to a GOT-less PIC symbol for
1261 sanity. */
1262 if (! flag_pic || ! cris_gotless_symbol (x))
1263 fatal_insn ("Internal: Invalid operand with 'P'", x);
1264 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
1265 return;
1267 case 'p':
1268 /* Adjust a power of two to its log2. */
1269 if (GET_CODE (x) != CONST_INT || exact_log2 (INTVAL (x)) < 0 )
1270 fatal_insn ("Internal: Invalid operand with 'p'", x);
1271 fprintf (file, "%d", exact_log2 (INTVAL (x)));
1272 return;
1274 case 's':
1275 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
1276 respectively. This modifier also terminates the inhibiting
1277 effects of the 'x' modifier. */
1278 cris_output_insn_is_bound = 0;
1279 if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
1281 if (INTVAL (x) >= 0)
1283 if (INTVAL (x) <= 255)
1284 putc ('b', file);
1285 else if (INTVAL (x) <= 65535)
1286 putc ('w', file);
1287 else
1288 putc ('d', file);
1290 else
1291 putc ('d', file);
1292 return;
1295 /* For a non-integer, print the size of the operand. */
1296 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
1297 ? 'd' : GET_MODE (x) == HImode ? 'w'
1298 : GET_MODE (x) == QImode ? 'b'
1299 /* If none of the above, emit an erroneous size letter. */
1300 : 'X',
1301 file);
1302 return;
1304 case 'z':
1305 /* Const_int: print b for -127 <= x <= 255,
1306 w for -32768 <= x <= 65535, else abort. */
1307 if (GET_CODE (x) != CONST_INT
1308 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
1309 fatal_insn ("Internal: Invalid operand with 'z'", x);
1310 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
1311 return;
1313 case '#':
1314 /* Output a 'nop' if there's nothing for the delay slot.
1315 This method stolen from the sparc files. */
1316 if (dbr_sequence_length () == 0)
1317 fputs ("\n\tnop", file);
1318 return;
1320 case 'H':
1321 /* Print high (most significant) part of something. */
1322 switch (GET_CODE (operand))
1324 case CONST_INT:
1325 /* Sign-extension from a normal int to a long long. */
1326 fprintf (file, INTVAL (operand) < 0 ? "-1" : "0");
1327 return;
1329 case CONST_DOUBLE:
1330 /* High part of a long long constant. */
1331 if (GET_MODE (operand) == VOIDmode)
1333 fprintf (file, "0x%x", CONST_DOUBLE_HIGH (x));
1334 return;
1336 else
1337 fatal_insn ("Internal: Invalid operand with 'H'", x);
1339 case REG:
1340 /* Print reg + 1. Check that there's not an attempt to print
1341 high-parts of registers like stack-pointer or higher. */
1342 if (REGNO (operand) > STACK_POINTER_REGNUM - 2)
1343 internal_error ("Internal: Bad register: %d", REGNO (operand));
1344 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
1345 return;
1347 case MEM:
1348 /* Adjust memory address to high part. */
1350 rtx adj_mem = operand;
1351 int size
1352 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
1354 /* Adjust so we can use two SImode in DImode.
1355 Calling adj_offsettable_operand will make sure it is an
1356 offsettable address. Don't do this for a postincrement
1357 though; it should remain as it was. */
1358 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
1359 adj_mem
1360 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
1362 output_address (XEXP (adj_mem, 0));
1363 return;
1366 default:
1367 fatal_insn ("Internal: Invalid operand for 'H'", x);
1370 case 'L':
1371 /* Strip the MEM expression. */
1372 operand = XEXP (operand, 0);
1373 break;
1375 case 'e':
1376 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
1377 cris_output_insn_is_bound is nonzero. */
1378 if (GET_CODE (operand) != SIGN_EXTEND
1379 && GET_CODE (operand) != ZERO_EXTEND
1380 && GET_CODE (operand) != CONST_INT)
1381 fatal_insn ("Internal: Invalid operand with 'e'", x);
1383 if (cris_output_insn_is_bound)
1385 cris_output_insn_is_bound = 0;
1386 return;
1389 putc (GET_CODE (operand) == SIGN_EXTEND
1390 || (GET_CODE (operand) == CONST_INT && INTVAL (operand) < 0)
1391 ? 's' : 'u', file);
1392 return;
1394 case 'm':
1395 /* Print the size letter of the inner element. We can do it by
1396 calling ourselves with the 's' modifier. */
1397 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
1398 fatal_insn ("Internal: Invalid operand with 'm'", x);
1399 cris_print_operand (file, XEXP (operand, 0), 's');
1400 return;
1402 case 'M':
1403 /* Print the least significant part of operand. */
1404 if (GET_CODE (operand) == CONST_DOUBLE)
1406 fprintf (file, "0x%x", CONST_DOUBLE_LOW (x));
1407 return;
1409 /* If not a CONST_DOUBLE, the least significant part equals the
1410 normal part, so handle it normally. */
1411 break;
1413 case 'A':
1414 /* When emitting an add for the high part of a DImode constant, we
1415 want to use addq for 0 and adds.w for -1. */
1416 if (GET_CODE (operand) != CONST_INT)
1417 fatal_insn ("Internal: Invalid operand with 'A' output modifier", x);
1418 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
1419 return;
1421 case 'D':
1422 /* When emitting an sub for the high part of a DImode constant, we
1423 want to use subq for 0 and subs.w for -1. */
1424 if (GET_CODE (operand) != CONST_INT)
1425 fatal_insn ("Internal: Invalid operand with 'D' output modifier", x);
1426 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
1427 return;
1429 case 'S':
1430 /* Print the operand as the index-part of an address.
1431 Easiest way out is to use cris_print_index. */
1432 cris_print_index (operand, file);
1433 return;
1435 case 'T':
1436 /* Print the size letter for an operand to a MULT, which must be a
1437 const_int with a suitable value. */
1438 if (GET_CODE (operand) != CONST_INT || INTVAL (operand) > 4)
1439 fatal_insn ("Internal: Invalid operand with 'T'", x);
1441 fprintf (file, "%s", mults[INTVAL (operand)]);
1442 return;
1444 case 0:
1445 /* No code, print as usual. */
1446 break;
1448 default:
1450 #define BADFORMAT "Internal: Invalid operand for '%c'"
1451 char s[sizeof BADFORMAT];
1452 sprintf (s, BADFORMAT, code);
1453 fatal_insn (s, x);
1457 /* Print an operand as without a modifier letter. */
1458 switch (GET_CODE (operand))
1460 case REG:
1461 if (REGNO (operand) > 15)
1462 internal_error ("Internal: Bad register: %d", REGNO (operand));
1463 fprintf (file, "$%s", reg_names[REGNO (operand)]);
1464 return;
1466 case MEM:
1467 output_address (XEXP (operand, 0));
1468 return;
1470 case CONST_DOUBLE:
1471 if (GET_MODE (operand) == VOIDmode)
1472 /* A long long constant. */
1473 output_addr_const (file, operand);
1474 else
1476 /* Only single precision is allowed as plain operands the
1477 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
1478 documented. */
1479 REAL_VALUE_TYPE r;
1480 long l;
1482 /* FIXME: Perhaps check overflow of the "single". */
1483 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1484 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1486 fprintf (file, "0x%lx", l);
1488 return;
1490 case UNSPEC:
1491 ASSERT_PLT_UNSPEC (operand);
1492 /* Fall through. */
1494 case CONST:
1495 cris_output_addr_const (file, operand);
1496 return;
1498 case MULT:
1499 case ASHIFT:
1501 /* For a (MULT (reg X) const_int) we output "rX.S". */
1502 int i = GET_CODE (XEXP (operand, 1)) == CONST_INT
1503 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1504 rtx reg = GET_CODE (XEXP (operand, 1)) == CONST_INT
1505 ? XEXP (operand, 0) : XEXP (operand, 1);
1507 if (GET_CODE (reg) != REG
1508 || (GET_CODE (XEXP (operand, 0)) != CONST_INT
1509 && GET_CODE (XEXP (operand, 1)) != CONST_INT))
1510 fatal_insn ("Can't print operand", x);
1512 cris_print_base (reg, file);
1513 fprintf (file, ".%c",
1514 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1515 : i == 4 ? 'd'
1516 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1517 : 'd');
1518 return;
1521 default:
1522 /* No need to handle all strange variants, let output_addr_const
1523 do it for us. */
1524 if (CONSTANT_P (operand))
1526 cris_output_addr_const (file, operand);
1527 return;
1530 fatal_insn ("Internal: Cannot decode operand", x);
1534 /* The PRINT_OPERAND_ADDRESS worker. */
1536 void
1537 cris_print_operand_address (file, x)
1538 FILE *file;
1539 rtx x;
1541 /* All these were inside MEM:s so output indirection characters. */
1542 putc ('[', file);
1544 if (CONSTANT_ADDRESS_P (x))
1545 cris_output_addr_const (file, x);
1546 else if (BASE_OR_AUTOINCR_P (x))
1547 cris_print_base (x, file);
1548 else if (GET_CODE (x) == PLUS)
1550 rtx x1, x2;
1552 x1 = XEXP (x, 0);
1553 x2 = XEXP (x, 1);
1554 if (BASE_P (x1))
1556 cris_print_base (x1, file);
1557 cris_print_index (x2, file);
1559 else if (BASE_P (x2))
1561 cris_print_base (x2, file);
1562 cris_print_index (x1, file);
1564 else
1565 fatal_insn ("Internal: This is not a recognized address", x);
1567 else if (GET_CODE (x) == MEM)
1569 /* A DIP. Output more indirection characters. */
1570 putc ('[', file);
1571 cris_print_base (XEXP (x, 0), file);
1572 putc (']', file);
1574 else
1575 fatal_insn ("Internal: This is not a recognized address", x);
1577 putc (']', file);
1580 /* The RETURN_ADDR_RTX worker.
1581 We mark that the return address is used, either by EH or
1582 __builtin_return_address, for use by the function prologue and
1583 epilogue. FIXME: This isn't optimal; we just use the mark in the
1584 prologue and epilogue to say that the return address is to be stored
1585 in the stack frame. We could return SRP for leaf-functions and use the
1586 initial-value machinery. */
1589 cris_return_addr_rtx (count, frameaddr)
1590 int count;
1591 rtx frameaddr ATTRIBUTE_UNUSED;
1593 cfun->machine->needs_return_address_on_stack = 1;
1595 /* The return-address is stored just above the saved frame-pointer (if
1596 present). Apparently we can't eliminate from the frame-pointer in
1597 that direction, so use the incoming args (maybe pretended) pointer. */
1598 return count == 0
1599 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1600 : NULL_RTX;
1603 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1604 handles FP -> SP elimination offset. */
1606 static int
1607 cris_initial_frame_pointer_offset ()
1609 int regno;
1611 /* Initial offset is 0 if we dont have a frame pointer. */
1612 int offs = 0;
1614 /* And 4 for each register pushed. */
1615 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1616 if ((((regs_ever_live[regno]
1617 && !call_used_regs[regno])
1618 || (regno == PIC_OFFSET_TABLE_REGNUM
1619 && (current_function_uses_pic_offset_table
1620 /* It is saved anyway, if there would be a gap. */
1621 || (flag_pic
1622 && regs_ever_live[regno + 1]
1623 && !call_used_regs[regno + 1]))))
1624 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1625 && regno != CRIS_SRP_REGNUM)
1626 || (current_function_calls_eh_return
1627 && (regno == EH_RETURN_DATA_REGNO (0)
1628 || regno == EH_RETURN_DATA_REGNO (1)
1629 || regno == EH_RETURN_DATA_REGNO (2)
1630 || regno == EH_RETURN_DATA_REGNO (3))))
1631 offs += 4;
1633 /* And then, last, we add the locals allocated. */
1634 offs += get_frame_size ();
1636 /* And more; the accumulated args size. */
1637 offs += current_function_outgoing_args_size;
1639 /* Then round it off, in case we use aligned stack. */
1640 if (TARGET_STACK_ALIGN)
1641 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1643 return offs;
1646 /* The INITIAL_ELIMINATION_OFFSET worker.
1647 Calculate the difference between imaginary registers such as frame
1648 pointer and the stack pointer. Used to eliminate the frame pointer
1649 and imaginary arg pointer. */
1652 cris_initial_elimination_offset (fromreg, toreg)
1653 int fromreg;
1654 int toreg;
1656 int fp_sp_offset
1657 = cris_initial_frame_pointer_offset ();
1659 /* We should be able to use regs_ever_live and related prologue
1660 information here, or alpha should not as well. */
1661 int return_address_on_stack
1662 = regs_ever_live[CRIS_SRP_REGNUM]
1663 || cfun->machine->needs_return_address_on_stack != 0;
1665 /* Here we act as if the frame-pointer is needed. */
1666 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1668 if (fromreg == ARG_POINTER_REGNUM
1669 && toreg == FRAME_POINTER_REGNUM)
1670 return ap_fp_offset;
1672 /* Between the frame pointer and the stack are only "normal" stack
1673 variables and saved registers. */
1674 if (fromreg == FRAME_POINTER_REGNUM
1675 && toreg == STACK_POINTER_REGNUM)
1676 return fp_sp_offset;
1678 /* We need to balance out the frame pointer here. */
1679 if (fromreg == ARG_POINTER_REGNUM
1680 && toreg == STACK_POINTER_REGNUM)
1681 return ap_fp_offset + fp_sp_offset - 4;
1683 abort ();
1686 /* This function looks into the pattern to see how this insn affects
1687 condition codes.
1689 Used when to eliminate test insns before a condition-code user,
1690 such as a "scc" insn or a conditional branch. This includes
1691 checking if the entities that cc was updated by, are changed by the
1692 operation.
1694 Currently a jumble of the old peek-inside-the-insn and the newer
1695 check-cc-attribute methods. */
1697 void
1698 cris_notice_update_cc (exp, insn)
1699 rtx exp;
1700 rtx insn;
1702 /* Check if user specified "-mcc-init" as a bug-workaround. FIXME:
1703 TARGET_CCINIT does not work; we must set CC_REVERSED as below.
1704 Several test-cases will otherwise fail, for example
1705 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1706 if (TARGET_CCINIT)
1708 CC_STATUS_INIT;
1709 return;
1712 /* Slowly, we're converting to using attributes to control the setting
1713 of condition-code status. */
1714 switch (get_attr_cc (insn))
1716 case CC_NONE:
1717 /* Even if it is "none", a setting may clobber a previous
1718 cc-value, so check. */
1719 if (GET_CODE (exp) == SET)
1721 if (cc_status.value1
1722 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1723 cc_status.value1))
1724 cc_status.value1 = 0;
1726 if (cc_status.value2
1727 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1728 cc_status.value2))
1729 cc_status.value2 = 0;
1731 return;
1733 case CC_CLOBBER:
1734 CC_STATUS_INIT;
1735 break;
1737 case CC_NORMAL:
1738 /* Which means, for:
1739 (set (cc0) (...)):
1740 CC is (...).
1742 (set (reg) (...)):
1743 CC is (reg) and (...) - unless (...) is 0, then CC does not change.
1744 CC_NO_OVERFLOW unless (...) is reg or mem.
1746 (set (mem) (...)):
1747 CC does not change.
1749 (set (pc) (...)):
1750 CC does not change.
1752 (parallel
1753 (set (reg1) (mem (bdap/biap)))
1754 (set (reg2) (bdap/biap))):
1755 CC is (reg1) and (mem (reg2))
1757 (parallel
1758 (set (mem (bdap/biap)) (reg1)) [or 0]
1759 (set (reg2) (bdap/biap))):
1760 CC does not change.
1762 (where reg and mem includes strict_low_parts variants thereof)
1764 For all others, assume CC is clobbered.
1765 Note that we do not have to care about setting CC_NO_OVERFLOW,
1766 since the overflow flag is set to 0 (i.e. right) for
1767 instructions where it does not have any sane sense, but where
1768 other flags have meanings. (This includes shifts; the carry is
1769 not set by them).
1771 Note that there are other parallel constructs we could match,
1772 but we don't do that yet. */
1774 if (GET_CODE (exp) == SET)
1776 /* FIXME: Check when this happens. It looks like we should
1777 actually do a CC_STATUS_INIT here to be safe. */
1778 if (SET_DEST (exp) == pc_rtx)
1779 return;
1781 /* Record CC0 changes, so we do not have to output multiple
1782 test insns. */
1783 if (SET_DEST (exp) == cc0_rtx)
1785 cc_status.value1 = SET_SRC (exp);
1786 cc_status.value2 = 0;
1788 /* Handle flags for the special btstq on one bit. */
1789 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1790 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1792 if (GET_CODE (XEXP (SET_SRC (exp), 0)) == CONST_INT)
1793 /* Using cmpq. */
1794 cc_status.flags = CC_INVERTED;
1795 else
1796 /* A one-bit btstq. */
1797 cc_status.flags = CC_Z_IN_NOT_N;
1799 else
1800 cc_status.flags = 0;
1802 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1804 if (!REG_P (XEXP (SET_SRC (exp), 0))
1805 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1806 /* For some reason gcc will not canonicalize compare
1807 operations, reversing the sign by itself if
1808 operands are in wrong order. */
1809 /* (But NOT inverted; eq is still eq.) */
1810 cc_status.flags = CC_REVERSED;
1812 /* This seems to be overlooked by gcc. FIXME: Check again.
1813 FIXME: Is it really safe? */
1814 cc_status.value2
1815 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1816 XEXP (SET_SRC (exp), 0),
1817 XEXP (SET_SRC (exp), 1));
1819 return;
1821 else if (REG_P (SET_DEST (exp))
1822 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1823 && REG_P (XEXP (SET_DEST (exp), 0))))
1825 /* A register is set; normally CC is set to show that no
1826 test insn is needed. Catch the exceptions. */
1828 /* If not to cc0, then no "set"s in non-natural mode give
1829 ok cc0... */
1830 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1831 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1833 /* ... except add:s and sub:s in DImode. */
1834 if (GET_MODE (SET_DEST (exp)) == DImode
1835 && (GET_CODE (SET_SRC (exp)) == PLUS
1836 || GET_CODE (SET_SRC (exp)) == MINUS))
1838 cc_status.flags = 0;
1839 cc_status.value1 = SET_DEST (exp);
1840 cc_status.value2 = SET_SRC (exp);
1842 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1843 cc_status.value2))
1844 cc_status.value2 = 0;
1846 /* Add and sub may set V, which gets us
1847 unoptimizable results in "gt" and "le" condition
1848 codes. */
1849 cc_status.flags |= CC_NO_OVERFLOW;
1851 return;
1854 else if (SET_SRC (exp) == const0_rtx)
1856 /* There's no CC0 change when clearing a register or
1857 memory. Just check for overlap. */
1858 if ((cc_status.value1
1859 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1860 cc_status.value1)))
1861 cc_status.value1 = 0;
1863 if ((cc_status.value2
1864 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1865 cc_status.value2)))
1866 cc_status.value2 = 0;
1868 return;
1870 else
1872 cc_status.flags = 0;
1873 cc_status.value1 = SET_DEST (exp);
1874 cc_status.value2 = SET_SRC (exp);
1876 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1877 cc_status.value2))
1878 cc_status.value2 = 0;
1880 /* Some operations may set V, which gets us
1881 unoptimizable results in "gt" and "le" condition
1882 codes. */
1883 if (GET_CODE (SET_SRC (exp)) == PLUS
1884 || GET_CODE (SET_SRC (exp)) == MINUS
1885 || GET_CODE (SET_SRC (exp)) == NEG)
1886 cc_status.flags |= CC_NO_OVERFLOW;
1888 return;
1891 else if (GET_CODE (SET_DEST (exp)) == MEM
1892 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1893 && GET_CODE (XEXP (SET_DEST (exp), 0)) == MEM))
1895 /* When SET to MEM, then CC is not changed (except for
1896 overlap). */
1897 if ((cc_status.value1
1898 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1899 cc_status.value1)))
1900 cc_status.value1 = 0;
1902 if ((cc_status.value2
1903 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1904 cc_status.value2)))
1905 cc_status.value2 = 0;
1907 return;
1910 else if (GET_CODE (exp) == PARALLEL)
1912 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1913 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1914 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1916 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1917 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 1)) == MEM)
1919 /* For "move.S [rx=ry+o],rz", say CC reflects
1920 value1=rz and value2=[rx] */
1921 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1922 cc_status.value2
1923 = gen_rtx_MEM (GET_MODE (XEXP (XVECEXP (exp, 0, 0), 0)),
1924 XEXP (XVECEXP (exp, 0, 1), 0));
1925 cc_status.flags = 0;
1927 /* Huh? A side-effect cannot change the destination
1928 register. */
1929 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1930 cc_status.value2))
1931 internal_error ("Internal: sideeffect-insn affecting main effect");
1932 return;
1934 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1935 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1936 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 0)) == MEM)
1938 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1939 say flags are not changed, except for overlap. */
1940 if ((cc_status.value1
1941 && cris_reg_overlap_mentioned_p (XEXP
1942 (XVECEXP
1943 (exp, 0, 0), 0),
1944 cc_status.value1))
1945 || (cc_status.value2
1946 && cris_reg_overlap_mentioned_p (XEXP
1947 (XVECEXP
1948 (exp, 0, 1), 0),
1949 cc_status.value2)))
1950 CC_STATUS_INIT;
1951 return;
1955 break;
1957 default:
1958 /* Unknown cc_attr value. */
1959 abort ();
1962 CC_STATUS_INIT;
1965 /* Return != 0 if the return sequence for the current function is short,
1966 like "ret" or "jump [sp+]". Prior to reloading, we can't tell how
1967 many registers must be saved, so return 0 then. */
1970 cris_simple_epilogue ()
1972 int regno;
1973 int reglimit = STACK_POINTER_REGNUM;
1974 int lastreg = -1;
1976 if (! reload_completed
1977 || frame_pointer_needed
1978 || get_frame_size () != 0
1979 || current_function_pretend_args_size
1980 || current_function_args_size
1981 || current_function_outgoing_args_size
1982 || current_function_calls_eh_return
1984 /* If we're not supposed to emit prologue and epilogue, we must
1985 not emit return-type instructions. */
1986 || !TARGET_PROLOGUE_EPILOGUE)
1987 return 0;
1989 /* We allow a "movem [sp+],rN" to sit in front if the "jump [sp+]" or
1990 in the delay-slot of the "ret". */
1991 for (regno = 0; regno < reglimit; regno++)
1992 if ((regs_ever_live[regno] && ! call_used_regs[regno])
1993 || (regno == PIC_OFFSET_TABLE_REGNUM
1994 && (current_function_uses_pic_offset_table
1995 /* It is saved anyway, if there would be a gap. */
1996 || (flag_pic
1997 && regs_ever_live[regno + 1]
1998 && !call_used_regs[regno + 1]))))
2000 if (lastreg != regno - 1)
2001 return 0;
2002 lastreg = regno;
2005 return 1;
2008 /* The ADDRESS_COST worker. */
2011 cris_address_cost (x)
2012 rtx x;
2014 /* The metric to use for the cost-macros is unclear.
2015 The metric used here is (the number of cycles needed) / 2,
2016 where we consider equal a cycle for a word of code and a cycle to
2017 read memory. */
2019 /* The cheapest addressing modes get 0, since nothing extra is needed. */
2020 if (BASE_OR_AUTOINCR_P (x))
2021 return 0;
2023 /* An indirect mem must be a DIP. This means two bytes extra for code,
2024 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
2025 if (GET_CODE (x) == MEM)
2026 return (2 + 4) / 2;
2028 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
2029 an extra DIP prefix and 4 bytes of constant in most cases.
2030 For PIC and a symbol with a GOT entry, we double the cost since we
2031 add a [rPIC+...] offset. A GOT-less symbol uses a BDAP prefix
2032 equivalent to the DIP prefix for non-PIC, hence the same cost. */
2033 if (CONSTANT_P (x))
2034 return flag_pic && cris_got_symbol (x) ? 2 * (2 + 4) / 2 : (2 + 4) / 2;
2036 /* Handle BIAP and BDAP prefixes. */
2037 if (GET_CODE (x) == PLUS)
2039 rtx tem1 = XEXP (x, 0);
2040 rtx tem2 = XEXP (x, 1);
2042 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
2043 recognize the typical MULT which is always in tem1 because of
2044 insn canonicalization. */
2045 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
2046 || REG_P (tem1))
2047 return 2 / 2;
2049 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
2050 PLUS is always found in tem2. */
2051 if (GET_CODE (tem2) == CONST_INT
2052 && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
2053 return 2 / 2;
2055 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2056 bytes. */
2057 if (GET_CODE (tem2) == CONST_INT
2058 && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
2059 return (2 + 2) / 2;
2061 /* A BDAP with some other constant is 2 bytes extra. */
2062 if (CONSTANT_P (tem2))
2063 return (2 + 2 + 2) / 2;
2065 /* BDAP with something indirect should have a higher cost than
2066 BIAP with register. FIXME: Should it cost like a MEM or more? */
2067 /* Don't need to check it, it's the only one left.
2068 FIXME: There was a REG test missing, perhaps there are others.
2069 Think more. */
2070 return (2 + 2 + 2) / 2;
2073 /* What else? Return a high cost. It matters only for valid
2074 addressing modes. */
2075 return 10;
2078 /* Check various objections to the side-effect. Used in the test-part
2079 of an anonymous insn describing an insn with a possible side-effect.
2080 Returns nonzero if the implied side-effect is ok.
2082 code : PLUS or MULT
2083 ops : An array of rtx:es. lreg, rreg, rval,
2084 The variables multop and other_op are indexes into this,
2085 or -1 if they are not applicable.
2086 lreg : The register that gets assigned in the side-effect.
2087 rreg : One register in the side-effect expression
2088 rval : The other register, or an int.
2089 multop : An integer to multiply rval with.
2090 other_op : One of the entities of the main effect,
2091 whose mode we must consider. */
2094 cris_side_effect_mode_ok (code, ops, lreg, rreg, rval, multop, other_op)
2095 enum rtx_code code;
2096 rtx *ops;
2097 int lreg, rreg, rval, multop, other_op;
2099 /* Find what value to multiply with, for rx =ry + rz * n. */
2100 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2102 rtx reg_rtx = ops[rreg];
2103 rtx val_rtx = ops[rval];
2105 /* The operands may be swapped. Canonicalize them in reg_rtx and
2106 val_rtx, where reg_rtx always is a reg (for this constraint to
2107 match). */
2108 if (! BASE_P (reg_rtx))
2109 reg_rtx = val_rtx, val_rtx = ops[rreg];
2111 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
2112 we have no business. */
2113 if (! BASE_P (reg_rtx))
2114 return 0;
2116 /* Don't do this when -mno-split. */
2117 if (!TARGET_SIDE_EFFECT_PREFIXES)
2118 return 0;
2120 /* The mult expression may be hidden in lreg. FIXME: Add more
2121 commentary about that. */
2122 if (GET_CODE (val_rtx) == MULT)
2124 mult = INTVAL (XEXP (val_rtx, 1));
2125 val_rtx = XEXP (val_rtx, 0);
2126 code = MULT;
2129 /* First check the "other operand". */
2130 if (other_op >= 0)
2132 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2133 return 0;
2135 /* Check if the lvalue register is the same as the "other
2136 operand". If so, the result is undefined and we shouldn't do
2137 this. FIXME: Check again. */
2138 if ((BASE_P (ops[lreg])
2139 && BASE_P (ops[other_op])
2140 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2141 || rtx_equal_p (ops[other_op], ops[lreg]))
2142 return 0;
2145 /* Do not accept frame_pointer_rtx as any operand. */
2146 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2147 || ops[rval] == frame_pointer_rtx
2148 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2149 return 0;
2151 if (code == PLUS
2152 && ! BASE_P (val_rtx))
2155 /* Do not allow rx = rx + n if a normal add or sub with same size
2156 would do. */
2157 if (rtx_equal_p (ops[lreg], reg_rtx)
2158 && GET_CODE (val_rtx) == CONST_INT
2159 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2160 return 0;
2162 /* Check allowed cases, like [r(+)?].[bwd] and const.
2163 A symbol is not allowed with PIC. */
2164 if (CONSTANT_P (val_rtx))
2165 return flag_pic == 0 || cris_symbol (val_rtx) == 0;
2167 if (GET_CODE (val_rtx) == MEM
2168 && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2169 return 1;
2171 if (GET_CODE (val_rtx) == SIGN_EXTEND
2172 && GET_CODE (XEXP (val_rtx, 0)) == MEM
2173 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2174 return 1;
2176 /* If we got here, it's not a valid addressing mode. */
2177 return 0;
2179 else if (code == MULT
2180 || (code == PLUS && BASE_P (val_rtx)))
2182 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2183 if (rtx_equal_p (ops[lreg], reg_rtx)
2184 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2185 return 0;
2187 /* Do not allow bad multiply-values. */
2188 if (mult != 1 && mult != 2 && mult != 4)
2189 return 0;
2191 /* Only allow r + ... */
2192 if (! BASE_P (reg_rtx))
2193 return 0;
2195 /* If we got here, all seems ok.
2196 (All checks need to be done above). */
2197 return 1;
2200 /* If we get here, the caller got its initial tests wrong. */
2201 internal_error ("Internal: cris_side_effect_mode_ok with bad operands");
2204 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2205 does not handle the case where the IN operand is strict_low_part; it
2206 does handle it for X. Test-case in Axis-20010516. This function takes
2207 care of that for THIS port. FIXME: strict_low_part is going away
2208 anyway. */
2210 static int
2211 cris_reg_overlap_mentioned_p (x, in)
2212 rtx x, in;
2214 /* The function reg_overlap_mentioned now handles when X is
2215 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2216 if (GET_CODE (in) == STRICT_LOW_PART)
2217 in = XEXP (in, 0);
2219 return reg_overlap_mentioned_p (x, in);
2222 /* The TARGET_ASM_NAMED_SECTION worker.
2223 We just dispatch to the functions for ELF and a.out. */
2225 void
2226 cris_target_asm_named_section (name, flags)
2227 const char *name;
2228 unsigned int flags;
2230 if (! TARGET_ELF)
2231 default_no_named_section (name, flags);
2232 else
2233 default_elf_asm_named_section (name, flags);
2236 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2239 cris_legitimate_pic_operand (x)
2240 rtx x;
2242 /* The PIC representation of a symbol with a GOT entry will be (for
2243 example; relocations differ):
2244 sym => [rPIC+sym:GOT]
2245 and for a GOT-less symbol it will be (for example, relocation differ):
2246 sym => rPIC+sym:GOTOFF
2247 so only a symbol with a GOT is by itself a valid operand, and it
2248 can't be a sum of a symbol and an offset. */
2249 return ! cris_symbol (x) || cris_got_symbol (x);
2252 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2253 CONSTANT_P. */
2256 cris_symbol (x)
2257 rtx x;
2259 switch (GET_CODE (x))
2261 case SYMBOL_REF:
2262 case LABEL_REF:
2263 return 1;
2265 case UNSPEC:
2266 /* A PLT reference. */
2267 ASSERT_PLT_UNSPEC (x);
2268 return 1;
2270 case CONST:
2271 return cris_symbol (XEXP (x, 0));
2273 case PLUS:
2274 case MINUS:
2275 return cris_symbol (XEXP (x, 0)) || cris_symbol (XEXP (x, 1));
2277 case CONST_INT:
2278 case CONST_DOUBLE:
2279 case CONSTANT_P_RTX:
2280 return 0;
2282 default:
2283 fatal_insn ("Unrecognized supposed constant", x);
2286 return 1;
2289 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2290 CONSTANT_P, and the symbol does not need a GOT entry. Also set
2291 current_function_uses_pic_offset_table if we're generating PIC and ever
2292 see something that would need one. */
2295 cris_gotless_symbol (x)
2296 rtx x;
2298 switch (GET_CODE (x))
2300 case UNSPEC:
2301 ASSERT_PLT_UNSPEC (x);
2302 return 1;
2304 case SYMBOL_REF:
2305 if (flag_pic && cfun != NULL)
2306 current_function_uses_pic_offset_table = 1;
2307 return SYMBOL_REF_FLAG (x);
2309 case LABEL_REF:
2310 /* We don't set current_function_uses_pic_offset_table for
2311 LABEL_REF:s in here, since they are almost always originating
2312 from some branch. The only time it does not come from a label is
2313 when GCC does something like __builtin_setjmp. Then we get the
2314 LABEL_REF from the movsi expander, so we mark it there as a
2315 special case. */
2316 return 1;
2318 case CONST:
2319 return cris_gotless_symbol (XEXP (x, 0));
2321 case PLUS:
2322 case MINUS:
2324 int x0 = cris_gotless_symbol (XEXP (x, 0)) != 0;
2325 int x1 = cris_gotless_symbol (XEXP (x, 1)) != 0;
2327 /* One and only one of them must be a local symbol. Neither must
2328 be some other, more general kind of symbol. */
2329 return
2330 (x0 ^ x1)
2331 && ! (x0 == 0 && cris_symbol (XEXP (x, 0)))
2332 && ! (x1 == 0 && cris_symbol (XEXP (x, 1)));
2335 case CONST_INT:
2336 case CONST_DOUBLE:
2337 case CONSTANT_P_RTX:
2338 return 0;
2340 default:
2341 fatal_insn ("Unrecognized supposed constant", x);
2344 return 1;
2347 /* Return non-zero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2348 CONSTANT_P, and the symbol needs a GOT entry. */
2351 cris_got_symbol (x)
2352 rtx x;
2354 switch (GET_CODE (x))
2356 case UNSPEC:
2357 ASSERT_PLT_UNSPEC (x);
2358 return 0;
2360 case SYMBOL_REF:
2361 if (flag_pic && cfun != NULL)
2362 current_function_uses_pic_offset_table = 1;
2363 return ! SYMBOL_REF_FLAG (x);
2365 case CONST:
2366 return cris_got_symbol (XEXP (x, 0));
2368 case LABEL_REF:
2369 /* A LABEL_REF is never visible as a symbol outside the local
2370 function. */
2371 case PLUS:
2372 case MINUS:
2373 /* Nope, can't access the GOT for "symbol + offset". */
2374 return 0;
2376 case CONST_INT:
2377 case CONST_DOUBLE:
2378 case CONSTANT_P_RTX:
2379 return 0;
2381 default:
2382 fatal_insn ("Unrecognized supposed constant in cris_global_pic_symbol",
2386 return 1;
2389 /* The OVERRIDE_OPTIONS worker.
2390 As is the norm, this also parses -mfoo=bar type parameters. */
2392 void
2393 cris_override_options ()
2395 if (cris_max_stackframe_str)
2397 cris_max_stackframe = atoi (cris_max_stackframe_str);
2399 /* Do some sanity checking. */
2400 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2401 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2402 cris_max_stackframe, 0x20000000);
2405 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2406 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2407 cris_cpu_version = CRIS_CPU_SVINTO;
2408 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2409 cris_cpu_version = CRIS_CPU_ETRAX4;
2411 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2412 if (cris_cpu_str)
2414 cris_cpu_version
2415 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2417 if (strcmp ("etrax4", cris_cpu_str) == 0)
2418 cris_cpu_version = 3;
2420 if (strcmp ("svinto", cris_cpu_str) == 0
2421 || strcmp ("etrax100", cris_cpu_str) == 0)
2422 cris_cpu_version = 8;
2424 if (strcmp ("ng", cris_cpu_str) == 0
2425 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2426 cris_cpu_version = 10;
2428 if (cris_cpu_version < 0 || cris_cpu_version > 10)
2429 error ("Unknown CRIS version specification in -march= or -mcpu= : %s",
2430 cris_cpu_str);
2432 /* Set the target flags. */
2433 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2434 target_flags |= TARGET_MASK_ETRAX4_ADD;
2436 /* If this is Svinto or higher, align for 32 bit accesses. */
2437 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2438 target_flags
2439 |= (TARGET_MASK_SVINTO | TARGET_MASK_ALIGN_BY_32
2440 | TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2441 | TARGET_MASK_DATA_ALIGN);
2443 /* Note that we do not add new flags when it can be completely
2444 described with a macro that uses -mcpu=X. So
2445 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2448 if (cris_tune_str)
2450 int cris_tune
2451 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2453 if (strcmp ("etrax4", cris_tune_str) == 0)
2454 cris_tune = 3;
2456 if (strcmp ("svinto", cris_tune_str) == 0
2457 || strcmp ("etrax100", cris_tune_str) == 0)
2458 cris_tune = 8;
2460 if (strcmp ("ng", cris_tune_str) == 0
2461 || strcmp ("etrax100lx", cris_tune_str) == 0)
2462 cris_tune = 10;
2464 if (cris_tune < 0 || cris_tune > 10)
2465 error ("Unknown CRIS cpu version specification in -mtune= : %s",
2466 cris_tune_str);
2468 if (cris_tune >= CRIS_CPU_SVINTO)
2469 /* We have currently nothing more to tune than alignment for
2470 memory accesses. */
2471 target_flags
2472 |= (TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2473 | TARGET_MASK_DATA_ALIGN | TARGET_MASK_ALIGN_BY_32);
2476 if (flag_pic)
2478 /* Use error rather than warning, so invalid use is easily
2479 detectable. Still change to the values we expect, to avoid
2480 further errors. */
2481 if (! TARGET_LINUX)
2483 error ("-fPIC not supported in this configuration");
2484 flag_pic = 0;
2487 /* Turn off function CSE. We need to have the addresses reach the
2488 call expanders to get PLT-marked, as they could otherwise be
2489 compared against zero directly or indirectly. After visiting the
2490 call expanders they will then be cse:ed, as the call expanders
2491 force_reg the addresses, effectively forcing flag_no_function_cse
2492 to 0. */
2493 flag_no_function_cse = 1;
2496 if ((write_symbols == DWARF_DEBUG
2497 || write_symbols == DWARF2_DEBUG) && ! TARGET_ELF)
2499 warning ("Specified -g option is invalid with -maout and -melinux");
2500 write_symbols = DBX_DEBUG;
2503 /* Set the per-function-data initializer. */
2504 init_machine_status = cris_init_machine_status;
2507 /* The ASM_OUTPUT_MI_THUNK worker. */
2509 void
2510 cris_asm_output_mi_thunk (stream, thunkdecl, delta, funcdecl)
2511 FILE *stream;
2512 tree thunkdecl ATTRIBUTE_UNUSED;
2513 int delta;
2514 tree funcdecl;
2516 if (delta > 0)
2517 asm_fprintf (stream, "\tadd%s %d,$%s\n",
2518 ADDITIVE_SIZE_MODIFIER (delta), delta,
2519 reg_names[CRIS_FIRST_ARG_REG]);
2520 else if (delta < 0)
2521 asm_fprintf (stream, "\tsub%s %d,$%s\n",
2522 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2523 reg_names[CRIS_FIRST_ARG_REG]);
2525 if (flag_pic)
2527 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2529 STRIP_NAME_ENCODING (name, name);
2530 fprintf (stream, "add.d ");
2531 assemble_name (stream, name);
2532 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2534 else
2536 fprintf (stream, "jump ");
2537 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2538 fprintf (stream, "\n");
2542 /* The EXPAND_BUILTIN_VA_ARG worker. This is modified from the
2543 "standard" implementation of va_arg: read the value from the current
2544 address and increment by the size of one or two registers. The
2545 important difference for CRIS is that if the type is
2546 pass-by-reference, then perform an indirection. */
2549 cris_expand_builtin_va_arg (valist, type)
2550 tree valist;
2551 tree type;
2553 tree addr_tree, t;
2554 rtx addr;
2555 enum machine_mode mode = TYPE_MODE (type);
2556 int passed_size;
2558 /* Get AP. */
2559 addr_tree = valist;
2561 /* Check if the type is passed by value or by reference. */
2562 if (MUST_PASS_IN_STACK (mode, type)
2563 || CRIS_FUNCTION_ARG_SIZE (mode, type) > 8)
2565 tree type_ptr = build_pointer_type (type);
2566 addr_tree = build1 (INDIRECT_REF, type_ptr, addr_tree);
2567 passed_size = 4;
2569 else
2570 passed_size = (CRIS_FUNCTION_ARG_SIZE (mode, type) > 4) ? 8 : 4;
2572 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2573 addr = copy_to_reg (addr);
2575 /* Compute new value for AP. */
2576 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2577 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2578 build_int_2 (passed_size, 0)));
2579 TREE_SIDE_EFFECTS (t) = 1;
2580 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2582 return addr;
2585 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2586 mark functions. */
2588 void
2589 cris_init_expanders ()
2591 /* Nothing here at the moment. */
2594 /* Zero initialization is OK for all current fields. */
2596 static void
2597 cris_init_machine_status (p)
2598 struct function *p;
2600 p->machine = xcalloc (1, sizeof (struct machine_function));
2603 /* Split a 2 word move (DI or presumably DF) into component parts.
2604 Originally a copy of gen_split_move_double in m32r.c. */
2607 cris_split_movdx (operands)
2608 rtx *operands;
2610 enum machine_mode mode = GET_MODE (operands[0]);
2611 rtx dest = operands[0];
2612 rtx src = operands[1];
2613 rtx val;
2615 /* We might have (SUBREG (MEM)) here, so just get rid of the
2616 subregs to make this code simpler. It is safe to call
2617 alter_subreg any time after reload. */
2618 if (GET_CODE (dest) == SUBREG)
2619 dest = alter_subreg (dest);
2620 if (GET_CODE (src) == SUBREG)
2621 src = alter_subreg (src);
2623 start_sequence ();
2624 if (GET_CODE (dest) == REG)
2626 int dregno = REGNO (dest);
2628 /* Reg-to-reg copy. */
2629 if (GET_CODE (src) == REG)
2631 int sregno = REGNO (src);
2633 int reverse = (dregno == sregno + 1);
2635 /* We normally copy the low-numbered register first. However, if
2636 the first register operand 0 is the same as the second register of
2637 operand 1, we must copy in the opposite order. */
2638 emit_insn (gen_rtx_SET (VOIDmode,
2639 operand_subword (dest, reverse, TRUE, mode),
2640 operand_subword (src, reverse, TRUE, mode)));
2642 emit_insn (gen_rtx_SET (VOIDmode,
2643 operand_subword (dest, !reverse, TRUE, mode),
2644 operand_subword (src, !reverse, TRUE, mode)));
2646 /* Constant-to-reg copy. */
2647 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
2649 rtx words[2];
2650 split_double (src, &words[0], &words[1]);
2651 emit_insn (gen_rtx_SET (VOIDmode,
2652 operand_subword (dest, 0, TRUE, mode),
2653 words[0]));
2655 emit_insn (gen_rtx_SET (VOIDmode,
2656 operand_subword (dest, 1, TRUE, mode),
2657 words[1]));
2659 /* Mem-to-reg copy. */
2660 else if (GET_CODE (src) == MEM)
2662 /* If the high-address word is used in the address, we must load it
2663 last. Otherwise, load it first. */
2664 rtx addr = XEXP (src, 0);
2665 int reverse
2666 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2668 /* The original code imples that we can't do
2669 move.x [rN+],rM move.x [rN],rM+1
2670 when rN is dead, because of REG_NOTES damage. That is
2671 consistent with what I've seen, so don't try it.
2673 We have two different cases here; if the addr is POST_INC,
2674 just pass it through, otherwise add constants. */
2676 if (GET_CODE (addr) == POST_INC)
2678 emit_insn (gen_rtx_SET (VOIDmode,
2679 operand_subword (dest, 0, TRUE, mode),
2680 change_address (src, SImode, addr)));
2681 emit_insn (gen_rtx_SET (VOIDmode,
2682 operand_subword (dest, 1, TRUE, mode),
2683 change_address (src, SImode, addr)));
2685 else
2687 /* Make sure we don't get any other addresses with
2688 embedded postincrements. They should be stopped in
2689 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2690 safety. */
2691 if (side_effects_p (addr))
2692 fatal_insn ("Unexpected side-effects in address", addr);
2694 emit_insn (gen_rtx_SET
2695 (VOIDmode,
2696 operand_subword (dest, reverse, TRUE, mode),
2697 change_address
2698 (src, SImode,
2699 plus_constant (addr,
2700 reverse * UNITS_PER_WORD))));
2701 emit_insn (gen_rtx_SET
2702 (VOIDmode,
2703 operand_subword (dest, ! reverse, TRUE, mode),
2704 change_address
2705 (src, SImode,
2706 plus_constant (addr,
2707 (! reverse) *
2708 UNITS_PER_WORD))));
2711 else
2712 abort ();
2714 /* Reg-to-mem copy or clear mem. */
2715 else if (GET_CODE (dest) == MEM
2716 && (GET_CODE (src) == REG
2717 || src == const0_rtx
2718 || src == CONST0_RTX (DFmode)))
2720 rtx addr = XEXP (dest, 0);
2722 if (GET_CODE (addr) == POST_INC)
2724 emit_insn (gen_rtx_SET (VOIDmode,
2725 change_address (dest, SImode, addr),
2726 operand_subword (src, 0, TRUE, mode)));
2727 emit_insn (gen_rtx_SET (VOIDmode,
2728 change_address (dest, SImode, addr),
2729 operand_subword (src, 1, TRUE, mode)));
2731 else
2733 /* Make sure we don't get any other addresses with embedded
2734 postincrements. They should be stopped in
2735 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2736 if (side_effects_p (addr))
2737 fatal_insn ("Unexpected side-effects in address", addr);
2739 emit_insn (gen_rtx_SET
2740 (VOIDmode,
2741 change_address (dest, SImode, addr),
2742 operand_subword (src, 0, TRUE, mode)));
2744 emit_insn (gen_rtx_SET
2745 (VOIDmode,
2746 change_address (dest, SImode,
2747 plus_constant (addr,
2748 UNITS_PER_WORD)),
2749 operand_subword (src, 1, TRUE, mode)));
2753 else
2754 abort ();
2756 val = gen_sequence ();
2757 end_sequence ();
2758 return val;
2761 /* This is in essence a copy of output_addr_const altered to output
2762 symbolic operands as PIC.
2764 FIXME: Add hooks similar to ASM_OUTPUT_SYMBOL_REF to get this effect in
2765 the "real" output_addr_const. All we need is one for LABEL_REF (and
2766 one for CODE_LABEL?). */
2768 void
2769 cris_output_addr_const (file, x)
2770 FILE *file;
2771 rtx x;
2773 int is_plt = 0;
2775 restart:
2776 switch (GET_CODE (x))
2778 case UNSPEC:
2779 ASSERT_PLT_UNSPEC (x);
2780 x = XVECEXP (x, 0, 0);
2781 is_plt = 1;
2783 /* Fall through. */
2784 case SYMBOL_REF:
2785 if (flag_pic)
2787 const char *origstr = XSTR (x, 0);
2788 const char *str;
2790 STRIP_NAME_ENCODING (str, origstr);
2792 if (is_plt)
2794 if (cris_pic_sympart_only)
2796 assemble_name (file, str);
2797 fprintf (file, ":PLTG");
2799 else
2801 if (TARGET_AVOID_GOTPLT)
2802 /* We shouldn't get here. */
2803 abort ();
2805 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2806 assemble_name (file, XSTR (x, 0));
2808 if (flag_pic == 1)
2809 fprintf (file, ":GOTPLT16]");
2810 else
2811 fprintf (file, ":GOTPLT]");
2814 else if (cris_gotless_symbol (x))
2816 if (! cris_pic_sympart_only)
2817 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2818 assemble_name (file, str);
2819 fprintf (file, ":GOTOFF");
2821 else if (cris_got_symbol (x))
2823 if (cris_pic_sympart_only)
2824 abort ();
2825 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2826 assemble_name (file, XSTR (x, 0));
2828 if (flag_pic == 1)
2829 fprintf (file, ":GOT16]");
2830 else
2831 fprintf (file, ":GOT]");
2833 else
2834 fatal_insn ("Unexpected PIC symbol", x);
2836 /* Sanity check. */
2837 if (! current_function_uses_pic_offset_table)
2838 internal_error ("Emitting PIC operand, but PIC register isn't set up");
2840 else
2841 assemble_name (file, XSTR (x, 0));
2842 break;
2844 case LABEL_REF:
2845 /* If we get one of those here, it should be dressed as PIC. Branch
2846 labels are normally output with the 'l' specifier, which means it
2847 will go directly to output_asm_label and not end up here. */
2848 if (GET_CODE (XEXP (x, 0)) != CODE_LABEL
2849 && (GET_CODE (XEXP (x, 0)) != NOTE
2850 || NOTE_LINE_NUMBER (XEXP (x, 0)) != NOTE_INSN_DELETED_LABEL))
2851 fatal_insn ("Unexpected address expression", x);
2853 if (flag_pic)
2855 if (cris_gotless_symbol (x))
2857 if (! cris_pic_sympart_only)
2858 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
2859 cris_output_addr_const (file, XEXP (x, 0));
2861 fprintf (file, ":GOTOFF");
2863 else
2864 /* Labels are never marked as global symbols. */
2865 fatal_insn ("Unexpected PIC symbol", x);
2867 /* Sanity check. */
2868 if (! current_function_uses_pic_offset_table)
2869 internal_error ("Emitting PIC operand, but PIC register isn't set up");
2870 break;
2873 output_addr_const (file, x);
2874 break;
2876 case NOTE:
2877 if (NOTE_LINE_NUMBER (x) != NOTE_INSN_DELETED_LABEL)
2878 fatal_insn ("Unexpected NOTE as addr_const:", x);
2879 case CODE_LABEL:
2880 case CONST_INT:
2881 case CONST_DOUBLE:
2882 case ZERO_EXTEND:
2883 case SIGN_EXTEND:
2884 output_addr_const (file, x);
2885 break;
2887 case CONST:
2888 /* This used to output parentheses around the expression,
2889 but that does not work on the 386 (either ATT or BSD assembler). */
2890 cris_output_addr_const (file, XEXP (x, 0));
2891 break;
2893 case PLUS:
2894 /* Some assemblers need integer constants to appear last (eg masm). */
2895 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
2897 cris_output_addr_const (file, XEXP (x, 1));
2898 if (INTVAL (XEXP (x, 0)) >= 0)
2899 fprintf (file, "+");
2900 output_addr_const (file, XEXP (x, 0));
2902 else
2904 cris_output_addr_const (file, XEXP (x, 0));
2905 if (GET_CODE (XEXP (x, 1)) != CONST_INT
2906 || INTVAL (XEXP (x, 1)) >= 0)
2907 fprintf (file, "+");
2908 cris_output_addr_const (file, XEXP (x, 1));
2910 break;
2912 case MINUS:
2913 /* Avoid outputting things like x-x or x+5-x,
2914 since some assemblers can't handle that. */
2915 x = simplify_subtraction (x);
2916 if (GET_CODE (x) != MINUS)
2917 goto restart;
2919 cris_output_addr_const (file, XEXP (x, 0));
2920 fprintf (file, "-");
2921 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
2922 && INTVAL (XEXP (x, 1)) < 0)
2923 || GET_CODE (XEXP (x, 1)) != CONST_INT)
2925 fprintf (file, "%s", targetm.asm_out.open_paren);
2926 cris_output_addr_const (file, XEXP (x, 1));
2927 fprintf (file, "%s", targetm.asm_out.close_paren);
2929 else
2930 output_addr_const (file, XEXP (x, 1));
2931 break;
2933 default:
2934 fatal_insn ("Unexpected address expression", x);
2938 /* The ENCODE_SECTION_INFO worker. Code-in whether we can get away
2939 without a GOT entry (needed for externally visible objects but not for
2940 functions) into SYMBOL_REF_FLAG and add the PLT suffix for global
2941 functions. */
2943 void
2944 cris_encode_section_info (exp)
2945 tree exp;
2947 if (flag_pic)
2949 if (DECL_P (exp))
2951 if (TREE_CODE (exp) == FUNCTION_DECL
2952 && (TREE_PUBLIC (exp) || DECL_WEAK (exp)))
2953 SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0)) = 0;
2954 else
2955 SYMBOL_REF_FLAG (XEXP (DECL_RTL (exp), 0))
2956 = ! TREE_PUBLIC (exp) && ! DECL_WEAK (exp);
2958 else
2959 /* Others are local entities. */
2960 SYMBOL_REF_FLAG (XEXP (TREE_CST_RTL (exp), 0)) = 1;
2964 #if 0
2965 /* Various small functions to replace macros. Only called from a
2966 debugger. They might collide with gcc functions or system functions,
2967 so only emit them when '#if 1' above. */
2969 enum rtx_code Get_code PARAMS ((rtx));
2971 enum rtx_code
2972 Get_code (x)
2973 rtx x;
2975 return GET_CODE (x);
2978 const char *Get_mode PARAMS ((rtx));
2980 const char *
2981 Get_mode (x)
2982 rtx x;
2984 return GET_MODE_NAME (GET_MODE (x));
2987 rtx Xexp PARAMS ((rtx, int));
2990 Xexp (x, n)
2991 rtx x;
2992 int n;
2994 return XEXP (x, n);
2997 rtx Xvecexp PARAMS ((rtx, int, int));
3000 Xvecexp (x, n, m)
3001 rtx x;
3002 int n;
3004 return XVECEXP (x, n, m);
3007 int Get_rtx_len PARAMS ((rtx));
3010 Get_rtx_len (x)
3011 rtx x;
3013 return GET_RTX_LENGTH (GET_CODE (x));
3016 /* Use upper-case to distinguish from local variables that are sometimes
3017 called next_insn and prev_insn. */
3019 rtx Next_insn PARAMS ((rtx));
3022 Next_insn (insn)
3023 rtx insn;
3025 return NEXT_INSN (insn);
3028 rtx Prev_insn PARAMS ((rtx));
3031 Prev_insn (insn)
3032 rtx insn;
3034 return PREV_INSN (insn);
3036 #endif
3039 * Local variables:
3040 * eval: (c-set-style "gnu")
3041 * indent-tabs-mode: t
3042 * End: