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