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