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