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