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