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