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