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