target.h (init_libfuncs): New hook.
[gcc.git] / gcc / config / cris / cris.c
1 /* Definitions for GCC. Part of the machine description for CRIS.
2 Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Axis Communications. Written by Hans-Peter Nilsson.
4
5 This file is part of GCC.
6
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.
11
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.
16
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. */
21
22 #include "config.h"
23 #include "system.h"
24 #include "coretypes.h"
25 #include "tm.h"
26 #include "rtl.h"
27 #include "regs.h"
28 #include "hard-reg-set.h"
29 #include "real.h"
30 #include "insn-config.h"
31 #include "conditions.h"
32 #include "insn-attr.h"
33 #include "flags.h"
34 #include "tree.h"
35 #include "expr.h"
36 #include "except.h"
37 #include "function.h"
38 #include "toplev.h"
39 #include "recog.h"
40 #include "tm_p.h"
41 #include "debug.h"
42 #include "output.h"
43 #include "target.h"
44 #include "target-def.h"
45 #include "ggc.h"
46 #include "optabs.h"
47
48 /* Usable when we have an amount to add or subtract, and want the
49 optimal size of the insn. */
50 #define ADDITIVE_SIZE_MODIFIER(size) \
51 ((size) <= 63 ? "q" : (size) <= 255 ? "u.b" : (size) <= 65535 ? "u.w" : ".d")
52
53 #define ASSERT_PLT_UNSPEC(x) \
54 do \
55 { \
56 if (XEXP (x, 1) != NULL_RTX \
57 || (GET_CODE (XVECEXP (x, 0, 0)) != SYMBOL_REF \
58 && GET_CODE (XVECEXP (x, 0, 0)) != LABEL_REF)) \
59 abort (); \
60 } while (0)
61
62 #define LOSE_AND_RETURN(msgid, x) \
63 do \
64 { \
65 cris_operand_lossage (msgid, x); \
66 return; \
67 } while (0)
68
69 /* Per-function machine data. */
70 struct machine_function GTY(())
71 {
72 int needs_return_address_on_stack;
73 };
74
75 /* This little fix suppresses the 'u' or 's' when '%e' in assembly
76 pattern. */
77 static char cris_output_insn_is_bound = 0;
78
79 /* This one suppresses printing out the "rPIC+" in
80 "rPIC+sym:GOTOFF+offset" when doing PIC. For a PLT symbol, it
81 suppresses outputting it as [rPIC+sym:GOTPLT] and outputs similarly
82 just the "sym:GOTOFF" part. */
83 static int cris_pic_sympart_only = 0;
84
85 /* Fix for reg_overlap_mentioned_p. */
86 static int cris_reg_overlap_mentioned_p (rtx, rtx);
87
88 static void cris_print_base (rtx, FILE *);
89
90 static void cris_print_index (rtx, FILE *);
91
92 static struct machine_function * cris_init_machine_status (void);
93
94 static int cris_initial_frame_pointer_offset (void);
95
96 static int saved_regs_mentioned (rtx);
97
98 static void cris_target_asm_function_prologue (FILE *, HOST_WIDE_INT);
99
100 static void cris_target_asm_function_epilogue (FILE *, HOST_WIDE_INT);
101
102 static void cris_operand_lossage (const char *, rtx);
103
104 static void cris_asm_output_mi_thunk
105 (FILE *, tree, HOST_WIDE_INT, HOST_WIDE_INT, tree);
106
107 static void cris_file_start (void);
108 static void cris_init_libfuncs (void);
109
110 static bool cris_rtx_costs (rtx, int, int, int *);
111 static int cris_address_cost (rtx);
112
113 /* The function cris_target_asm_function_epilogue puts the last insn to
114 output here. It always fits; there won't be a symbol operand. Used in
115 delay_slots_for_epilogue and function_epilogue. */
116 static char save_last[80];
117
118 /* This is the argument from the "-max-stack-stackframe=" option. */
119 const char *cris_max_stackframe_str;
120
121 /* This is the argument from the "-march=" option. */
122 const char *cris_cpu_str;
123
124 /* This is the argument from the "-mtune=" option. */
125 const char *cris_tune_str;
126
127 /* This is the argument from the "-melinux-stacksize=" option. */
128 const char *cris_elinux_stacksize_str;
129
130 /* This is the parsed result of the "-max-stack-stackframe=" option. If
131 it (still) is zero, then there was no such option given. */
132 int cris_max_stackframe = 0;
133
134 /* This is the parsed result of the "-march=" option, if given. */
135 int cris_cpu_version = CRIS_DEFAULT_CPU_VERSION;
136
137 #undef TARGET_ASM_ALIGNED_HI_OP
138 #define TARGET_ASM_ALIGNED_HI_OP "\t.word\t"
139 #undef TARGET_ASM_ALIGNED_SI_OP
140 #define TARGET_ASM_ALIGNED_SI_OP "\t.dword\t"
141 #undef TARGET_ASM_ALIGNED_DI_OP
142 #define TARGET_ASM_ALIGNED_DI_OP "\t.quad\t"
143
144 /* We need to define these, since the 2byte, 4byte, 8byte op:s are only
145 available in ELF. These "normal" pseudos do not have any alignment
146 constraints or side-effects. */
147 #undef TARGET_ASM_UNALIGNED_HI_OP
148 #define TARGET_ASM_UNALIGNED_HI_OP TARGET_ASM_ALIGNED_HI_OP
149
150 #undef TARGET_ASM_UNALIGNED_SI_OP
151 #define TARGET_ASM_UNALIGNED_SI_OP TARGET_ASM_ALIGNED_SI_OP
152
153 #undef TARGET_ASM_UNALIGNED_DI_OP
154 #define TARGET_ASM_UNALIGNED_DI_OP TARGET_ASM_ALIGNED_DI_OP
155
156 #undef TARGET_ASM_FUNCTION_PROLOGUE
157 #define TARGET_ASM_FUNCTION_PROLOGUE cris_target_asm_function_prologue
158
159 #undef TARGET_ASM_FUNCTION_EPILOGUE
160 #define TARGET_ASM_FUNCTION_EPILOGUE cris_target_asm_function_epilogue
161
162 #undef TARGET_ASM_OUTPUT_MI_THUNK
163 #define TARGET_ASM_OUTPUT_MI_THUNK cris_asm_output_mi_thunk
164 #undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
165 #define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
166
167 #undef TARGET_ASM_FILE_START
168 #define TARGET_ASM_FILE_START cris_file_start
169
170 #undef TARGET_INIT_LIBFUNCS
171 #define TARGET_INIT_LIBFUNCS cris_init_libfuncs
172
173 #undef TARGET_RTX_COSTS
174 #define TARGET_RTX_COSTS cris_rtx_costs
175 #undef TARGET_ADDRESS_COST
176 #define TARGET_ADDRESS_COST cris_address_cost
177
178 struct gcc_target targetm = TARGET_INITIALIZER;
179
180 /* Predicate functions. */
181
182 /* This checks a part of an address, the one that is not a plain register
183 for an addressing mode using BDAP.
184 Allowed operands is either:
185 a) a register
186 b) a CONST operand (but not a symbol when generating PIC)
187 c) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
188
189 int
190 cris_bdap_operand (rtx op, enum machine_mode mode)
191 {
192 register enum rtx_code code = GET_CODE (op);
193
194 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
195 return 0;
196
197 /* Just return whether this is a simple register or constant. */
198 if (register_operand (op, mode)
199 || (CONSTANT_P (op) && !(flag_pic && cris_symbol (op))))
200 return 1;
201
202 /* Is it a [r] or possibly a [r+]? */
203 if (code == MEM)
204 {
205 rtx tem = XEXP (op, 0);
206
207 if (mode == SImode
208 && (register_operand (tem, SImode)
209 || (GET_CODE (tem) == POST_INC
210 && register_operand (XEXP (tem, 0), SImode))))
211 return 1;
212 else
213 return 0;
214 }
215
216 /* Perhaps a sign-extended mem: [r].(b|w) or [r+].(b|w)? */
217 if (code == SIGN_EXTEND)
218 {
219 rtx tem = XEXP (op, 0);
220
221 if (GET_CODE (tem) != MEM)
222 return 0;
223
224 tem = XEXP (tem, 0);
225 if (mode == SImode
226 && (register_operand (tem, SImode)
227 || (GET_CODE (tem) == POST_INC
228 && register_operand (XEXP (tem, 0), SImode))))
229 return 1;
230 else
231 return 0;
232 }
233
234 return 0;
235 }
236
237 /* This is similar to cris_bdap_operand:
238 It checks a part of an address, the one that is not a plain register
239 for an addressing mode using BDAP *or* BIAP.
240 Allowed operands is either:
241 a) a register
242 b) a CONST operand (but not a symbol when generating PIC)
243 c) a mult of (1, 2 or 4) and a register
244 d) a [r] or [r+] in SImode, or sign-extend from HI or QI. */
245
246 int
247 cris_bdap_biap_operand (rtx op, enum machine_mode mode)
248 {
249 register enum rtx_code code = GET_CODE (op);
250 rtx reg;
251 rtx val;
252
253 /* Check for bdap operand. */
254 if (cris_bdap_operand (op, mode))
255 return 1;
256
257 if (mode != SImode && (mode != VOIDmode || GET_MODE (op) != VOIDmode))
258 return 0;
259
260 /* Check that we're looking at a BIAP operand. */
261 if (code != MULT)
262 return 0;
263
264 /* Canonicalize register and multiplicand. */
265 if (GET_CODE (XEXP (op, 0)) == CONST_INT)
266 {
267 val = XEXP (op, 0);
268 reg = XEXP (op, 1);
269 }
270 else
271 {
272 val = XEXP (op, 1);
273 reg = XEXP (op, 0);
274 }
275
276 /* Check that the operands are correct after canonicalization. */
277 if (! register_operand (reg, SImode) || GET_CODE (val) != CONST_INT)
278 return 0;
279
280 /* Check that the multiplicand has a valid value. */
281 if ((code == MULT
282 && (INTVAL (val) == 1 || INTVAL (val) == 2 || INTVAL (val) == 4)))
283 return 1;
284
285 return 0;
286 }
287
288 /* Check if MODE is same as mode for X, and X is PLUS, MINUS, IOR or
289 AND or UMIN. */
290
291 int
292 cris_orthogonal_operator (rtx x, enum machine_mode mode)
293 {
294 enum rtx_code code = GET_CODE (x);
295
296 if (mode == VOIDmode)
297 mode = GET_MODE (x);
298
299 return (GET_MODE (x) == mode
300 && (code == PLUS || code == MINUS
301 || code == IOR || code == AND || code == UMIN));
302 }
303
304 /* Check if MODE is same as mode for X, and X is PLUS, IOR or AND or
305 UMIN. */
306
307 int
308 cris_commutative_orth_op (rtx x, enum machine_mode mode)
309 {
310 enum rtx_code code = GET_CODE (x);
311
312 if (mode == VOIDmode)
313 mode = GET_MODE (x);
314
315 return (GET_MODE (x) == mode &&
316 (code == PLUS
317 || code == IOR || code == AND || code == UMIN));
318 }
319
320 /* Check if MODE is same as mode for X, and X is PLUS or MINUS or UMIN. */
321
322 int
323 cris_operand_extend_operator (rtx x, enum machine_mode mode)
324 {
325 enum rtx_code code = GET_CODE (x);
326
327 if (mode == VOIDmode)
328 mode = GET_MODE (x);
329
330 return (GET_MODE (x) == mode
331 && (code == PLUS || code == MINUS || code == UMIN));
332 }
333
334 /* Check if MODE is same as mode for X, and X is PLUS or MINUS. */
335
336 int
337 cris_additive_operand_extend_operator (rtx x, enum machine_mode mode)
338 {
339 enum rtx_code code = GET_CODE (x);
340
341 if (mode == VOIDmode)
342 mode = GET_MODE (x);
343
344 return (GET_MODE (x) == mode
345 && (code == PLUS || code == MINUS));
346 }
347
348 /* Check to see if MODE is same as mode for X, and X is SIGN_EXTEND or
349 ZERO_EXTEND. */
350
351 int
352 cris_extend_operator (rtx x, enum machine_mode mode)
353 {
354 enum rtx_code code = GET_CODE (x);
355
356 if (mode == VOIDmode)
357 mode = GET_MODE (x);
358
359 return
360 (GET_MODE (x) == mode && (code == SIGN_EXTEND || code == ZERO_EXTEND));
361 }
362
363 /* Check to see if MODE is same as mode for X, and X is PLUS or BOUND. */
364
365 int
366 cris_plus_or_bound_operator (rtx x, enum machine_mode mode)
367 {
368 enum rtx_code code = GET_CODE (x);
369
370 if (mode == VOIDmode)
371 mode = GET_MODE (x);
372
373 return
374 (GET_MODE (x) == mode && (code == UMIN || code == PLUS));
375 }
376
377 /* Since with -fPIC, not all symbols are valid PIC symbols or indeed
378 general_operands, we have to have a predicate that matches it for the
379 "movsi" expander. */
380
381 int
382 cris_general_operand_or_symbol (rtx op, enum machine_mode mode)
383 {
384 return general_operand (op, mode)
385 || (CONSTANT_P (op) && cris_symbol (op));
386 }
387
388 /* Since a PIC symbol without a GOT entry is not a general_operand, we
389 have to have a predicate that matches it. We use this in the expanded
390 "movsi" anonymous pattern for PIC symbols. */
391
392 int
393 cris_general_operand_or_gotless_symbol (rtx op, enum machine_mode mode)
394 {
395 return general_operand (op, mode)
396 || (CONSTANT_P (op) && cris_gotless_symbol (op));
397 }
398
399 /* Since a PLT symbol is not a general_operand, we have to have a
400 predicate that matches it when we need it. We use this in the expanded
401 "call" and "call_value" anonymous patterns. */
402
403 int
404 cris_general_operand_or_plt_symbol (rtx op, enum machine_mode mode)
405 {
406 return general_operand (op, mode)
407 || (GET_CODE (op) == CONST
408 && GET_CODE (XEXP (op, 0)) == UNSPEC
409 && !TARGET_AVOID_GOTPLT);
410 }
411
412 /* This matches a (MEM (general_operand)) or
413 (MEM (cris_general_operand_or_symbol)). The second one isn't a valid
414 memory_operand, so we need this predicate to recognize call
415 destinations before we change them to a PLT operand (by wrapping in
416 UNSPEC 0). */
417
418 int
419 cris_mem_call_operand (rtx op, enum machine_mode mode)
420 {
421 rtx xmem;
422
423 if (GET_CODE (op) != MEM)
424 return 0;
425
426 if (memory_operand (op, mode))
427 return 1;
428
429 xmem = XEXP (op, 0);
430
431 return cris_general_operand_or_symbol (xmem, GET_MODE (op));
432 }
433
434 /* The CONDITIONAL_REGISTER_USAGE worker. */
435
436 void
437 cris_conditional_register_usage (void)
438 {
439 /* FIXME: This isn't nice. We should be able to use that register for
440 something else if the PIC table isn't needed. */
441 if (flag_pic)
442 fixed_regs[PIC_OFFSET_TABLE_REGNUM]
443 = call_used_regs[PIC_OFFSET_TABLE_REGNUM] = 1;
444 }
445
446 /* Return current_function_uses_pic_offset_table. For use in cris.md,
447 since some generated files do not include function.h. */
448
449 int
450 cris_cfun_uses_pic_table (void)
451 {
452 return current_function_uses_pic_offset_table;
453 }
454
455 /* Given an rtx, return the text string corresponding to the CODE of X.
456 Intended for use in the assembly language output section of a
457 define_insn. */
458
459 const char *
460 cris_op_str (rtx x)
461 {
462 cris_output_insn_is_bound = 0;
463 switch (GET_CODE (x))
464 {
465 case PLUS:
466 return "add";
467 break;
468
469 case MINUS:
470 return "sub";
471 break;
472
473 case MULT:
474 return "mul";
475 break;
476
477 case DIV:
478 return "div";
479 break;
480
481 case AND:
482 return "and";
483 break;
484
485 case IOR:
486 return "or";
487 break;
488
489 case XOR:
490 return "xor";
491 break;
492
493 case NOT:
494 return "not";
495 break;
496
497 case ASHIFT:
498 return "lsl";
499 break;
500
501 case LSHIFTRT:
502 return "lsr";
503 break;
504
505 case ASHIFTRT:
506 return "asr";
507 break;
508
509 case UMIN:
510 /* Used to control the sign/zero-extend character for the 'e' modifier.
511 BOUND has none. */
512 cris_output_insn_is_bound = 1;
513 return "bound";
514 break;
515
516 default:
517 return "Unknown operator";
518 break;
519 }
520 }
521
522 /* Emit an error message when we're in an asm, and a fatal error for
523 "normal" insns. Formatted output isn't easily implemented, since we
524 use output_operand_lossage to output the actual message and handle the
525 categorization of the error. */
526
527 static void
528 cris_operand_lossage (const char *msgid, rtx op)
529 {
530 debug_rtx (op);
531 output_operand_lossage ("%s", msgid);
532 }
533
534 /* Print an index part of an address to file. */
535
536 static void
537 cris_print_index (rtx index, FILE *file)
538 {
539 rtx inner = XEXP (index, 0);
540
541 /* Make the index "additive" unless we'll output a negative number, in
542 which case the sign character is free (as in free beer). */
543 if (GET_CODE (index) != CONST_INT || INTVAL (index) >= 0)
544 putc ('+', file);
545
546 if (REG_P (index))
547 fprintf (file, "$%s.b", reg_names[REGNO (index)]);
548 else if (CONSTANT_P (index))
549 cris_output_addr_const (file, index);
550 else if (GET_CODE (index) == MULT)
551 {
552 fprintf (file, "$%s.",
553 reg_names[REGNO (XEXP (index, 0))]);
554
555 putc (INTVAL (XEXP (index, 1)) == 2 ? 'w' : 'd', file);
556 }
557 else if (GET_CODE (index) == SIGN_EXTEND &&
558 GET_CODE (inner) == MEM)
559 {
560 rtx inner_inner = XEXP (inner, 0);
561
562 if (GET_CODE (inner_inner) == POST_INC)
563 {
564 fprintf (file, "[$%s+].",
565 reg_names[REGNO (XEXP (inner_inner, 0))]);
566 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
567 }
568 else
569 {
570 fprintf (file, "[$%s].", reg_names[REGNO (inner_inner)]);
571
572 putc (GET_MODE (inner) == HImode ? 'w' : 'b', file);
573 }
574 }
575 else if (GET_CODE (index) == MEM)
576 {
577 if (GET_CODE (inner) == POST_INC)
578 fprintf (file, "[$%s+].d", reg_names[REGNO (XEXP (inner, 0))]);
579 else
580 fprintf (file, "[$%s].d", reg_names[REGNO (inner)]);
581 }
582 else
583 cris_operand_lossage ("unexpected index-type in cris_print_index",
584 index);
585 }
586
587 /* Print a base rtx of an address to file. */
588
589 static void
590 cris_print_base (rtx base, FILE *file)
591 {
592 if (REG_P (base))
593 fprintf (file, "$%s", reg_names[REGNO (base)]);
594 else if (GET_CODE (base) == POST_INC)
595 fprintf (file, "$%s+", reg_names[REGNO (XEXP (base, 0))]);
596 else
597 cris_operand_lossage ("unexpected base-type in cris_print_base",
598 base);
599 }
600
601 /* Usable as a guard in expressions. */
602
603 int
604 cris_fatal (char *arg)
605 {
606 internal_error (arg);
607
608 /* We'll never get here; this is just to appease compilers. */
609 return 0;
610 }
611
612 /* Textual function prologue. */
613
614 static void
615 cris_target_asm_function_prologue (FILE *file, HOST_WIDE_INT size)
616 {
617 int regno;
618
619 /* Shorten the used name for readability. */
620 int cfoa_size = current_function_outgoing_args_size;
621 int last_movem_reg = -1;
622 int doing_dwarf = dwarf2out_do_frame ();
623 int framesize;
624 int faked_args_size = 0;
625 int cfa_write_offset = 0;
626 char *cfa_label = NULL;
627 int return_address_on_stack
628 = regs_ever_live[CRIS_SRP_REGNUM]
629 || cfun->machine->needs_return_address_on_stack != 0;
630
631 /* Don't do anything if no prologues or epilogues are wanted. */
632 if (!TARGET_PROLOGUE_EPILOGUE)
633 return;
634
635 if (size < 0)
636 abort ();
637
638 /* Align the size to what's best for the CPU model. */
639 if (TARGET_STACK_ALIGN)
640 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
641
642 if (current_function_pretend_args_size)
643 {
644 int pretend = current_function_pretend_args_size;
645 for (regno = CRIS_FIRST_ARG_REG + CRIS_MAX_ARGS_IN_REGS - 1;
646 pretend > 0;
647 regno--, pretend -= 4)
648 {
649 fprintf (file, "\tpush $%s\n", reg_names[regno]);
650 faked_args_size += 4;
651 }
652 }
653
654 framesize = faked_args_size;
655
656 if (doing_dwarf)
657 {
658 /* FIXME: Slightly redundant calculation, as we do the same in
659 pieces below. This offset must be the total adjustment of the
660 stack-pointer. We can then def_cfa call at the end of this
661 function with the current implementation of execute_cfa_insn, but
662 that wouldn't really be clean. */
663
664 int cfa_offset
665 = faked_args_size
666 + (return_address_on_stack ? 4 : 0)
667 + (frame_pointer_needed ? 4 : 0);
668
669 int cfa_reg;
670
671 if (frame_pointer_needed)
672 cfa_reg = FRAME_POINTER_REGNUM;
673 else
674 {
675 cfa_reg = STACK_POINTER_REGNUM;
676 cfa_offset += cris_initial_frame_pointer_offset ();
677 }
678
679 cfa_label = dwarf2out_cfi_label ();
680 dwarf2out_def_cfa (cfa_label, cfa_reg, cfa_offset);
681
682 cfa_write_offset = - faked_args_size - 4;
683 }
684
685 /* Save SRP if not a leaf function. */
686 if (return_address_on_stack)
687 {
688 fprintf (file, "\tPush $srp\n");
689 framesize += 4;
690
691 if (doing_dwarf)
692 {
693 dwarf2out_return_save (cfa_label, cfa_write_offset);
694 cfa_write_offset -= 4;
695 }
696 }
697
698 /* Set up frame pointer if needed. */
699 if (frame_pointer_needed)
700 {
701 fprintf (file, "\tpush $%s\n\tmove.d $sp,$%s\n",
702 reg_names[FRAME_POINTER_REGNUM],
703 reg_names[FRAME_POINTER_REGNUM]);
704 framesize += 4;
705
706 if (doing_dwarf)
707 {
708 dwarf2out_reg_save (cfa_label, FRAME_POINTER_REGNUM,
709 cfa_write_offset);
710 cfa_write_offset -= 4;
711 }
712 }
713
714 /* Local vars are located above saved regs. */
715 cfa_write_offset -= size;
716
717 /* Get a contiguous sequence of registers, starting with r0, that need
718 to be saved. */
719 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
720 {
721 if ((((regs_ever_live[regno]
722 && !call_used_regs[regno])
723 || (regno == (int) PIC_OFFSET_TABLE_REGNUM
724 && (current_function_uses_pic_offset_table
725 /* It is saved anyway, if there would be a gap. */
726 || (flag_pic
727 && regs_ever_live[regno + 1]
728 && !call_used_regs[regno + 1]))))
729 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
730 && regno != CRIS_SRP_REGNUM)
731 || (current_function_calls_eh_return
732 && (regno == EH_RETURN_DATA_REGNO (0)
733 || regno == EH_RETURN_DATA_REGNO (1)
734 || regno == EH_RETURN_DATA_REGNO (2)
735 || regno == EH_RETURN_DATA_REGNO (3))))
736 {
737 /* Check if movem may be used for registers so far. */
738 if (regno == last_movem_reg + 1)
739 /* Yes, update next expected register. */
740 last_movem_reg++;
741 else
742 {
743 /* We cannot use movem for all registers. We have to flush
744 any movem:ed registers we got so far. */
745 if (last_movem_reg != -1)
746 {
747 /* It is a win to use a side-effect assignment for
748 64 <= size <= 128. But side-effect on movem was
749 not usable for CRIS v0..3. Also only do it if
750 side-effects insns are allowed. */
751 if ((last_movem_reg + 1) * 4 + size >= 64
752 && (last_movem_reg + 1) * 4 + size <= 128
753 && cris_cpu_version >= CRIS_CPU_SVINTO
754 && TARGET_SIDE_EFFECT_PREFIXES)
755 fprintf (file, "\tmovem $%s,[$sp=$sp-"HOST_WIDE_INT_PRINT_DEC"]\n",
756 reg_names[last_movem_reg],
757 (last_movem_reg + 1) * 4 + size);
758 else
759 {
760 /* Avoid printing multiple subsequent sub:s for sp. */
761 fprintf (file, "\tsub%s "HOST_WIDE_INT_PRINT_DEC",$sp\n",
762 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1)
763 * 4 + size),
764 (last_movem_reg + 1) * 4 + size);
765
766 fprintf (file, "\tmovem $%s,[$sp]\n",
767 reg_names[last_movem_reg]);
768 }
769
770 framesize += (last_movem_reg + 1) * 4 + size;
771
772 if (TARGET_PDEBUG)
773 fprintf (file, "; frame "HOST_WIDE_INT_PRINT_DEC
774 ", #regs %d, bytes %d args %d\n",
775 size,
776 last_movem_reg + 1,
777 (last_movem_reg + 1) * 4,
778 current_function_args_size);
779
780 last_movem_reg = -1;
781 size = 0;
782 }
783 else if (size > 0)
784 {
785 /* Local vars on stack, but there are no movem:s.
786 Just allocate space. */
787 fprintf (file, "\tSub%s "HOST_WIDE_INT_PRINT_DEC",$sp\n",
788 ADDITIVE_SIZE_MODIFIER (size),
789 size);
790 framesize += size;
791 size = 0;
792 }
793
794 fprintf (file, "\tPush $%s\n", reg_names[regno]);
795 framesize += 4;
796 }
797
798 if (doing_dwarf)
799 {
800 /* Registers are stored lowest numbered at highest address,
801 which matches the loop order; we just need to update the
802 write-offset. */
803 dwarf2out_reg_save (cfa_label, regno, cfa_write_offset);
804 cfa_write_offset -= 4;
805 }
806 }
807 }
808
809 /* Check after, if we can movem all registers. This is the normal
810 case. */
811 if (last_movem_reg != -1)
812 {
813 /* Side-effect assignment on movem was not supported for CRIS v0..3,
814 and don't do it if we're asked not to.
815
816 The movem is already accounted for, for unwind. */
817
818 if ((last_movem_reg + 1) * 4 + size >= 64
819 && (last_movem_reg + 1) * 4 + size <= 128
820 && cris_cpu_version >= CRIS_CPU_SVINTO
821 && TARGET_SIDE_EFFECT_PREFIXES)
822 fprintf (file, "\tmovem $%s,[$sp=$sp-"HOST_WIDE_INT_PRINT_DEC"]\n",
823 reg_names[last_movem_reg],
824 (last_movem_reg+1) * 4 + size);
825 else
826 {
827 /* Avoid printing multiple subsequent sub:s for sp. FIXME:
828 Clean up the conditional expression. */
829 fprintf (file, "\tsub%s "HOST_WIDE_INT_PRINT_DEC",$sp\n",
830 ADDITIVE_SIZE_MODIFIER ((last_movem_reg + 1) * 4 + size),
831 (last_movem_reg + 1) * 4 + size);
832 /* To be compatible with v0..v3 means we do not use an assignment
833 addressing mode with movem. We normally don't need that
834 anyway. It would only be slightly more efficient for 64..128
835 bytes frame size. */
836 fprintf (file, "\tmovem $%s,[$sp]\n", reg_names[last_movem_reg]);
837 }
838
839 framesize += (last_movem_reg + 1) * 4 + size;
840
841 if (TARGET_PDEBUG)
842 fprintf (file, "; frame "HOST_WIDE_INT_PRINT_DEC
843 ", #regs %d, bytes %d args %d\n",
844 size,
845 last_movem_reg + 1,
846 (last_movem_reg + 1) * 4,
847 current_function_args_size);
848
849 /* We have to put outgoing argument space after regs. */
850 if (cfoa_size)
851 {
852 /* This does not need to be accounted for, for unwind. */
853
854 fprintf (file, "\tSub%s %d,$sp\n",
855 ADDITIVE_SIZE_MODIFIER (cfoa_size),
856 cfoa_size);
857 framesize += cfoa_size;
858 }
859 }
860 else if ((size + cfoa_size) > 0)
861 {
862 /* This does not need to be accounted for, for unwind. */
863
864 /* Local vars on stack, and we could not use movem. Add a sub here. */
865 fprintf (file, "\tSub%s "HOST_WIDE_INT_PRINT_DEC",$sp\n",
866 ADDITIVE_SIZE_MODIFIER (size + cfoa_size),
867 cfoa_size + size);
868 framesize += size + cfoa_size;
869 }
870
871 /* Set up the PIC register. */
872 if (current_function_uses_pic_offset_table)
873 fprintf (file, "\tmove.d $pc,$%s\n\tsub.d .:GOTOFF,$%s\n",
874 reg_names[PIC_OFFSET_TABLE_REGNUM],
875 reg_names[PIC_OFFSET_TABLE_REGNUM]);
876
877 if (TARGET_PDEBUG)
878 fprintf (file,
879 "; parm #%d @ %d; frame " HOST_WIDE_INT_PRINT_DEC
880 ", FP-SP is %d; leaf: %s%s; fp %s, outg: %d arg %d\n",
881 CRIS_MAX_ARGS_IN_REGS + 1, FIRST_PARM_OFFSET (0),
882 get_frame_size (),
883 cris_initial_frame_pointer_offset (),
884 leaf_function_p () ? "yes" : "no",
885 return_address_on_stack ? "no" :"yes",
886 frame_pointer_needed ? "yes" : "no",
887 cfoa_size, current_function_args_size);
888
889 if (cris_max_stackframe && framesize > cris_max_stackframe)
890 warning ("stackframe too big: %d bytes", framesize);
891 }
892
893 /* Return nonzero if there are regs mentioned in the insn that are not all
894 in the call_used regs. This is part of the decision whether an insn
895 can be put in the epilogue. */
896
897 static int
898 saved_regs_mentioned (rtx x)
899 {
900 int i;
901 const char *fmt;
902 RTX_CODE code;
903
904 /* Mainly stolen from refers_to_regno_p in rtlanal.c. */
905
906 code = GET_CODE (x);
907
908 switch (code)
909 {
910 case REG:
911 i = REGNO (x);
912 return !call_used_regs[i];
913
914 case SUBREG:
915 /* If this is a SUBREG of a hard reg, we can see exactly which
916 registers are being modified. Otherwise, handle normally. */
917 i = REGNO (SUBREG_REG (x));
918 return !call_used_regs[i];
919
920 default:
921 ;
922 }
923
924 fmt = GET_RTX_FORMAT (code);
925 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
926 {
927 if (fmt[i] == 'e')
928 {
929 if (saved_regs_mentioned (XEXP (x, i)))
930 return 1;
931 }
932 else if (fmt[i] == 'E')
933 {
934 int j;
935 for (j = XVECLEN (x, i) - 1; j >=0; j--)
936 if (saved_regs_mentioned (XEXP (x, i)))
937 return 1;
938 }
939 }
940
941 return 0;
942 }
943
944 /* Figure out if the insn may be put in the epilogue. */
945
946 int
947 cris_eligible_for_epilogue_delay (rtx insn)
948 {
949 /* First of all, it must be as slottable as for a delayed branch insn. */
950 if (get_attr_slottable (insn) != SLOTTABLE_YES)
951 return 0;
952
953 /* It must not refer to the stack pointer (may be valid for some cases
954 that I can't think of). */
955 if (reg_mentioned_p (stack_pointer_rtx, PATTERN (insn)))
956 return 0;
957
958 /* The frame pointer will be restored in the epilogue, before the
959 "ret", so it can't be referred to. */
960 if (frame_pointer_needed
961 && reg_mentioned_p (frame_pointer_rtx, PATTERN (insn)))
962 return 0;
963
964 /* All saved regs are restored before the delayed insn.
965 This means that we cannot have any instructions that mention the
966 registers that are restored by the epilogue. */
967 if (saved_regs_mentioned (PATTERN (insn)))
968 return 0;
969
970 /* It seems to be ok. */
971 return 1;
972 }
973
974 /* Return the number of delay-slots in the epilogue: return 1 if it
975 contains "ret", else 0. */
976
977 int
978 cris_delay_slots_for_epilogue (void)
979 {
980 /* Check if we use a return insn, which we only do for leaf functions.
981 Else there is no slot to fill. */
982 if (regs_ever_live[CRIS_SRP_REGNUM]
983 || cfun->machine->needs_return_address_on_stack != 0)
984 return 0;
985
986 /* By calling function_epilogue with the same parameters as from gcc
987 we can get info about if the epilogue can fill the delay-slot by itself.
988 If it is filled from the epilogue, then the corresponding string
989 is in save_last.
990 This depends on that the "size" argument to function_epilogue
991 always is get_frame_size.
992 FIXME: Kludgy. At least make it a separate function that is not
993 misnamed or abuses the stream parameter. */
994 cris_target_asm_function_epilogue (NULL, get_frame_size ());
995
996 if (*save_last)
997 return 1;
998 return 0;
999 }
1000
1001 /* Textual function epilogue. When file is NULL, it serves doubly as
1002 a test for whether the epilogue can fill any "ret" delay-slots by
1003 itself by storing the delay insn in save_last. */
1004
1005 static void
1006 cris_target_asm_function_epilogue (FILE *file, HOST_WIDE_INT size)
1007 {
1008 int regno;
1009 int last_movem_reg = -1;
1010 rtx insn = get_last_insn ();
1011 int argspace_offset = current_function_outgoing_args_size;
1012 int pretend = current_function_pretend_args_size;
1013 int return_address_on_stack
1014 = regs_ever_live[CRIS_SRP_REGNUM]
1015 || cfun->machine->needs_return_address_on_stack != 0;
1016
1017 save_last[0] = 0;
1018
1019 if (file && !TARGET_PROLOGUE_EPILOGUE)
1020 return;
1021
1022 if (TARGET_PDEBUG && file)
1023 fprintf (file, ";;\n");
1024
1025 /* Align byte count of stack frame. */
1026 if (TARGET_STACK_ALIGN)
1027 size = TARGET_ALIGN_BY_32 ? (size + 3) & ~3 : (size + 1) & ~1;
1028
1029 /* If the last insn was a BARRIER, we don't have to write any code,
1030 then all returns were covered by "return" insns. */
1031 if (GET_CODE (insn) == NOTE)
1032 insn = prev_nonnote_insn (insn);
1033 if (insn
1034 && (GET_CODE (insn) == BARRIER
1035 /* We must make sure that the insn really is a "return" and
1036 not a conditional branch. Try to match the return exactly,
1037 and if it doesn't match, assume it is a conditional branch
1038 (and output an epilogue). */
1039 || (GET_CODE (insn) == JUMP_INSN
1040 && GET_CODE (PATTERN (insn)) == RETURN)))
1041 {
1042 if (TARGET_PDEBUG && file)
1043 fprintf (file, ";;;;;\n");
1044 return;
1045 }
1046
1047 /* Check how many saved regs we can movem. They start at r0 and must
1048 be contiguous. */
1049 for (regno = 0;
1050 regno < FIRST_PSEUDO_REGISTER;
1051 regno++)
1052 if ((((regs_ever_live[regno]
1053 && !call_used_regs[regno])
1054 || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1055 && (current_function_uses_pic_offset_table
1056 /* It is saved anyway, if there would be a gap. */
1057 || (flag_pic
1058 && regs_ever_live[regno + 1]
1059 && !call_used_regs[regno + 1]))))
1060 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1061 && regno != CRIS_SRP_REGNUM)
1062 || (current_function_calls_eh_return
1063 && (regno == EH_RETURN_DATA_REGNO (0)
1064 || regno == EH_RETURN_DATA_REGNO (1)
1065 || regno == EH_RETURN_DATA_REGNO (2)
1066 || regno == EH_RETURN_DATA_REGNO (3))))
1067
1068 {
1069 if (regno == last_movem_reg + 1)
1070 last_movem_reg++;
1071 else
1072 break;
1073 }
1074
1075 for (regno = FIRST_PSEUDO_REGISTER - 1;
1076 regno > last_movem_reg;
1077 regno--)
1078 if ((((regs_ever_live[regno]
1079 && !call_used_regs[regno])
1080 || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1081 && (current_function_uses_pic_offset_table
1082 /* It is saved anyway, if there would be a gap. */
1083 || (flag_pic
1084 && regs_ever_live[regno + 1]
1085 && !call_used_regs[regno + 1]))))
1086 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1087 && regno != CRIS_SRP_REGNUM)
1088 || (current_function_calls_eh_return
1089 && (regno == EH_RETURN_DATA_REGNO (0)
1090 || regno == EH_RETURN_DATA_REGNO (1)
1091 || regno == EH_RETURN_DATA_REGNO (2)
1092 || regno == EH_RETURN_DATA_REGNO (3))))
1093 {
1094 if (argspace_offset)
1095 {
1096 /* There is an area for outgoing parameters located before
1097 the saved registers. We have to adjust for that. */
1098 if (file)
1099 fprintf (file, "\tAdd%s %d,$sp\n",
1100 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1101 argspace_offset);
1102
1103 /* Make sure we only do this once. */
1104 argspace_offset = 0;
1105 }
1106
1107 /* Flush previous non-movem:ed registers. */
1108 if (*save_last && file)
1109 fprintf (file, save_last);
1110 sprintf (save_last, "\tPop $%s\n", reg_names[regno]);
1111 }
1112
1113 if (last_movem_reg != -1)
1114 {
1115 if (argspace_offset)
1116 {
1117 /* Adjust for the outgoing parameters area, if that's not
1118 handled yet. */
1119 if (*save_last && file)
1120 {
1121 fprintf (file, save_last);
1122 *save_last = 0;
1123 }
1124
1125 if (file)
1126 fprintf (file, "\tAdd%s %d,$sp\n",
1127 ADDITIVE_SIZE_MODIFIER (argspace_offset),
1128 argspace_offset);
1129 argspace_offset = 0;
1130 }
1131 /* Flush previous non-movem:ed registers. */
1132 else if (*save_last && file)
1133 fprintf (file, save_last);
1134 sprintf (save_last, "\tmovem [$sp+],$%s\n", reg_names[last_movem_reg]);
1135 }
1136
1137 /* Restore frame pointer if necessary. */
1138 if (frame_pointer_needed)
1139 {
1140 if (*save_last && file)
1141 fprintf (file, save_last);
1142
1143 if (file)
1144 fprintf (file, "\tmove.d $%s,$sp\n",
1145 reg_names[FRAME_POINTER_REGNUM]);
1146 sprintf (save_last, "\tPop $%s\n",
1147 reg_names[FRAME_POINTER_REGNUM]);
1148 }
1149 else
1150 {
1151 /* If there was no frame-pointer to restore sp from, we must
1152 explicitly deallocate local variables. */
1153
1154 /* Handle space for outgoing parameters that hasn't been handled
1155 yet. */
1156 size += argspace_offset;
1157
1158 if (size)
1159 {
1160 if (*save_last && file)
1161 fprintf (file, save_last);
1162
1163 sprintf (save_last, "\tadd%s "HOST_WIDE_INT_PRINT_DEC",$sp\n",
1164 ADDITIVE_SIZE_MODIFIER (size), size);
1165 }
1166
1167 /* If the size was not in the range for a "quick", we must flush
1168 it here. */
1169 if (size > 63)
1170 {
1171 if (file)
1172 fprintf (file, save_last);
1173 *save_last = 0;
1174 }
1175 }
1176
1177 /* If this function has no pushed register parameters
1178 (stdargs/varargs), and if it is not a leaf function, then we can
1179 just jump-return here. */
1180 if (return_address_on_stack && pretend == 0)
1181 {
1182 if (*save_last && file)
1183 fprintf (file, save_last);
1184 *save_last = 0;
1185
1186 if (file)
1187 {
1188 if (current_function_calls_eh_return)
1189 {
1190 /* The installed EH-return address is in *this* frame, so we
1191 need to pop it before we return. */
1192 fprintf (file, "\tpop $srp\n");
1193 fprintf (file, "\tret\n");
1194 fprintf (file, "\tadd.d $%s,$sp\n", reg_names[CRIS_STACKADJ_REG]);
1195 }
1196 else
1197 fprintf (file, "\tJump [$sp+]\n");
1198
1199 /* Do a sanity check to avoid generating invalid code. */
1200 if (current_function_epilogue_delay_list)
1201 internal_error ("allocated but unused delay list in epilogue");
1202 }
1203 return;
1204 }
1205
1206 /* Rather than add current_function_calls_eh_return conditions
1207 everywhere in the following code (and not be able to test it
1208 thoroughly), assert the assumption that all usage of
1209 __builtin_eh_return are handled above. */
1210 if (current_function_calls_eh_return)
1211 internal_error ("unexpected function type needing stack adjustment for\
1212 __builtin_eh_return");
1213
1214 /* If we pushed some register parameters, then adjust the stack for
1215 them. */
1216 if (pretend)
1217 {
1218 /* Since srp is stored on the way, we need to restore it first. */
1219 if (return_address_on_stack)
1220 {
1221 if (*save_last && file)
1222 fprintf (file, save_last);
1223 *save_last = 0;
1224
1225 if (file)
1226 fprintf (file, "\tpop $srp\n");
1227 }
1228
1229 if (*save_last && file)
1230 fprintf (file, save_last);
1231
1232 sprintf (save_last, "\tadd%s %d,$sp\n",
1233 ADDITIVE_SIZE_MODIFIER (pretend), pretend);
1234 }
1235
1236 /* Here's where we have a delay-slot we need to fill. */
1237 if (file && current_function_epilogue_delay_list)
1238 {
1239 /* If gcc has allocated an insn for the epilogue delay slot, but
1240 things were arranged so we now thought we could do it
1241 ourselves, don't forget to flush that insn. */
1242 if (*save_last)
1243 fprintf (file, save_last);
1244
1245 fprintf (file, "\tRet\n");
1246
1247 /* Output the delay-slot-insn the mandated way. */
1248 final_scan_insn (XEXP (current_function_epilogue_delay_list, 0),
1249 file, 1, -2, 1);
1250 }
1251 else if (file)
1252 {
1253 fprintf (file, "\tRet\n");
1254
1255 /* If the GCC did not do it, we have to use whatever insn we have,
1256 or a nop. */
1257 if (*save_last)
1258 fprintf (file, save_last);
1259 else
1260 fprintf (file, "\tnOp\n");
1261 }
1262 }
1263
1264 /* The PRINT_OPERAND worker. */
1265
1266 void
1267 cris_print_operand (FILE *file, rtx x, int code)
1268 {
1269 rtx operand = x;
1270
1271 /* Size-strings corresponding to MULT expressions. */
1272 static const char *const mults[] = { "BAD:0", ".b", ".w", "BAD:3", ".d" };
1273
1274 /* New code entries should just be added to the switch below. If
1275 handling is finished, just return. If handling was just a
1276 modification of the operand, the modified operand should be put in
1277 "operand", and then do a break to let default handling
1278 (zero-modifier) output the operand. */
1279
1280 switch (code)
1281 {
1282 case 'b':
1283 /* Print the unsigned supplied integer as if it was signed
1284 and < 0, i.e print 255 or 65535 as -1, 254, 65534 as -2, etc. */
1285 if (GET_CODE (x) != CONST_INT
1286 || ! CONST_OK_FOR_LETTER_P (INTVAL (x), 'O'))
1287 LOSE_AND_RETURN ("invalid operand for 'b' modifier", x);
1288 fprintf (file, HOST_WIDE_INT_PRINT_DEC,
1289 INTVAL (x)| (INTVAL (x) <= 255 ? ~255 : ~65535));
1290 return;
1291
1292 case 'x':
1293 /* Print assembler code for operator. */
1294 fprintf (file, "%s", cris_op_str (operand));
1295 return;
1296
1297 case 'v':
1298 /* Print the operand without the PIC register. */
1299 if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1300 LOSE_AND_RETURN ("invalid operand for 'v' modifier", x);
1301 cris_pic_sympart_only++;
1302 cris_output_addr_const (file, x);
1303 cris_pic_sympart_only--;
1304 return;
1305
1306 case 'P':
1307 /* Print the PIC register. Applied to a GOT-less PIC symbol for
1308 sanity. */
1309 if (! flag_pic || ! CONSTANT_P (x) || ! cris_gotless_symbol (x))
1310 LOSE_AND_RETURN ("invalid operand for 'P' modifier", x);
1311 fprintf (file, "$%s", reg_names [PIC_OFFSET_TABLE_REGNUM]);
1312 return;
1313
1314 case 'p':
1315 /* Adjust a power of two to its log2. */
1316 if (GET_CODE (x) != CONST_INT || exact_log2 (INTVAL (x)) < 0 )
1317 LOSE_AND_RETURN ("invalid operand for 'p' modifier", x);
1318 fprintf (file, "%d", exact_log2 (INTVAL (x)));
1319 return;
1320
1321 case 's':
1322 /* For an integer, print 'b' or 'w' if <= 255 or <= 65535
1323 respectively. This modifier also terminates the inhibiting
1324 effects of the 'x' modifier. */
1325 cris_output_insn_is_bound = 0;
1326 if (GET_MODE (x) == VOIDmode && GET_CODE (x) == CONST_INT)
1327 {
1328 if (INTVAL (x) >= 0)
1329 {
1330 if (INTVAL (x) <= 255)
1331 putc ('b', file);
1332 else if (INTVAL (x) <= 65535)
1333 putc ('w', file);
1334 else
1335 putc ('d', file);
1336 }
1337 else
1338 putc ('d', file);
1339 return;
1340 }
1341
1342 /* For a non-integer, print the size of the operand. */
1343 putc ((GET_MODE (x) == SImode || GET_MODE (x) == SFmode)
1344 ? 'd' : GET_MODE (x) == HImode ? 'w'
1345 : GET_MODE (x) == QImode ? 'b'
1346 /* If none of the above, emit an erroneous size letter. */
1347 : 'X',
1348 file);
1349 return;
1350
1351 case 'z':
1352 /* Const_int: print b for -127 <= x <= 255,
1353 w for -32768 <= x <= 65535, else abort. */
1354 if (GET_CODE (x) != CONST_INT
1355 || INTVAL (x) < -32768 || INTVAL (x) > 65535)
1356 LOSE_AND_RETURN ("invalid operand for 'z' modifier", x);
1357 putc (INTVAL (x) >= -128 && INTVAL (x) <= 255 ? 'b' : 'w', file);
1358 return;
1359
1360 case '#':
1361 /* Output a 'nop' if there's nothing for the delay slot.
1362 This method stolen from the sparc files. */
1363 if (dbr_sequence_length () == 0)
1364 fputs ("\n\tnop", file);
1365 return;
1366
1367 case 'H':
1368 /* Print high (most significant) part of something. */
1369 switch (GET_CODE (operand))
1370 {
1371 case CONST_INT:
1372 if (HOST_BITS_PER_WIDE_INT == 32)
1373 /* Sign-extension from a normal int to a long long. */
1374 fprintf (file, INTVAL (operand) < 0 ? "-1" : "0");
1375 else
1376 fprintf (file, "0x%x", (unsigned int)(INTVAL (x) >> 31 >> 1));
1377 return;
1378
1379 case CONST_DOUBLE:
1380 /* High part of a long long constant. */
1381 if (GET_MODE (operand) == VOIDmode)
1382 {
1383 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_HIGH (x));
1384 return;
1385 }
1386 else
1387 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1388
1389 case REG:
1390 /* Print reg + 1. Check that there's not an attempt to print
1391 high-parts of registers like stack-pointer or higher. */
1392 if (REGNO (operand) > STACK_POINTER_REGNUM - 2)
1393 LOSE_AND_RETURN ("bad register", operand);
1394 fprintf (file, "$%s", reg_names[REGNO (operand) + 1]);
1395 return;
1396
1397 case MEM:
1398 /* Adjust memory address to high part. */
1399 {
1400 rtx adj_mem = operand;
1401 int size
1402 = GET_MODE_BITSIZE (GET_MODE (operand)) / BITS_PER_UNIT;
1403
1404 /* Adjust so we can use two SImode in DImode.
1405 Calling adj_offsettable_operand will make sure it is an
1406 offsettable address. Don't do this for a postincrement
1407 though; it should remain as it was. */
1408 if (GET_CODE (XEXP (adj_mem, 0)) != POST_INC)
1409 adj_mem
1410 = adjust_address (adj_mem, GET_MODE (adj_mem), size / 2);
1411
1412 output_address (XEXP (adj_mem, 0));
1413 return;
1414 }
1415
1416 default:
1417 LOSE_AND_RETURN ("invalid operand for 'H' modifier", x);
1418 }
1419
1420 case 'L':
1421 /* Strip the MEM expression. */
1422 operand = XEXP (operand, 0);
1423 break;
1424
1425 case 'e':
1426 /* Print 's' if operand is SIGN_EXTEND or 'u' if ZERO_EXTEND unless
1427 cris_output_insn_is_bound is nonzero. */
1428 if (GET_CODE (operand) != SIGN_EXTEND
1429 && GET_CODE (operand) != ZERO_EXTEND
1430 && GET_CODE (operand) != CONST_INT)
1431 LOSE_AND_RETURN ("invalid operand for 'e' modifier", x);
1432
1433 if (cris_output_insn_is_bound)
1434 {
1435 cris_output_insn_is_bound = 0;
1436 return;
1437 }
1438
1439 putc (GET_CODE (operand) == SIGN_EXTEND
1440 || (GET_CODE (operand) == CONST_INT && INTVAL (operand) < 0)
1441 ? 's' : 'u', file);
1442 return;
1443
1444 case 'm':
1445 /* Print the size letter of the inner element. We can do it by
1446 calling ourselves with the 's' modifier. */
1447 if (GET_CODE (operand) != SIGN_EXTEND && GET_CODE (operand) != ZERO_EXTEND)
1448 LOSE_AND_RETURN ("invalid operand for 'm' modifier", x);
1449 cris_print_operand (file, XEXP (operand, 0), 's');
1450 return;
1451
1452 case 'M':
1453 /* Print the least significant part of operand. */
1454 if (GET_CODE (operand) == CONST_DOUBLE)
1455 {
1456 fprintf (file, HOST_WIDE_INT_PRINT_HEX, CONST_DOUBLE_LOW (x));
1457 return;
1458 }
1459 else if (HOST_BITS_PER_WIDE_INT > 32 && GET_CODE (operand) == CONST_INT)
1460 {
1461 fprintf (file, HOST_WIDE_INT_PRINT_HEX,
1462 INTVAL (x) & ((unsigned int) 0x7fffffff * 2 + 1));
1463 return;
1464 }
1465 /* Otherwise the least significant part equals the normal part,
1466 so handle it normally. */
1467 break;
1468
1469 case 'A':
1470 /* When emitting an add for the high part of a DImode constant, we
1471 want to use addq for 0 and adds.w for -1. */
1472 if (GET_CODE (operand) != CONST_INT)
1473 LOSE_AND_RETURN ("invalid operand for 'A' modifier", x);
1474 fprintf (file, INTVAL (operand) < 0 ? "adds.w" : "addq");
1475 return;
1476
1477 case 'D':
1478 /* When emitting an sub for the high part of a DImode constant, we
1479 want to use subq for 0 and subs.w for -1. */
1480 if (GET_CODE (operand) != CONST_INT)
1481 LOSE_AND_RETURN ("invalid operand for 'D' modifier", x);
1482 fprintf (file, INTVAL (operand) < 0 ? "subs.w" : "subq");
1483 return;
1484
1485 case 'S':
1486 /* Print the operand as the index-part of an address.
1487 Easiest way out is to use cris_print_index. */
1488 cris_print_index (operand, file);
1489 return;
1490
1491 case 'T':
1492 /* Print the size letter for an operand to a MULT, which must be a
1493 const_int with a suitable value. */
1494 if (GET_CODE (operand) != CONST_INT || INTVAL (operand) > 4)
1495 LOSE_AND_RETURN ("invalid operand for 'T' modifier", x);
1496 fprintf (file, "%s", mults[INTVAL (operand)]);
1497 return;
1498
1499 case 0:
1500 /* No code, print as usual. */
1501 break;
1502
1503 default:
1504 LOSE_AND_RETURN ("invalid operand modifier letter", x);
1505 }
1506
1507 /* Print an operand as without a modifier letter. */
1508 switch (GET_CODE (operand))
1509 {
1510 case REG:
1511 if (REGNO (operand) > 15)
1512 internal_error ("internal error: bad register: %d", REGNO (operand));
1513 fprintf (file, "$%s", reg_names[REGNO (operand)]);
1514 return;
1515
1516 case MEM:
1517 output_address (XEXP (operand, 0));
1518 return;
1519
1520 case CONST_DOUBLE:
1521 if (GET_MODE (operand) == VOIDmode)
1522 /* A long long constant. */
1523 output_addr_const (file, operand);
1524 else
1525 {
1526 /* Only single precision is allowed as plain operands the
1527 moment. FIXME: REAL_VALUE_FROM_CONST_DOUBLE isn't
1528 documented. */
1529 REAL_VALUE_TYPE r;
1530 long l;
1531
1532 /* FIXME: Perhaps check overflow of the "single". */
1533 REAL_VALUE_FROM_CONST_DOUBLE (r, operand);
1534 REAL_VALUE_TO_TARGET_SINGLE (r, l);
1535
1536 fprintf (file, "0x%lx", l);
1537 }
1538 return;
1539
1540 case UNSPEC:
1541 ASSERT_PLT_UNSPEC (operand);
1542 /* Fall through. */
1543
1544 case CONST:
1545 cris_output_addr_const (file, operand);
1546 return;
1547
1548 case MULT:
1549 case ASHIFT:
1550 {
1551 /* For a (MULT (reg X) const_int) we output "rX.S". */
1552 int i = GET_CODE (XEXP (operand, 1)) == CONST_INT
1553 ? INTVAL (XEXP (operand, 1)) : INTVAL (XEXP (operand, 0));
1554 rtx reg = GET_CODE (XEXP (operand, 1)) == CONST_INT
1555 ? XEXP (operand, 0) : XEXP (operand, 1);
1556
1557 if (GET_CODE (reg) != REG
1558 || (GET_CODE (XEXP (operand, 0)) != CONST_INT
1559 && GET_CODE (XEXP (operand, 1)) != CONST_INT))
1560 LOSE_AND_RETURN ("unexpected multiplicative operand", x);
1561
1562 cris_print_base (reg, file);
1563 fprintf (file, ".%c",
1564 i == 0 || (i == 1 && GET_CODE (operand) == MULT) ? 'b'
1565 : i == 4 ? 'd'
1566 : (i == 2 && GET_CODE (operand) == MULT) || i == 1 ? 'w'
1567 : 'd');
1568 return;
1569 }
1570
1571 default:
1572 /* No need to handle all strange variants, let output_addr_const
1573 do it for us. */
1574 if (CONSTANT_P (operand))
1575 {
1576 cris_output_addr_const (file, operand);
1577 return;
1578 }
1579
1580 LOSE_AND_RETURN ("unexpected operand", x);
1581 }
1582 }
1583
1584 /* The PRINT_OPERAND_ADDRESS worker. */
1585
1586 void
1587 cris_print_operand_address (FILE *file, rtx x)
1588 {
1589 /* All these were inside MEM:s so output indirection characters. */
1590 putc ('[', file);
1591
1592 if (CONSTANT_ADDRESS_P (x))
1593 cris_output_addr_const (file, x);
1594 else if (BASE_OR_AUTOINCR_P (x))
1595 cris_print_base (x, file);
1596 else if (GET_CODE (x) == PLUS)
1597 {
1598 rtx x1, x2;
1599
1600 x1 = XEXP (x, 0);
1601 x2 = XEXP (x, 1);
1602 if (BASE_P (x1))
1603 {
1604 cris_print_base (x1, file);
1605 cris_print_index (x2, file);
1606 }
1607 else if (BASE_P (x2))
1608 {
1609 cris_print_base (x2, file);
1610 cris_print_index (x1, file);
1611 }
1612 else
1613 LOSE_AND_RETURN ("unrecognized address", x);
1614 }
1615 else if (GET_CODE (x) == MEM)
1616 {
1617 /* A DIP. Output more indirection characters. */
1618 putc ('[', file);
1619 cris_print_base (XEXP (x, 0), file);
1620 putc (']', file);
1621 }
1622 else
1623 LOSE_AND_RETURN ("unrecognized address", x);
1624
1625 putc (']', file);
1626 }
1627
1628 /* The RETURN_ADDR_RTX worker.
1629 We mark that the return address is used, either by EH or
1630 __builtin_return_address, for use by the function prologue and
1631 epilogue. FIXME: This isn't optimal; we just use the mark in the
1632 prologue and epilogue to say that the return address is to be stored
1633 in the stack frame. We could return SRP for leaf-functions and use the
1634 initial-value machinery. */
1635
1636 rtx
1637 cris_return_addr_rtx (int count, rtx frameaddr ATTRIBUTE_UNUSED)
1638 {
1639 cfun->machine->needs_return_address_on_stack = 1;
1640
1641 /* The return-address is stored just above the saved frame-pointer (if
1642 present). Apparently we can't eliminate from the frame-pointer in
1643 that direction, so use the incoming args (maybe pretended) pointer. */
1644 return count == 0
1645 ? gen_rtx_MEM (Pmode, plus_constant (virtual_incoming_args_rtx, -4))
1646 : NULL_RTX;
1647 }
1648
1649 /* This used to be the INITIAL_FRAME_POINTER_OFFSET worker; now only
1650 handles FP -> SP elimination offset. */
1651
1652 static int
1653 cris_initial_frame_pointer_offset (void)
1654 {
1655 int regno;
1656
1657 /* Initial offset is 0 if we don't have a frame pointer. */
1658 int offs = 0;
1659
1660 /* And 4 for each register pushed. */
1661 for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
1662 if ((((regs_ever_live[regno]
1663 && !call_used_regs[regno])
1664 || (regno == (int) PIC_OFFSET_TABLE_REGNUM
1665 && (current_function_uses_pic_offset_table
1666 /* It is saved anyway, if there would be a gap. */
1667 || (flag_pic
1668 && regs_ever_live[regno + 1]
1669 && !call_used_regs[regno + 1]))))
1670 && (regno != FRAME_POINTER_REGNUM || !frame_pointer_needed)
1671 && regno != CRIS_SRP_REGNUM)
1672 || (current_function_calls_eh_return
1673 && (regno == EH_RETURN_DATA_REGNO (0)
1674 || regno == EH_RETURN_DATA_REGNO (1)
1675 || regno == EH_RETURN_DATA_REGNO (2)
1676 || regno == EH_RETURN_DATA_REGNO (3))))
1677 offs += 4;
1678
1679 /* And then, last, we add the locals allocated. */
1680 offs += get_frame_size ();
1681
1682 /* And more; the accumulated args size. */
1683 offs += current_function_outgoing_args_size;
1684
1685 /* Then round it off, in case we use aligned stack. */
1686 if (TARGET_STACK_ALIGN)
1687 offs = TARGET_ALIGN_BY_32 ? (offs + 3) & ~3 : (offs + 1) & ~1;
1688
1689 return offs;
1690 }
1691
1692 /* The INITIAL_ELIMINATION_OFFSET worker.
1693 Calculate the difference between imaginary registers such as frame
1694 pointer and the stack pointer. Used to eliminate the frame pointer
1695 and imaginary arg pointer. */
1696
1697 int
1698 cris_initial_elimination_offset (int fromreg, int toreg)
1699 {
1700 int fp_sp_offset
1701 = cris_initial_frame_pointer_offset ();
1702
1703 /* We should be able to use regs_ever_live and related prologue
1704 information here, or alpha should not as well. */
1705 int return_address_on_stack
1706 = regs_ever_live[CRIS_SRP_REGNUM]
1707 || cfun->machine->needs_return_address_on_stack != 0;
1708
1709 /* Here we act as if the frame-pointer is needed. */
1710 int ap_fp_offset = 4 + (return_address_on_stack ? 4 : 0);
1711
1712 if (fromreg == ARG_POINTER_REGNUM
1713 && toreg == FRAME_POINTER_REGNUM)
1714 return ap_fp_offset;
1715
1716 /* Between the frame pointer and the stack are only "normal" stack
1717 variables and saved registers. */
1718 if (fromreg == FRAME_POINTER_REGNUM
1719 && toreg == STACK_POINTER_REGNUM)
1720 return fp_sp_offset;
1721
1722 /* We need to balance out the frame pointer here. */
1723 if (fromreg == ARG_POINTER_REGNUM
1724 && toreg == STACK_POINTER_REGNUM)
1725 return ap_fp_offset + fp_sp_offset - 4;
1726
1727 abort ();
1728 }
1729
1730 /* This function looks into the pattern to see how this insn affects
1731 condition codes.
1732
1733 Used when to eliminate test insns before a condition-code user,
1734 such as a "scc" insn or a conditional branch. This includes
1735 checking if the entities that cc was updated by, are changed by the
1736 operation.
1737
1738 Currently a jumble of the old peek-inside-the-insn and the newer
1739 check-cc-attribute methods. */
1740
1741 void
1742 cris_notice_update_cc (rtx exp, rtx insn)
1743 {
1744 /* Check if user specified "-mcc-init" as a bug-workaround. FIXME:
1745 TARGET_CCINIT does not work; we must set CC_REVERSED as below.
1746 Several testcases will otherwise fail, for example
1747 gcc.c-torture/execute/20000217-1.c -O0 and -O1. */
1748 if (TARGET_CCINIT)
1749 {
1750 CC_STATUS_INIT;
1751 return;
1752 }
1753
1754 /* Slowly, we're converting to using attributes to control the setting
1755 of condition-code status. */
1756 switch (get_attr_cc (insn))
1757 {
1758 case CC_NONE:
1759 /* Even if it is "none", a setting may clobber a previous
1760 cc-value, so check. */
1761 if (GET_CODE (exp) == SET)
1762 {
1763 if (cc_status.value1
1764 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1765 cc_status.value1))
1766 cc_status.value1 = 0;
1767
1768 if (cc_status.value2
1769 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1770 cc_status.value2))
1771 cc_status.value2 = 0;
1772 }
1773 return;
1774
1775 case CC_CLOBBER:
1776 CC_STATUS_INIT;
1777 break;
1778
1779 case CC_NORMAL:
1780 /* Which means, for:
1781 (set (cc0) (...)):
1782 CC is (...).
1783
1784 (set (reg) (...)):
1785 CC is (reg) and (...) - unless (...) is 0, then CC does not change.
1786 CC_NO_OVERFLOW unless (...) is reg or mem.
1787
1788 (set (mem) (...)):
1789 CC does not change.
1790
1791 (set (pc) (...)):
1792 CC does not change.
1793
1794 (parallel
1795 (set (reg1) (mem (bdap/biap)))
1796 (set (reg2) (bdap/biap))):
1797 CC is (reg1) and (mem (reg2))
1798
1799 (parallel
1800 (set (mem (bdap/biap)) (reg1)) [or 0]
1801 (set (reg2) (bdap/biap))):
1802 CC does not change.
1803
1804 (where reg and mem includes strict_low_parts variants thereof)
1805
1806 For all others, assume CC is clobbered.
1807 Note that we do not have to care about setting CC_NO_OVERFLOW,
1808 since the overflow flag is set to 0 (i.e. right) for
1809 instructions where it does not have any sane sense, but where
1810 other flags have meanings. (This includes shifts; the carry is
1811 not set by them).
1812
1813 Note that there are other parallel constructs we could match,
1814 but we don't do that yet. */
1815
1816 if (GET_CODE (exp) == SET)
1817 {
1818 /* FIXME: Check when this happens. It looks like we should
1819 actually do a CC_STATUS_INIT here to be safe. */
1820 if (SET_DEST (exp) == pc_rtx)
1821 return;
1822
1823 /* Record CC0 changes, so we do not have to output multiple
1824 test insns. */
1825 if (SET_DEST (exp) == cc0_rtx)
1826 {
1827 cc_status.value1 = SET_SRC (exp);
1828 cc_status.value2 = 0;
1829
1830 /* Handle flags for the special btstq on one bit. */
1831 if (GET_CODE (SET_SRC (exp)) == ZERO_EXTRACT
1832 && XEXP (SET_SRC (exp), 1) == const1_rtx)
1833 {
1834 if (GET_CODE (XEXP (SET_SRC (exp), 0)) == CONST_INT)
1835 /* Using cmpq. */
1836 cc_status.flags = CC_INVERTED;
1837 else
1838 /* A one-bit btstq. */
1839 cc_status.flags = CC_Z_IN_NOT_N;
1840 }
1841 else
1842 cc_status.flags = 0;
1843
1844 if (GET_CODE (SET_SRC (exp)) == COMPARE)
1845 {
1846 if (!REG_P (XEXP (SET_SRC (exp), 0))
1847 && XEXP (SET_SRC (exp), 1) != const0_rtx)
1848 /* For some reason gcc will not canonicalize compare
1849 operations, reversing the sign by itself if
1850 operands are in wrong order. */
1851 /* (But NOT inverted; eq is still eq.) */
1852 cc_status.flags = CC_REVERSED;
1853
1854 /* This seems to be overlooked by gcc. FIXME: Check again.
1855 FIXME: Is it really safe? */
1856 cc_status.value2
1857 = gen_rtx_MINUS (GET_MODE (SET_SRC (exp)),
1858 XEXP (SET_SRC (exp), 0),
1859 XEXP (SET_SRC (exp), 1));
1860 }
1861 return;
1862 }
1863 else if (REG_P (SET_DEST (exp))
1864 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1865 && REG_P (XEXP (SET_DEST (exp), 0))))
1866 {
1867 /* A register is set; normally CC is set to show that no
1868 test insn is needed. Catch the exceptions. */
1869
1870 /* If not to cc0, then no "set"s in non-natural mode give
1871 ok cc0... */
1872 if (GET_MODE_SIZE (GET_MODE (SET_DEST (exp))) > UNITS_PER_WORD
1873 || GET_MODE_CLASS (GET_MODE (SET_DEST (exp))) == MODE_FLOAT)
1874 {
1875 /* ... except add:s and sub:s in DImode. */
1876 if (GET_MODE (SET_DEST (exp)) == DImode
1877 && (GET_CODE (SET_SRC (exp)) == PLUS
1878 || GET_CODE (SET_SRC (exp)) == MINUS))
1879 {
1880 cc_status.flags = 0;
1881 cc_status.value1 = SET_DEST (exp);
1882 cc_status.value2 = SET_SRC (exp);
1883
1884 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1885 cc_status.value2))
1886 cc_status.value2 = 0;
1887
1888 /* Add and sub may set V, which gets us
1889 unoptimizable results in "gt" and "le" condition
1890 codes. */
1891 cc_status.flags |= CC_NO_OVERFLOW;
1892
1893 return;
1894 }
1895 }
1896 else if (SET_SRC (exp) == const0_rtx)
1897 {
1898 /* There's no CC0 change when clearing a register or
1899 memory. Just check for overlap. */
1900 if ((cc_status.value1
1901 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1902 cc_status.value1)))
1903 cc_status.value1 = 0;
1904
1905 if ((cc_status.value2
1906 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1907 cc_status.value2)))
1908 cc_status.value2 = 0;
1909
1910 return;
1911 }
1912 else
1913 {
1914 cc_status.flags = 0;
1915 cc_status.value1 = SET_DEST (exp);
1916 cc_status.value2 = SET_SRC (exp);
1917
1918 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1919 cc_status.value2))
1920 cc_status.value2 = 0;
1921
1922 /* Some operations may set V, which gets us
1923 unoptimizable results in "gt" and "le" condition
1924 codes. */
1925 if (GET_CODE (SET_SRC (exp)) == PLUS
1926 || GET_CODE (SET_SRC (exp)) == MINUS
1927 || GET_CODE (SET_SRC (exp)) == NEG)
1928 cc_status.flags |= CC_NO_OVERFLOW;
1929
1930 return;
1931 }
1932 }
1933 else if (GET_CODE (SET_DEST (exp)) == MEM
1934 || (GET_CODE (SET_DEST (exp)) == STRICT_LOW_PART
1935 && GET_CODE (XEXP (SET_DEST (exp), 0)) == MEM))
1936 {
1937 /* When SET to MEM, then CC is not changed (except for
1938 overlap). */
1939 if ((cc_status.value1
1940 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1941 cc_status.value1)))
1942 cc_status.value1 = 0;
1943
1944 if ((cc_status.value2
1945 && cris_reg_overlap_mentioned_p (SET_DEST (exp),
1946 cc_status.value2)))
1947 cc_status.value2 = 0;
1948
1949 return;
1950 }
1951 }
1952 else if (GET_CODE (exp) == PARALLEL)
1953 {
1954 if (GET_CODE (XVECEXP (exp, 0, 0)) == SET
1955 && GET_CODE (XVECEXP (exp, 0, 1)) == SET
1956 && REG_P (XEXP (XVECEXP (exp, 0, 1), 0)))
1957 {
1958 if (REG_P (XEXP (XVECEXP (exp, 0, 0), 0))
1959 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 1)) == MEM)
1960 {
1961 /* For "move.S [rx=ry+o],rz", say CC reflects
1962 value1=rz and value2=[rx] */
1963 cc_status.value1 = XEXP (XVECEXP (exp, 0, 0), 0);
1964 cc_status.value2
1965 = gen_rtx_MEM (GET_MODE (XEXP (XVECEXP (exp, 0, 0), 0)),
1966 XEXP (XVECEXP (exp, 0, 1), 0));
1967 cc_status.flags = 0;
1968
1969 /* Huh? A side-effect cannot change the destination
1970 register. */
1971 if (cris_reg_overlap_mentioned_p (cc_status.value1,
1972 cc_status.value2))
1973 internal_error ("internal error: sideeffect-insn affecting main effect");
1974 return;
1975 }
1976 else if ((REG_P (XEXP (XVECEXP (exp, 0, 0), 1))
1977 || XEXP (XVECEXP (exp, 0, 0), 1) == const0_rtx)
1978 && GET_CODE (XEXP (XVECEXP (exp, 0, 0), 0)) == MEM)
1979 {
1980 /* For "move.S rz,[rx=ry+o]" and "clear.S [rx=ry+o]",
1981 say flags are not changed, except for overlap. */
1982 if (cc_status.value1
1983 && cris_reg_overlap_mentioned_p (XEXP
1984 (XVECEXP
1985 (exp, 0, 0), 0),
1986 cc_status.value1))
1987 cc_status.value1 = 0;
1988
1989 if (cc_status.value1
1990 && cris_reg_overlap_mentioned_p (XEXP
1991 (XVECEXP
1992 (exp, 0, 1), 0),
1993 cc_status.value1))
1994 cc_status.value1 = 0;
1995
1996 if (cc_status.value2
1997 && cris_reg_overlap_mentioned_p (XEXP
1998 (XVECEXP
1999 (exp, 0, 0), 0),
2000 cc_status.value2))
2001 cc_status.value2 = 0;
2002
2003 if (cc_status.value2
2004 && cris_reg_overlap_mentioned_p (XEXP
2005 (XVECEXP
2006 (exp, 0, 1), 0),
2007 cc_status.value2))
2008 cc_status.value2 = 0;
2009
2010 return;
2011 }
2012 }
2013 }
2014 break;
2015
2016 default:
2017 /* Unknown cc_attr value. */
2018 abort ();
2019 }
2020
2021 CC_STATUS_INIT;
2022 }
2023
2024 /* Return != 0 if the return sequence for the current function is short,
2025 like "ret" or "jump [sp+]". Prior to reloading, we can't tell how
2026 many registers must be saved, so return 0 then. */
2027
2028 int
2029 cris_simple_epilogue (void)
2030 {
2031 int regno;
2032 int reglimit = STACK_POINTER_REGNUM;
2033 int lastreg = -1;
2034
2035 if (! reload_completed
2036 || frame_pointer_needed
2037 || get_frame_size () != 0
2038 || current_function_pretend_args_size
2039 || current_function_args_size
2040 || current_function_outgoing_args_size
2041 || current_function_calls_eh_return
2042
2043 /* If we're not supposed to emit prologue and epilogue, we must
2044 not emit return-type instructions. */
2045 || !TARGET_PROLOGUE_EPILOGUE)
2046 return 0;
2047
2048 /* We allow a "movem [sp+],rN" to sit in front if the "jump [sp+]" or
2049 in the delay-slot of the "ret". */
2050 for (regno = 0; regno < reglimit; regno++)
2051 if ((regs_ever_live[regno] && ! call_used_regs[regno])
2052 || (regno == (int) PIC_OFFSET_TABLE_REGNUM
2053 && (current_function_uses_pic_offset_table
2054 /* It is saved anyway, if there would be a gap. */
2055 || (flag_pic
2056 && regs_ever_live[regno + 1]
2057 && !call_used_regs[regno + 1]))))
2058 {
2059 if (lastreg != regno - 1)
2060 return 0;
2061 lastreg = regno;
2062 }
2063
2064 return 1;
2065 }
2066
2067 /* Compute a (partial) cost for rtx X. Return true if the complete
2068 cost has been computed, and false if subexpressions should be
2069 scanned. In either case, *TOTAL contains the cost result. */
2070
2071 static bool
2072 cris_rtx_costs (rtx x, int code, int outer_code, int *total)
2073 {
2074 switch (code)
2075 {
2076 case CONST_INT:
2077 {
2078 HOST_WIDE_INT val = INTVAL (x);
2079 if (val == 0)
2080 *total = 0;
2081 else if (val < 32 && val >= -32)
2082 *total = 1;
2083 /* Eight or 16 bits are a word and cycle more expensive. */
2084 else if (val <= 32767 && val >= -32768)
2085 *total = 2;
2086 /* A 32 bit constant (or very seldom, unsigned 16 bits) costs
2087 another word. FIXME: This isn't linear to 16 bits. */
2088 else
2089 *total = 4;
2090 return true;
2091 }
2092
2093 case LABEL_REF:
2094 *total = 6;
2095 return true;
2096
2097 case CONST:
2098 case SYMBOL_REF:
2099 /* For PIC, we need a prefix (if it isn't already there),
2100 and the PIC register. For a global PIC symbol, we also
2101 need a read of the GOT. */
2102 if (flag_pic)
2103 {
2104 if (cris_got_symbol (x))
2105 *total = 2 + 4 + 6;
2106 else
2107 *total = 2 + 6;
2108 }
2109 else
2110 *total = 6;
2111 return true;
2112
2113 case CONST_DOUBLE:
2114 if (x != CONST0_RTX (GET_MODE (x) == VOIDmode ? DImode : GET_MODE (x)))
2115 *total = 12;
2116 else
2117 /* Make 0.0 cheap, else test-insns will not be used. */
2118 *total = 0;
2119 return true;
2120
2121 case MULT:
2122 /* Identify values that are no powers of two. Powers of 2 are
2123 taken care of already and those values should not be changed. */
2124 if (GET_CODE (XEXP (x, 1)) != CONST_INT
2125 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
2126 {
2127 /* If we have a multiply insn, then the cost is between
2128 1 and 2 "fast" instructions. */
2129 if (TARGET_HAS_MUL_INSNS)
2130 {
2131 *total = COSTS_N_INSNS (1) + COSTS_N_INSNS (1) / 2;
2132 return true;
2133 }
2134
2135 /* Estimate as 4 + 4 * #ofbits. */
2136 *total = COSTS_N_INSNS (132);
2137 return true;
2138 }
2139 return false;
2140
2141 case UDIV:
2142 case MOD:
2143 case UMOD:
2144 case DIV:
2145 if (GET_CODE (XEXP (x, 1)) != CONST_INT
2146 || exact_log2 (INTVAL (XEXP (x, 1)) < 0))
2147 {
2148 /* Estimate this as 4 + 8 * #of bits. */
2149 *total = COSTS_N_INSNS (260);
2150 return true;
2151 }
2152 return false;
2153
2154 case AND:
2155 if (GET_CODE (XEXP (x, 1)) == CONST_INT
2156 /* Two constants may actually happen before optimization. */
2157 && GET_CODE (XEXP (x, 0)) != CONST_INT
2158 && !CONST_OK_FOR_LETTER_P (INTVAL (XEXP (x, 1)), 'I'))
2159 {
2160 *total = (rtx_cost (XEXP (x, 0), outer_code) + 2
2161 + 2 * GET_MODE_NUNITS (GET_MODE (XEXP (x, 0))));
2162 return true;
2163 }
2164 return false;
2165
2166 case ZERO_EXTEND: case SIGN_EXTEND:
2167 *total = rtx_cost (XEXP (x, 0), outer_code);
2168 return true;
2169
2170 default:
2171 return false;
2172 }
2173 }
2174
2175 /* The ADDRESS_COST worker. */
2176
2177 static int
2178 cris_address_cost (rtx x)
2179 {
2180 /* The metric to use for the cost-macros is unclear.
2181 The metric used here is (the number of cycles needed) / 2,
2182 where we consider equal a cycle for a word of code and a cycle to
2183 read memory. */
2184
2185 /* The cheapest addressing modes get 0, since nothing extra is needed. */
2186 if (BASE_OR_AUTOINCR_P (x))
2187 return 0;
2188
2189 /* An indirect mem must be a DIP. This means two bytes extra for code,
2190 and 4 bytes extra for memory read, i.e. (2 + 4) / 2. */
2191 if (GET_CODE (x) == MEM)
2192 return (2 + 4) / 2;
2193
2194 /* Assume (2 + 4) / 2 for a single constant; a dword, since it needs
2195 an extra DIP prefix and 4 bytes of constant in most cases.
2196 For PIC and a symbol with a GOT entry, we double the cost since we
2197 add a [rPIC+...] offset. A GOT-less symbol uses a BDAP prefix
2198 equivalent to the DIP prefix for non-PIC, hence the same cost. */
2199 if (CONSTANT_P (x))
2200 return flag_pic && cris_got_symbol (x) ? 2 * (2 + 4) / 2 : (2 + 4) / 2;
2201
2202 /* Handle BIAP and BDAP prefixes. */
2203 if (GET_CODE (x) == PLUS)
2204 {
2205 rtx tem1 = XEXP (x, 0);
2206 rtx tem2 = XEXP (x, 1);
2207
2208 /* A BIAP is 2 extra bytes for the prefix insn, nothing more. We
2209 recognize the typical MULT which is always in tem1 because of
2210 insn canonicalization. */
2211 if ((GET_CODE (tem1) == MULT && BIAP_INDEX_P (tem1))
2212 || REG_P (tem1))
2213 return 2 / 2;
2214
2215 /* A BDAP (quick) is 2 extra bytes. Any constant operand to the
2216 PLUS is always found in tem2. */
2217 if (GET_CODE (tem2) == CONST_INT
2218 && INTVAL (tem2) < 128 && INTVAL (tem2) >= -128)
2219 return 2 / 2;
2220
2221 /* A BDAP -32768 .. 32767 is like BDAP quick, but with 2 extra
2222 bytes. */
2223 if (GET_CODE (tem2) == CONST_INT
2224 && CONST_OK_FOR_LETTER_P (INTVAL (tem2), 'L'))
2225 return (2 + 2) / 2;
2226
2227 /* A BDAP with some other constant is 2 bytes extra. */
2228 if (CONSTANT_P (tem2))
2229 return (2 + 2 + 2) / 2;
2230
2231 /* BDAP with something indirect should have a higher cost than
2232 BIAP with register. FIXME: Should it cost like a MEM or more? */
2233 /* Don't need to check it, it's the only one left.
2234 FIXME: There was a REG test missing, perhaps there are others.
2235 Think more. */
2236 return (2 + 2 + 2) / 2;
2237 }
2238
2239 /* What else? Return a high cost. It matters only for valid
2240 addressing modes. */
2241 return 10;
2242 }
2243
2244 /* Check various objections to the side-effect. Used in the test-part
2245 of an anonymous insn describing an insn with a possible side-effect.
2246 Returns nonzero if the implied side-effect is ok.
2247
2248 code : PLUS or MULT
2249 ops : An array of rtx:es. lreg, rreg, rval,
2250 The variables multop and other_op are indexes into this,
2251 or -1 if they are not applicable.
2252 lreg : The register that gets assigned in the side-effect.
2253 rreg : One register in the side-effect expression
2254 rval : The other register, or an int.
2255 multop : An integer to multiply rval with.
2256 other_op : One of the entities of the main effect,
2257 whose mode we must consider. */
2258
2259 int
2260 cris_side_effect_mode_ok (enum rtx_code code, rtx *ops,
2261 int lreg, int rreg, int rval,
2262 int multop, int other_op)
2263 {
2264 /* Find what value to multiply with, for rx =ry + rz * n. */
2265 int mult = multop < 0 ? 1 : INTVAL (ops[multop]);
2266
2267 rtx reg_rtx = ops[rreg];
2268 rtx val_rtx = ops[rval];
2269
2270 /* The operands may be swapped. Canonicalize them in reg_rtx and
2271 val_rtx, where reg_rtx always is a reg (for this constraint to
2272 match). */
2273 if (! BASE_P (reg_rtx))
2274 reg_rtx = val_rtx, val_rtx = ops[rreg];
2275
2276 /* Don't forget to check that reg_rtx really is a reg. If it isn't,
2277 we have no business. */
2278 if (! BASE_P (reg_rtx))
2279 return 0;
2280
2281 /* Don't do this when -mno-split. */
2282 if (!TARGET_SIDE_EFFECT_PREFIXES)
2283 return 0;
2284
2285 /* The mult expression may be hidden in lreg. FIXME: Add more
2286 commentary about that. */
2287 if (GET_CODE (val_rtx) == MULT)
2288 {
2289 mult = INTVAL (XEXP (val_rtx, 1));
2290 val_rtx = XEXP (val_rtx, 0);
2291 code = MULT;
2292 }
2293
2294 /* First check the "other operand". */
2295 if (other_op >= 0)
2296 {
2297 if (GET_MODE_SIZE (GET_MODE (ops[other_op])) > UNITS_PER_WORD)
2298 return 0;
2299
2300 /* Check if the lvalue register is the same as the "other
2301 operand". If so, the result is undefined and we shouldn't do
2302 this. FIXME: Check again. */
2303 if ((BASE_P (ops[lreg])
2304 && BASE_P (ops[other_op])
2305 && REGNO (ops[lreg]) == REGNO (ops[other_op]))
2306 || rtx_equal_p (ops[other_op], ops[lreg]))
2307 return 0;
2308 }
2309
2310 /* Do not accept frame_pointer_rtx as any operand. */
2311 if (ops[lreg] == frame_pointer_rtx || ops[rreg] == frame_pointer_rtx
2312 || ops[rval] == frame_pointer_rtx
2313 || (other_op >= 0 && ops[other_op] == frame_pointer_rtx))
2314 return 0;
2315
2316 if (code == PLUS
2317 && ! BASE_P (val_rtx))
2318 {
2319
2320 /* Do not allow rx = rx + n if a normal add or sub with same size
2321 would do. */
2322 if (rtx_equal_p (ops[lreg], reg_rtx)
2323 && GET_CODE (val_rtx) == CONST_INT
2324 && (INTVAL (val_rtx) <= 63 && INTVAL (val_rtx) >= -63))
2325 return 0;
2326
2327 /* Check allowed cases, like [r(+)?].[bwd] and const.
2328 A symbol is not allowed with PIC. */
2329 if (CONSTANT_P (val_rtx))
2330 return flag_pic == 0 || cris_symbol (val_rtx) == 0;
2331
2332 if (GET_CODE (val_rtx) == MEM
2333 && BASE_OR_AUTOINCR_P (XEXP (val_rtx, 0)))
2334 return 1;
2335
2336 if (GET_CODE (val_rtx) == SIGN_EXTEND
2337 && GET_CODE (XEXP (val_rtx, 0)) == MEM
2338 && BASE_OR_AUTOINCR_P (XEXP (XEXP (val_rtx, 0), 0)))
2339 return 1;
2340
2341 /* If we got here, it's not a valid addressing mode. */
2342 return 0;
2343 }
2344 else if (code == MULT
2345 || (code == PLUS && BASE_P (val_rtx)))
2346 {
2347 /* Do not allow rx = rx + ry.S, since it doesn't give better code. */
2348 if (rtx_equal_p (ops[lreg], reg_rtx)
2349 || (mult == 1 && rtx_equal_p (ops[lreg], val_rtx)))
2350 return 0;
2351
2352 /* Do not allow bad multiply-values. */
2353 if (mult != 1 && mult != 2 && mult != 4)
2354 return 0;
2355
2356 /* Only allow r + ... */
2357 if (! BASE_P (reg_rtx))
2358 return 0;
2359
2360 /* If we got here, all seems ok.
2361 (All checks need to be done above). */
2362 return 1;
2363 }
2364
2365 /* If we get here, the caller got its initial tests wrong. */
2366 internal_error ("internal error: cris_side_effect_mode_ok with bad operands");
2367 }
2368
2369 /* The function reg_overlap_mentioned_p in CVS (still as of 2001-05-16)
2370 does not handle the case where the IN operand is strict_low_part; it
2371 does handle it for X. Test-case in Axis-20010516. This function takes
2372 care of that for THIS port. FIXME: strict_low_part is going away
2373 anyway. */
2374
2375 static int
2376 cris_reg_overlap_mentioned_p (rtx x, rtx in)
2377 {
2378 /* The function reg_overlap_mentioned now handles when X is
2379 strict_low_part, but not when IN is a STRICT_LOW_PART. */
2380 if (GET_CODE (in) == STRICT_LOW_PART)
2381 in = XEXP (in, 0);
2382
2383 return reg_overlap_mentioned_p (x, in);
2384 }
2385
2386 /* The TARGET_ASM_NAMED_SECTION worker.
2387 We just dispatch to the functions for ELF and a.out. */
2388
2389 void
2390 cris_target_asm_named_section (const char *name, unsigned int flags)
2391 {
2392 if (! TARGET_ELF)
2393 default_no_named_section (name, flags);
2394 else
2395 default_elf_asm_named_section (name, flags);
2396 }
2397
2398 /* The LEGITIMATE_PIC_OPERAND_P worker. */
2399
2400 int
2401 cris_legitimate_pic_operand (rtx x)
2402 {
2403 /* The PIC representation of a symbol with a GOT entry will be (for
2404 example; relocations differ):
2405 sym => [rPIC+sym:GOT]
2406 and for a GOT-less symbol it will be (for example, relocation differ):
2407 sym => rPIC+sym:GOTOFF
2408 so only a symbol with a GOT is by itself a valid operand, and it
2409 can't be a sum of a symbol and an offset. */
2410 return ! cris_symbol (x) || cris_got_symbol (x);
2411 }
2412
2413 /* Return nonzero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2414 CONSTANT_P. */
2415
2416 int
2417 cris_symbol (rtx x)
2418 {
2419 switch (GET_CODE (x))
2420 {
2421 case SYMBOL_REF:
2422 case LABEL_REF:
2423 return 1;
2424
2425 case UNSPEC:
2426 /* A PLT reference. */
2427 ASSERT_PLT_UNSPEC (x);
2428 return 1;
2429
2430 case CONST:
2431 return cris_symbol (XEXP (x, 0));
2432
2433 case PLUS:
2434 case MINUS:
2435 return cris_symbol (XEXP (x, 0)) || cris_symbol (XEXP (x, 1));
2436
2437 case CONST_INT:
2438 case CONST_DOUBLE:
2439 case CONSTANT_P_RTX:
2440 return 0;
2441
2442 default:
2443 fatal_insn ("unrecognized supposed constant", x);
2444 }
2445
2446 return 1;
2447 }
2448
2449 /* Return nonzero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2450 CONSTANT_P, and the symbol does not need a GOT entry. Also set
2451 current_function_uses_pic_offset_table if we're generating PIC and ever
2452 see something that would need one. */
2453
2454 int
2455 cris_gotless_symbol (rtx x)
2456 {
2457 #ifdef ENABLE_CHECKING
2458 if (!flag_pic)
2459 abort ();
2460 #endif
2461
2462 switch (GET_CODE (x))
2463 {
2464 case UNSPEC:
2465 ASSERT_PLT_UNSPEC (x);
2466 return 1;
2467
2468 case SYMBOL_REF:
2469 if (cfun != NULL)
2470 current_function_uses_pic_offset_table = 1;
2471 return SYMBOL_REF_LOCAL_P (x);
2472
2473 case LABEL_REF:
2474 /* We don't set current_function_uses_pic_offset_table for
2475 LABEL_REF:s in here, since they are almost always originating
2476 from some branch. The only time it does not come from a label is
2477 when GCC does something like __builtin_setjmp. Then we get the
2478 LABEL_REF from the movsi expander, so we mark it there as a
2479 special case. */
2480 return 1;
2481
2482 case CONST:
2483 return cris_gotless_symbol (XEXP (x, 0));
2484
2485 case PLUS:
2486 case MINUS:
2487 {
2488 int x0 = cris_gotless_symbol (XEXP (x, 0)) != 0;
2489 int x1 = cris_gotless_symbol (XEXP (x, 1)) != 0;
2490
2491 /* One and only one of them must be a local symbol. Neither must
2492 be some other, more general kind of symbol. */
2493 return
2494 (x0 ^ x1)
2495 && ! (x0 == 0 && cris_symbol (XEXP (x, 0)))
2496 && ! (x1 == 0 && cris_symbol (XEXP (x, 1)));
2497 }
2498
2499 case CONST_INT:
2500 case CONST_DOUBLE:
2501 case CONSTANT_P_RTX:
2502 return 0;
2503
2504 default:
2505 fatal_insn ("unrecognized supposed constant", x);
2506 }
2507
2508 return 1;
2509 }
2510
2511 /* Return nonzero if there's a SYMBOL_REF or LABEL_REF hiding inside this
2512 CONSTANT_P, and the symbol needs a GOT entry. */
2513
2514 int
2515 cris_got_symbol (rtx x)
2516 {
2517 #ifdef ENABLE_CHECKING
2518 if (!flag_pic)
2519 abort ();
2520 #endif
2521
2522 switch (GET_CODE (x))
2523 {
2524 case UNSPEC:
2525 ASSERT_PLT_UNSPEC (x);
2526 return 0;
2527
2528 case SYMBOL_REF:
2529 if (cfun != NULL)
2530 current_function_uses_pic_offset_table = 1;
2531 return ! SYMBOL_REF_LOCAL_P (x);
2532
2533 case CONST:
2534 return cris_got_symbol (XEXP (x, 0));
2535
2536 case LABEL_REF:
2537 /* A LABEL_REF is never visible as a symbol outside the local
2538 function. */
2539 case PLUS:
2540 case MINUS:
2541 /* Nope, can't access the GOT for "symbol + offset". */
2542 return 0;
2543
2544 case CONST_INT:
2545 case CONST_DOUBLE:
2546 case CONSTANT_P_RTX:
2547 return 0;
2548
2549 default:
2550 fatal_insn ("unrecognized supposed constant in cris_global_pic_symbol",
2551 x);
2552 }
2553
2554 return 1;
2555 }
2556
2557 /* The OVERRIDE_OPTIONS worker.
2558 As is the norm, this also parses -mfoo=bar type parameters. */
2559
2560 void
2561 cris_override_options (void)
2562 {
2563 if (cris_max_stackframe_str)
2564 {
2565 cris_max_stackframe = atoi (cris_max_stackframe_str);
2566
2567 /* Do some sanity checking. */
2568 if (cris_max_stackframe < 0 || cris_max_stackframe > 0x20000000)
2569 internal_error ("-max-stackframe=%d is not usable, not between 0 and %d",
2570 cris_max_stackframe, 0x20000000);
2571 }
2572
2573 /* Let "-metrax4" and "-metrax100" change the cpu version. */
2574 if (TARGET_SVINTO && cris_cpu_version < CRIS_CPU_SVINTO)
2575 cris_cpu_version = CRIS_CPU_SVINTO;
2576 else if (TARGET_ETRAX4_ADD && cris_cpu_version < CRIS_CPU_ETRAX4)
2577 cris_cpu_version = CRIS_CPU_ETRAX4;
2578
2579 /* Parse -march=... and its synonym, the deprecated -mcpu=... */
2580 if (cris_cpu_str)
2581 {
2582 cris_cpu_version
2583 = (*cris_cpu_str == 'v' ? atoi (cris_cpu_str + 1) : -1);
2584
2585 if (strcmp ("etrax4", cris_cpu_str) == 0)
2586 cris_cpu_version = 3;
2587
2588 if (strcmp ("svinto", cris_cpu_str) == 0
2589 || strcmp ("etrax100", cris_cpu_str) == 0)
2590 cris_cpu_version = 8;
2591
2592 if (strcmp ("ng", cris_cpu_str) == 0
2593 || strcmp ("etrax100lx", cris_cpu_str) == 0)
2594 cris_cpu_version = 10;
2595
2596 if (cris_cpu_version < 0 || cris_cpu_version > 10)
2597 error ("unknown CRIS version specification in -march= or -mcpu= : %s",
2598 cris_cpu_str);
2599
2600 /* Set the target flags. */
2601 if (cris_cpu_version >= CRIS_CPU_ETRAX4)
2602 target_flags |= TARGET_MASK_ETRAX4_ADD;
2603
2604 /* If this is Svinto or higher, align for 32 bit accesses. */
2605 if (cris_cpu_version >= CRIS_CPU_SVINTO)
2606 target_flags
2607 |= (TARGET_MASK_SVINTO | TARGET_MASK_ALIGN_BY_32
2608 | TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2609 | TARGET_MASK_DATA_ALIGN);
2610
2611 /* Note that we do not add new flags when it can be completely
2612 described with a macro that uses -mcpu=X. So
2613 TARGET_HAS_MUL_INSNS is (cris_cpu_version >= CRIS_CPU_NG). */
2614 }
2615
2616 if (cris_tune_str)
2617 {
2618 int cris_tune
2619 = (*cris_tune_str == 'v' ? atoi (cris_tune_str + 1) : -1);
2620
2621 if (strcmp ("etrax4", cris_tune_str) == 0)
2622 cris_tune = 3;
2623
2624 if (strcmp ("svinto", cris_tune_str) == 0
2625 || strcmp ("etrax100", cris_tune_str) == 0)
2626 cris_tune = 8;
2627
2628 if (strcmp ("ng", cris_tune_str) == 0
2629 || strcmp ("etrax100lx", cris_tune_str) == 0)
2630 cris_tune = 10;
2631
2632 if (cris_tune < 0 || cris_tune > 10)
2633 error ("unknown CRIS cpu version specification in -mtune= : %s",
2634 cris_tune_str);
2635
2636 if (cris_tune >= CRIS_CPU_SVINTO)
2637 /* We have currently nothing more to tune than alignment for
2638 memory accesses. */
2639 target_flags
2640 |= (TARGET_MASK_STACK_ALIGN | TARGET_MASK_CONST_ALIGN
2641 | TARGET_MASK_DATA_ALIGN | TARGET_MASK_ALIGN_BY_32);
2642 }
2643
2644 if (flag_pic)
2645 {
2646 /* Use error rather than warning, so invalid use is easily
2647 detectable. Still change to the values we expect, to avoid
2648 further errors. */
2649 if (! TARGET_LINUX)
2650 {
2651 error ("-fPIC and -fpic are not supported in this configuration");
2652 flag_pic = 0;
2653 }
2654
2655 /* Turn off function CSE. We need to have the addresses reach the
2656 call expanders to get PLT-marked, as they could otherwise be
2657 compared against zero directly or indirectly. After visiting the
2658 call expanders they will then be cse:ed, as the call expanders
2659 force_reg the addresses, effectively forcing flag_no_function_cse
2660 to 0. */
2661 flag_no_function_cse = 1;
2662 }
2663
2664 if ((write_symbols == DWARF_DEBUG
2665 || write_symbols == DWARF2_DEBUG) && ! TARGET_ELF)
2666 {
2667 warning ("that particular -g option is invalid with -maout and -melinux");
2668 write_symbols = DBX_DEBUG;
2669 }
2670
2671 /* Set the per-function-data initializer. */
2672 init_machine_status = cris_init_machine_status;
2673 }
2674
2675 /* The TARGET_ASM_OUTPUT_MI_THUNK worker. */
2676
2677 static void
2678 cris_asm_output_mi_thunk (FILE *stream,
2679 tree thunkdecl ATTRIBUTE_UNUSED,
2680 HOST_WIDE_INT delta,
2681 HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED,
2682 tree funcdecl)
2683 {
2684 if (delta > 0)
2685 fprintf (stream, "\tadd%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2686 ADDITIVE_SIZE_MODIFIER (delta), delta,
2687 reg_names[CRIS_FIRST_ARG_REG]);
2688 else if (delta < 0)
2689 fprintf (stream, "\tsub%s " HOST_WIDE_INT_PRINT_DEC ",$%s\n",
2690 ADDITIVE_SIZE_MODIFIER (-delta), -delta,
2691 reg_names[CRIS_FIRST_ARG_REG]);
2692
2693 if (flag_pic)
2694 {
2695 const char *name = XSTR (XEXP (DECL_RTL (funcdecl), 0), 0);
2696
2697 name = (* targetm.strip_name_encoding) (name);
2698 fprintf (stream, "add.d ");
2699 assemble_name (stream, name);
2700 fprintf (stream, "%s,$pc\n", CRIS_PLT_PCOFFSET_SUFFIX);
2701 }
2702 else
2703 {
2704 fprintf (stream, "jump ");
2705 assemble_name (stream, XSTR (XEXP (DECL_RTL (funcdecl), 0), 0));
2706 fprintf (stream, "\n");
2707 }
2708 }
2709
2710 /* Boilerplate emitted at start of file.
2711
2712 NO_APP *only at file start* means faster assembly. It also means
2713 comments are not allowed. In some cases comments will be output
2714 for debugging purposes. Make sure they are allowed then.
2715
2716 We want a .file directive only if TARGET_ELF. */
2717 static void
2718 cris_file_start (void)
2719 {
2720 /* These expressions can vary at run time, so we cannot put
2721 them into TARGET_INITIALIZER. */
2722 targetm.file_start_app_off = !(TARGET_PDEBUG || flag_print_asm_name);
2723 targetm.file_start_file_directive = TARGET_ELF;
2724
2725 default_file_start ();
2726 }
2727
2728 /* Rename the function calls for integer multiply and divide. */
2729 static void
2730 cris_init_libfuncs ()
2731 {
2732 set_optab_libfunc (smul_optab, SImode, "__Mul");
2733 set_optab_libfunc (sdiv_optab, SImode, "__Div");
2734 set_optab_libfunc (udiv_optab, SImode, "__Udiv");
2735 set_optab_libfunc (smod_optab, SImode, "__Mod");
2736 set_optab_libfunc (umod_optab, SImode, "__Umod");
2737 }
2738
2739 /* The EXPAND_BUILTIN_VA_ARG worker. This is modified from the
2740 "standard" implementation of va_arg: read the value from the current
2741 address and increment by the size of one or two registers. The
2742 important difference for CRIS is that if the type is
2743 pass-by-reference, then perform an indirection. */
2744
2745 rtx
2746 cris_expand_builtin_va_arg (tree valist, tree type)
2747 {
2748 tree addr_tree, t;
2749 rtx addr;
2750 tree passed_size = size_zero_node;
2751 tree type_size = NULL;
2752 tree size3 = size_int (3);
2753 tree size4 = size_int (4);
2754 tree size8 = size_int (8);
2755 tree rounded_size;
2756
2757 /* Get AP. */
2758 addr_tree = valist;
2759
2760 if (type == error_mark_node
2761 || (type_size = TYPE_SIZE_UNIT (TYPE_MAIN_VARIANT (type))) == NULL
2762 || TREE_OVERFLOW (type_size))
2763 /* Presumably an error; the size isn't computable. A message has
2764 supposedly been emitted elsewhere. */
2765 rounded_size = size_zero_node;
2766 else
2767 rounded_size
2768 = fold (build (MULT_EXPR, sizetype,
2769 fold (build (TRUNC_DIV_EXPR, sizetype,
2770 fold (build (PLUS_EXPR, sizetype,
2771 type_size, size3)),
2772 size4)),
2773 size4));
2774
2775 if (!integer_zerop (rounded_size))
2776 {
2777 /* Check if the type is passed by value or by reference. Values up
2778 to 8 bytes are passed by-value, padded to register-size (4
2779 bytes). Larger values and varying-size types are passed
2780 by reference. */
2781 passed_size
2782 = (!really_constant_p (type_size)
2783 ? size4
2784 : fold (build (COND_EXPR, sizetype,
2785 fold (build (GT_EXPR, sizetype,
2786 rounded_size,
2787 size8)),
2788 size4,
2789 rounded_size)));
2790
2791 addr_tree
2792 = (!really_constant_p (type_size)
2793 ? build1 (INDIRECT_REF, build_pointer_type (type), addr_tree)
2794 : fold (build (COND_EXPR, TREE_TYPE (addr_tree),
2795 fold (build (GT_EXPR, sizetype,
2796 rounded_size,
2797 size8)),
2798 build1 (INDIRECT_REF, build_pointer_type (type),
2799 addr_tree),
2800 addr_tree)));
2801 }
2802
2803 addr = expand_expr (addr_tree, NULL_RTX, Pmode, EXPAND_NORMAL);
2804 addr = copy_to_reg (addr);
2805
2806 if (!integer_zerop (rounded_size))
2807 {
2808 /* Compute new value for AP. */
2809 t = build (MODIFY_EXPR, TREE_TYPE (valist), valist,
2810 build (PLUS_EXPR, TREE_TYPE (valist), valist,
2811 passed_size));
2812 TREE_SIDE_EFFECTS (t) = 1;
2813 expand_expr (t, const0_rtx, VOIDmode, EXPAND_NORMAL);
2814 }
2815
2816 return addr;
2817 }
2818
2819 /* The INIT_EXPANDERS worker sets the per-function-data initializer and
2820 mark functions. */
2821
2822 void
2823 cris_init_expanders (void)
2824 {
2825 /* Nothing here at the moment. */
2826 }
2827
2828 /* Zero initialization is OK for all current fields. */
2829
2830 static struct machine_function *
2831 cris_init_machine_status (void)
2832 {
2833 return ggc_alloc_cleared (sizeof (struct machine_function));
2834 }
2835
2836 /* Split a 2 word move (DI or presumably DF) into component parts.
2837 Originally a copy of gen_split_move_double in m32r.c. */
2838
2839 rtx
2840 cris_split_movdx (rtx *operands)
2841 {
2842 enum machine_mode mode = GET_MODE (operands[0]);
2843 rtx dest = operands[0];
2844 rtx src = operands[1];
2845 rtx val;
2846
2847 /* We used to have to handle (SUBREG (MEM)) here, but that should no
2848 longer happen; after reload there are no SUBREGs any more, and we're
2849 only called after reload. */
2850 if (GET_CODE (dest) == SUBREG || GET_CODE (src) == SUBREG)
2851 abort ();
2852
2853 start_sequence ();
2854 if (GET_CODE (dest) == REG)
2855 {
2856 int dregno = REGNO (dest);
2857
2858 /* Reg-to-reg copy. */
2859 if (GET_CODE (src) == REG)
2860 {
2861 int sregno = REGNO (src);
2862
2863 int reverse = (dregno == sregno + 1);
2864
2865 /* We normally copy the low-numbered register first. However, if
2866 the first register operand 0 is the same as the second register of
2867 operand 1, we must copy in the opposite order. */
2868 emit_insn (gen_rtx_SET (VOIDmode,
2869 operand_subword (dest, reverse, TRUE, mode),
2870 operand_subword (src, reverse, TRUE, mode)));
2871
2872 emit_insn (gen_rtx_SET (VOIDmode,
2873 operand_subword (dest, !reverse, TRUE, mode),
2874 operand_subword (src, !reverse, TRUE, mode)));
2875 }
2876 /* Constant-to-reg copy. */
2877 else if (GET_CODE (src) == CONST_INT || GET_CODE (src) == CONST_DOUBLE)
2878 {
2879 rtx words[2];
2880 split_double (src, &words[0], &words[1]);
2881 emit_insn (gen_rtx_SET (VOIDmode,
2882 operand_subword (dest, 0, TRUE, mode),
2883 words[0]));
2884
2885 emit_insn (gen_rtx_SET (VOIDmode,
2886 operand_subword (dest, 1, TRUE, mode),
2887 words[1]));
2888 }
2889 /* Mem-to-reg copy. */
2890 else if (GET_CODE (src) == MEM)
2891 {
2892 /* If the high-address word is used in the address, we must load it
2893 last. Otherwise, load it first. */
2894 rtx addr = XEXP (src, 0);
2895 int reverse
2896 = (refers_to_regno_p (dregno, dregno + 1, addr, NULL) != 0);
2897
2898 /* The original code imples that we can't do
2899 move.x [rN+],rM move.x [rN],rM+1
2900 when rN is dead, because of REG_NOTES damage. That is
2901 consistent with what I've seen, so don't try it.
2902
2903 We have two different cases here; if the addr is POST_INC,
2904 just pass it through, otherwise add constants. */
2905
2906 if (GET_CODE (addr) == POST_INC)
2907 {
2908 emit_insn (gen_rtx_SET (VOIDmode,
2909 operand_subword (dest, 0, TRUE, mode),
2910 change_address (src, SImode, addr)));
2911 emit_insn (gen_rtx_SET (VOIDmode,
2912 operand_subword (dest, 1, TRUE, mode),
2913 change_address (src, SImode, addr)));
2914 }
2915 else
2916 {
2917 /* Make sure we don't get any other addresses with
2918 embedded postincrements. They should be stopped in
2919 GO_IF_LEGITIMATE_ADDRESS, but we're here for your
2920 safety. */
2921 if (side_effects_p (addr))
2922 fatal_insn ("unexpected side-effects in address", addr);
2923
2924 emit_insn (gen_rtx_SET
2925 (VOIDmode,
2926 operand_subword (dest, reverse, TRUE, mode),
2927 change_address
2928 (src, SImode,
2929 plus_constant (addr,
2930 reverse * UNITS_PER_WORD))));
2931 emit_insn (gen_rtx_SET
2932 (VOIDmode,
2933 operand_subword (dest, ! reverse, TRUE, mode),
2934 change_address
2935 (src, SImode,
2936 plus_constant (addr,
2937 (! reverse) *
2938 UNITS_PER_WORD))));
2939 }
2940 }
2941 else
2942 abort ();
2943 }
2944 /* Reg-to-mem copy or clear mem. */
2945 else if (GET_CODE (dest) == MEM
2946 && (GET_CODE (src) == REG
2947 || src == const0_rtx
2948 || src == CONST0_RTX (DFmode)))
2949 {
2950 rtx addr = XEXP (dest, 0);
2951
2952 if (GET_CODE (addr) == POST_INC)
2953 {
2954 emit_insn (gen_rtx_SET (VOIDmode,
2955 change_address (dest, SImode, addr),
2956 operand_subword (src, 0, TRUE, mode)));
2957 emit_insn (gen_rtx_SET (VOIDmode,
2958 change_address (dest, SImode, addr),
2959 operand_subword (src, 1, TRUE, mode)));
2960 }
2961 else
2962 {
2963 /* Make sure we don't get any other addresses with embedded
2964 postincrements. They should be stopped in
2965 GO_IF_LEGITIMATE_ADDRESS, but we're here for your safety. */
2966 if (side_effects_p (addr))
2967 fatal_insn ("unexpected side-effects in address", addr);
2968
2969 emit_insn (gen_rtx_SET
2970 (VOIDmode,
2971 change_address (dest, SImode, addr),
2972 operand_subword (src, 0, TRUE, mode)));
2973
2974 emit_insn (gen_rtx_SET
2975 (VOIDmode,
2976 change_address (dest, SImode,
2977 plus_constant (addr,
2978 UNITS_PER_WORD)),
2979 operand_subword (src, 1, TRUE, mode)));
2980 }
2981 }
2982
2983 else
2984 abort ();
2985
2986 val = get_insns ();
2987 end_sequence ();
2988 return val;
2989 }
2990
2991 /* This is in essence a copy of output_addr_const altered to output
2992 symbolic operands as PIC.
2993
2994 FIXME: Add hooks similar to ASM_OUTPUT_SYMBOL_REF to get this effect in
2995 the "real" output_addr_const. All we need is one for LABEL_REF (and
2996 one for CODE_LABEL?). */
2997
2998 void
2999 cris_output_addr_const (FILE *file, rtx x)
3000 {
3001 int is_plt = 0;
3002
3003 restart:
3004 switch (GET_CODE (x))
3005 {
3006 case UNSPEC:
3007 ASSERT_PLT_UNSPEC (x);
3008 x = XVECEXP (x, 0, 0);
3009 is_plt = 1;
3010
3011 /* Fall through. */
3012 case SYMBOL_REF:
3013 if (flag_pic)
3014 {
3015 const char *origstr = XSTR (x, 0);
3016 const char *str;
3017
3018 str = (* targetm.strip_name_encoding) (origstr);
3019
3020 if (is_plt)
3021 {
3022 if (cris_pic_sympart_only)
3023 {
3024 assemble_name (file, str);
3025 fprintf (file, ":PLTG");
3026 }
3027 else
3028 {
3029 if (TARGET_AVOID_GOTPLT)
3030 /* We shouldn't get here. */
3031 abort ();
3032
3033 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
3034 assemble_name (file, XSTR (x, 0));
3035
3036 if (flag_pic == 1)
3037 fprintf (file, ":GOTPLT16]");
3038 else
3039 fprintf (file, ":GOTPLT]");
3040 }
3041 }
3042 else if (cris_gotless_symbol (x))
3043 {
3044 if (! cris_pic_sympart_only)
3045 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
3046 assemble_name (file, str);
3047 fprintf (file, ":GOTOFF");
3048 }
3049 else if (cris_got_symbol (x))
3050 {
3051 if (cris_pic_sympart_only)
3052 abort ();
3053 fprintf (file, "[$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
3054 assemble_name (file, XSTR (x, 0));
3055
3056 if (flag_pic == 1)
3057 fprintf (file, ":GOT16]");
3058 else
3059 fprintf (file, ":GOT]");
3060 }
3061 else
3062 LOSE_AND_RETURN ("unexpected PIC symbol", x);
3063
3064 /* Sanity check. */
3065 if (! current_function_uses_pic_offset_table)
3066 output_operand_lossage ("PIC register isn't set up");
3067 }
3068 else
3069 assemble_name (file, XSTR (x, 0));
3070 break;
3071
3072 case LABEL_REF:
3073 /* If we get one of those here, it should be dressed as PIC. Branch
3074 labels are normally output with the 'l' specifier, which means it
3075 will go directly to output_asm_label and not end up here. */
3076 if (GET_CODE (XEXP (x, 0)) != CODE_LABEL
3077 && (GET_CODE (XEXP (x, 0)) != NOTE
3078 || NOTE_LINE_NUMBER (XEXP (x, 0)) != NOTE_INSN_DELETED_LABEL))
3079 fatal_insn ("unexpected address expression", x);
3080
3081 if (flag_pic)
3082 {
3083 if (cris_gotless_symbol (x))
3084 {
3085 if (! cris_pic_sympart_only)
3086 fprintf (file, "$%s+", reg_names [PIC_OFFSET_TABLE_REGNUM]);
3087 cris_output_addr_const (file, XEXP (x, 0));
3088
3089 fprintf (file, ":GOTOFF");
3090 }
3091 else
3092 /* Labels are never marked as global symbols. */
3093 fatal_insn ("unexpected PIC symbol", x);
3094
3095 /* Sanity check. */
3096 if (! current_function_uses_pic_offset_table)
3097 internal_error ("emitting PIC operand, but PIC register isn't set up");
3098 break;
3099 }
3100
3101 output_addr_const (file, x);
3102 break;
3103
3104 case NOTE:
3105 if (NOTE_LINE_NUMBER (x) != NOTE_INSN_DELETED_LABEL)
3106 fatal_insn ("unexpected NOTE as addr_const:", x);
3107 case CODE_LABEL:
3108 case CONST_INT:
3109 case CONST_DOUBLE:
3110 case ZERO_EXTEND:
3111 case SIGN_EXTEND:
3112 output_addr_const (file, x);
3113 break;
3114
3115 case CONST:
3116 /* This used to output parentheses around the expression,
3117 but that does not work on the 386 (either ATT or BSD assembler). */
3118 cris_output_addr_const (file, XEXP (x, 0));
3119 break;
3120
3121 case PLUS:
3122 /* Some assemblers need integer constants to appear last (eg masm). */
3123 if (GET_CODE (XEXP (x, 0)) == CONST_INT)
3124 {
3125 cris_output_addr_const (file, XEXP (x, 1));
3126 if (INTVAL (XEXP (x, 0)) >= 0)
3127 fprintf (file, "+");
3128 output_addr_const (file, XEXP (x, 0));
3129 }
3130 else
3131 {
3132 cris_output_addr_const (file, XEXP (x, 0));
3133 if (GET_CODE (XEXP (x, 1)) != CONST_INT
3134 || INTVAL (XEXP (x, 1)) >= 0)
3135 fprintf (file, "+");
3136 cris_output_addr_const (file, XEXP (x, 1));
3137 }
3138 break;
3139
3140 case MINUS:
3141 /* Avoid outputting things like x-x or x+5-x,
3142 since some assemblers can't handle that. */
3143 x = simplify_subtraction (x);
3144 if (GET_CODE (x) != MINUS)
3145 goto restart;
3146
3147 cris_output_addr_const (file, XEXP (x, 0));
3148 fprintf (file, "-");
3149 if ((GET_CODE (XEXP (x, 1)) == CONST_INT
3150 && INTVAL (XEXP (x, 1)) < 0)
3151 || GET_CODE (XEXP (x, 1)) != CONST_INT)
3152 {
3153 fprintf (file, "%s", targetm.asm_out.open_paren);
3154 cris_output_addr_const (file, XEXP (x, 1));
3155 fprintf (file, "%s", targetm.asm_out.close_paren);
3156 }
3157 else
3158 output_addr_const (file, XEXP (x, 1));
3159 break;
3160
3161 default:
3162 LOSE_AND_RETURN ("unexpected address expression", x);
3163 }
3164 }
3165
3166 #if 0
3167 /* Various small functions to replace macros. Only called from a
3168 debugger. They might collide with gcc functions or system functions,
3169 so only emit them when '#if 1' above. */
3170
3171 enum rtx_code Get_code (rtx);
3172
3173 enum rtx_code
3174 Get_code (rtx x)
3175 {
3176 return GET_CODE (x);
3177 }
3178
3179 const char *Get_mode (rtx);
3180
3181 const char *
3182 Get_mode (rtx x)
3183 {
3184 return GET_MODE_NAME (GET_MODE (x));
3185 }
3186
3187 rtx Xexp (rtx, int);
3188
3189 rtx
3190 Xexp (rtx x, int n)
3191 {
3192 return XEXP (x, n);
3193 }
3194
3195 rtx Xvecexp (rtx, int, int);
3196
3197 rtx
3198 Xvecexp (rtx x, int n, int m)
3199 {
3200 return XVECEXP (x, n, m);
3201 }
3202
3203 int Get_rtx_len (rtx);
3204
3205 int
3206 Get_rtx_len (rtx x)
3207 {
3208 return GET_RTX_LENGTH (GET_CODE (x));
3209 }
3210
3211 /* Use upper-case to distinguish from local variables that are sometimes
3212 called next_insn and prev_insn. */
3213
3214 rtx Next_insn (rtx);
3215
3216 rtx
3217 Next_insn (rtx insn)
3218 {
3219 return NEXT_INSN (insn);
3220 }
3221
3222 rtx Prev_insn (rtx);
3223
3224 rtx
3225 Prev_insn (rtx insn)
3226 {
3227 return PREV_INSN (insn);
3228 }
3229 #endif
3230
3231 #include "gt-cris.h"
3232
3233 /*
3234 * Local variables:
3235 * eval: (c-set-style "gnu")
3236 * indent-tabs-mode: t
3237 * End:
3238 */