[multiple changes]
[official-gcc.git] / gcc / config / rx / rx.c
blobc9720eb3e155713fe040955281ffb0998ad520a1
1 /* Subroutines used for code generation on Renesas RX processors.
2 Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3 Contributed by Red Hat.
5 This file is part of GCC.
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 3, or (at your option)
10 any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* To Do:
23 * Re-enable memory-to-memory copies and fix up reload. */
25 #include "config.h"
26 #include "system.h"
27 #include "coretypes.h"
28 #include "tm.h"
29 #include "tree.h"
30 #include "rtl.h"
31 #include "regs.h"
32 #include "hard-reg-set.h"
33 #include "insn-config.h"
34 #include "conditions.h"
35 #include "output.h"
36 #include "insn-attr.h"
37 #include "flags.h"
38 #include "function.h"
39 #include "expr.h"
40 #include "optabs.h"
41 #include "libfuncs.h"
42 #include "recog.h"
43 #include "diagnostic-core.h"
44 #include "toplev.h"
45 #include "reload.h"
46 #include "df.h"
47 #include "ggc.h"
48 #include "tm_p.h"
49 #include "debug.h"
50 #include "target.h"
51 #include "target-def.h"
52 #include "langhooks.h"
53 #include "opts.h"
55 static unsigned int rx_gp_base_regnum_val = INVALID_REGNUM;
56 static unsigned int rx_pid_base_regnum_val = INVALID_REGNUM;
57 static unsigned int rx_num_interrupt_regs;
59 static unsigned int
60 rx_gp_base_regnum (void)
62 if (rx_gp_base_regnum_val == INVALID_REGNUM)
63 gcc_unreachable ();
64 return rx_gp_base_regnum_val;
67 static unsigned int
68 rx_pid_base_regnum (void)
70 if (rx_pid_base_regnum_val == INVALID_REGNUM)
71 gcc_unreachable ();
72 return rx_pid_base_regnum_val;
75 /* Find a SYMBOL_REF in a "standard" MEM address and return its decl. */
77 static tree
78 rx_decl_for_addr (rtx op)
80 if (GET_CODE (op) == MEM)
81 op = XEXP (op, 0);
82 if (GET_CODE (op) == CONST)
83 op = XEXP (op, 0);
84 while (GET_CODE (op) == PLUS)
85 op = XEXP (op, 0);
86 if (GET_CODE (op) == SYMBOL_REF)
87 return SYMBOL_REF_DECL (op);
88 return NULL_TREE;
91 static void rx_print_operand (FILE *, rtx, int);
93 #define CC_FLAG_S (1 << 0)
94 #define CC_FLAG_Z (1 << 1)
95 #define CC_FLAG_O (1 << 2)
96 #define CC_FLAG_C (1 << 3)
97 #define CC_FLAG_FP (1 << 4) /* Fake, to differentiate CC_Fmode. */
99 static unsigned int flags_from_mode (enum machine_mode mode);
100 static unsigned int flags_from_code (enum rtx_code code);
102 /* Return true if OP is a reference to an object in a PID data area. */
104 enum pid_type
106 PID_NOT_PID = 0, /* The object is not in the PID data area. */
107 PID_ENCODED, /* The object is in the PID data area. */
108 PID_UNENCODED /* The object will be placed in the PID data area, but it has not been placed there yet. */
111 static enum pid_type
112 rx_pid_data_operand (rtx op)
114 tree op_decl;
116 if (!TARGET_PID)
117 return PID_NOT_PID;
119 if (GET_CODE (op) == PLUS
120 && GET_CODE (XEXP (op, 0)) == REG
121 && GET_CODE (XEXP (op, 1)) == CONST
122 && GET_CODE (XEXP (XEXP (op, 1), 0)) == UNSPEC)
123 return PID_ENCODED;
125 op_decl = rx_decl_for_addr (op);
127 if (op_decl)
129 if (TREE_READONLY (op_decl))
130 return PID_UNENCODED;
132 else
134 /* Sigh, some special cases. */
135 if (GET_CODE (op) == SYMBOL_REF
136 || GET_CODE (op) == LABEL_REF)
137 return PID_UNENCODED;
140 return PID_NOT_PID;
143 static rtx
144 rx_legitimize_address (rtx x,
145 rtx oldx ATTRIBUTE_UNUSED,
146 enum machine_mode mode ATTRIBUTE_UNUSED)
148 if (rx_pid_data_operand (x) == PID_UNENCODED)
150 rtx rv = gen_pid_addr (gen_rtx_REG (SImode, rx_pid_base_regnum ()), x);
151 return rv;
154 if (GET_CODE (x) == PLUS
155 && GET_CODE (XEXP (x, 0)) == PLUS
156 && REG_P (XEXP (XEXP (x, 0), 0))
157 && REG_P (XEXP (x, 1)))
158 return force_reg (SImode, x);
160 return x;
163 /* Return true if OP is a reference to an object in a small data area. */
165 static bool
166 rx_small_data_operand (rtx op)
168 if (rx_small_data_limit == 0)
169 return false;
171 if (GET_CODE (op) == SYMBOL_REF)
172 return SYMBOL_REF_SMALL_P (op);
174 return false;
177 static bool
178 rx_is_legitimate_address (enum machine_mode mode, rtx x,
179 bool strict ATTRIBUTE_UNUSED)
181 if (RTX_OK_FOR_BASE (x, strict))
182 /* Register Indirect. */
183 return true;
185 if ((GET_MODE_SIZE (mode) == 4
186 || GET_MODE_SIZE (mode) == 2
187 || GET_MODE_SIZE (mode) == 1)
188 && (GET_CODE (x) == PRE_DEC || GET_CODE (x) == POST_INC))
189 /* Pre-decrement Register Indirect or
190 Post-increment Register Indirect. */
191 return RTX_OK_FOR_BASE (XEXP (x, 0), strict);
193 switch (rx_pid_data_operand (x))
195 case PID_UNENCODED:
196 return false;
197 case PID_ENCODED:
198 return true;
199 default:
200 break;
203 if (GET_CODE (x) == PLUS)
205 rtx arg1 = XEXP (x, 0);
206 rtx arg2 = XEXP (x, 1);
207 rtx index = NULL_RTX;
209 if (REG_P (arg1) && RTX_OK_FOR_BASE (arg1, strict))
210 index = arg2;
211 else if (REG_P (arg2) && RTX_OK_FOR_BASE (arg2, strict))
212 index = arg1;
213 else
214 return false;
216 switch (GET_CODE (index))
218 case CONST_INT:
220 /* Register Relative: REG + INT.
221 Only positive, mode-aligned, mode-sized
222 displacements are allowed. */
223 HOST_WIDE_INT val = INTVAL (index);
224 int factor;
226 if (val < 0)
227 return false;
229 switch (GET_MODE_SIZE (mode))
231 default:
232 case 4: factor = 4; break;
233 case 2: factor = 2; break;
234 case 1: factor = 1; break;
237 if (val > (65535 * factor))
238 return false;
239 return (val % factor) == 0;
242 case REG:
243 /* Unscaled Indexed Register Indirect: REG + REG
244 Size has to be "QI", REG has to be valid. */
245 return GET_MODE_SIZE (mode) == 1 && RTX_OK_FOR_BASE (index, strict);
247 case MULT:
249 /* Scaled Indexed Register Indirect: REG + (REG * FACTOR)
250 Factor has to equal the mode size, REG has to be valid. */
251 rtx factor;
253 factor = XEXP (index, 1);
254 index = XEXP (index, 0);
256 return REG_P (index)
257 && RTX_OK_FOR_BASE (index, strict)
258 && CONST_INT_P (factor)
259 && GET_MODE_SIZE (mode) == INTVAL (factor);
262 default:
263 return false;
267 /* Small data area accesses turn into register relative offsets. */
268 return rx_small_data_operand (x);
271 /* Returns TRUE for simple memory addreses, ie ones
272 that do not involve register indirect addressing
273 or pre/post increment/decrement. */
275 bool
276 rx_is_restricted_memory_address (rtx mem, enum machine_mode mode)
278 if (! rx_is_legitimate_address
279 (mode, mem, reload_in_progress || reload_completed))
280 return false;
282 switch (GET_CODE (mem))
284 case REG:
285 /* Simple memory addresses are OK. */
286 return true;
288 case PRE_DEC:
289 case POST_INC:
290 return false;
292 case PLUS:
294 rtx base, index;
296 /* Only allow REG+INT addressing. */
297 base = XEXP (mem, 0);
298 index = XEXP (mem, 1);
300 if (! RX_REG_P (base) || ! CONST_INT_P (index))
301 return false;
303 return IN_RANGE (INTVAL (index), 0, (0x10000 * GET_MODE_SIZE (mode)) - 1);
306 case SYMBOL_REF:
307 /* Can happen when small data is being supported.
308 Assume that it will be resolved into GP+INT. */
309 return true;
311 default:
312 gcc_unreachable ();
316 /* Implement TARGET_MODE_DEPENDENT_ADDRESS_P. */
318 static bool
319 rx_mode_dependent_address_p (const_rtx addr)
321 if (GET_CODE (addr) == CONST)
322 addr = XEXP (addr, 0);
324 switch (GET_CODE (addr))
326 /* --REG and REG++ only work in SImode. */
327 case PRE_DEC:
328 case POST_INC:
329 return true;
331 case MINUS:
332 case PLUS:
333 if (! REG_P (XEXP (addr, 0)))
334 return true;
336 addr = XEXP (addr, 1);
338 switch (GET_CODE (addr))
340 case REG:
341 /* REG+REG only works in SImode. */
342 return true;
344 case CONST_INT:
345 /* REG+INT is only mode independent if INT is a
346 multiple of 4, positive and will fit into 8-bits. */
347 if (((INTVAL (addr) & 3) == 0)
348 && IN_RANGE (INTVAL (addr), 4, 252))
349 return false;
350 return true;
352 case SYMBOL_REF:
353 case LABEL_REF:
354 return true;
356 case MULT:
357 gcc_assert (REG_P (XEXP (addr, 0)));
358 gcc_assert (CONST_INT_P (XEXP (addr, 1)));
359 /* REG+REG*SCALE is always mode dependent. */
360 return true;
362 default:
363 /* Not recognized, so treat as mode dependent. */
364 return true;
367 case CONST_INT:
368 case SYMBOL_REF:
369 case LABEL_REF:
370 case REG:
371 /* These are all mode independent. */
372 return false;
374 default:
375 /* Everything else is unrecognized,
376 so treat as mode dependent. */
377 return true;
381 /* A C compound statement to output to stdio stream FILE the
382 assembler syntax for an instruction operand that is a memory
383 reference whose address is ADDR. */
385 static void
386 rx_print_operand_address (FILE * file, rtx addr)
388 switch (GET_CODE (addr))
390 case REG:
391 fprintf (file, "[");
392 rx_print_operand (file, addr, 0);
393 fprintf (file, "]");
394 break;
396 case PRE_DEC:
397 fprintf (file, "[-");
398 rx_print_operand (file, XEXP (addr, 0), 0);
399 fprintf (file, "]");
400 break;
402 case POST_INC:
403 fprintf (file, "[");
404 rx_print_operand (file, XEXP (addr, 0), 0);
405 fprintf (file, "+]");
406 break;
408 case PLUS:
410 rtx arg1 = XEXP (addr, 0);
411 rtx arg2 = XEXP (addr, 1);
412 rtx base, index;
414 if (REG_P (arg1) && RTX_OK_FOR_BASE (arg1, true))
415 base = arg1, index = arg2;
416 else if (REG_P (arg2) && RTX_OK_FOR_BASE (arg2, true))
417 base = arg2, index = arg1;
418 else
420 rx_print_operand (file, arg1, 0);
421 fprintf (file, " + ");
422 rx_print_operand (file, arg2, 0);
423 break;
426 if (REG_P (index) || GET_CODE (index) == MULT)
428 fprintf (file, "[");
429 rx_print_operand (file, index, 'A');
430 fprintf (file, ",");
432 else /* GET_CODE (index) == CONST_INT */
434 rx_print_operand (file, index, 'A');
435 fprintf (file, "[");
437 rx_print_operand (file, base, 0);
438 fprintf (file, "]");
439 break;
442 case CONST:
443 if (GET_CODE (XEXP (addr, 0)) == UNSPEC)
445 addr = XEXP (addr, 0);
446 gcc_assert (XINT (addr, 1) == UNSPEC_CONST);
448 /* FIXME: Putting this case label here is an appalling abuse of the C language. */
449 case UNSPEC:
450 addr = XVECEXP (addr, 0, 0);
451 gcc_assert (CONST_INT_P (addr));
453 /* Fall through. */
454 case LABEL_REF:
455 case SYMBOL_REF:
456 fprintf (file, "#");
457 /* Fall through. */
458 default:
459 output_addr_const (file, addr);
460 break;
464 static void
465 rx_print_integer (FILE * file, HOST_WIDE_INT val)
467 if (IN_RANGE (val, -64, 64))
468 fprintf (file, HOST_WIDE_INT_PRINT_DEC, val);
469 else
470 fprintf (file,
471 TARGET_AS100_SYNTAX
472 ? "0%" HOST_WIDE_INT_PRINT "xH" : HOST_WIDE_INT_PRINT_HEX,
473 val);
476 static bool
477 rx_assemble_integer (rtx x, unsigned int size, int is_aligned)
479 const char * op = integer_asm_op (size, is_aligned);
481 if (! CONST_INT_P (x))
482 return default_assemble_integer (x, size, is_aligned);
484 if (op == NULL)
485 return false;
486 fputs (op, asm_out_file);
488 rx_print_integer (asm_out_file, INTVAL (x));
489 fputc ('\n', asm_out_file);
490 return true;
494 /* Handles the insertion of a single operand into the assembler output.
495 The %<letter> directives supported are:
497 %A Print an operand without a leading # character.
498 %B Print an integer comparison name.
499 %C Print a control register name.
500 %F Print a condition code flag name.
501 %G Register used for small-data-area addressing
502 %H Print high part of a DImode register, integer or address.
503 %L Print low part of a DImode register, integer or address.
504 %N Print the negation of the immediate value.
505 %P Register used for PID addressing
506 %Q If the operand is a MEM, then correctly generate
507 register indirect or register relative addressing.
508 %R Like %Q but for zero-extending loads. */
510 static void
511 rx_print_operand (FILE * file, rtx op, int letter)
513 bool unsigned_load = false;
514 bool print_hash = true;
516 if (letter == 'A'
517 && ((GET_CODE (op) == CONST
518 && GET_CODE (XEXP (op, 0)) == UNSPEC)
519 || GET_CODE (op) == UNSPEC))
521 print_hash = false;
522 letter = 0;
525 switch (letter)
527 case 'A':
528 /* Print an operand without a leading #. */
529 if (MEM_P (op))
530 op = XEXP (op, 0);
532 switch (GET_CODE (op))
534 case LABEL_REF:
535 case SYMBOL_REF:
536 output_addr_const (file, op);
537 break;
538 case CONST_INT:
539 fprintf (file, "%ld", (long) INTVAL (op));
540 break;
541 default:
542 rx_print_operand (file, op, 0);
543 break;
545 break;
547 case 'B':
549 enum rtx_code code = GET_CODE (op);
550 enum machine_mode mode = GET_MODE (XEXP (op, 0));
551 const char *ret;
553 if (mode == CC_Fmode)
555 /* C flag is undefined, and O flag carries unordered. None of the
556 branch combinations that include O use it helpfully. */
557 switch (code)
559 case ORDERED:
560 ret = "no";
561 break;
562 case UNORDERED:
563 ret = "o";
564 break;
565 case LT:
566 ret = "n";
567 break;
568 case GE:
569 ret = "pz";
570 break;
571 case EQ:
572 ret = "eq";
573 break;
574 case NE:
575 ret = "ne";
576 break;
577 default:
578 gcc_unreachable ();
581 else
583 unsigned int flags = flags_from_mode (mode);
585 switch (code)
587 case LT:
588 ret = (flags & CC_FLAG_O ? "lt" : "n");
589 break;
590 case GE:
591 ret = (flags & CC_FLAG_O ? "ge" : "pz");
592 break;
593 case GT:
594 ret = "gt";
595 break;
596 case LE:
597 ret = "le";
598 break;
599 case GEU:
600 ret = "geu";
601 break;
602 case LTU:
603 ret = "ltu";
604 break;
605 case GTU:
606 ret = "gtu";
607 break;
608 case LEU:
609 ret = "leu";
610 break;
611 case EQ:
612 ret = "eq";
613 break;
614 case NE:
615 ret = "ne";
616 break;
617 default:
618 gcc_unreachable ();
620 gcc_checking_assert ((flags_from_code (code) & ~flags) == 0);
622 fputs (ret, file);
623 break;
626 case 'C':
627 gcc_assert (CONST_INT_P (op));
628 switch (INTVAL (op))
630 case 0: fprintf (file, "psw"); break;
631 case 2: fprintf (file, "usp"); break;
632 case 3: fprintf (file, "fpsw"); break;
633 case 4: fprintf (file, "cpen"); break;
634 case 8: fprintf (file, "bpsw"); break;
635 case 9: fprintf (file, "bpc"); break;
636 case 0xa: fprintf (file, "isp"); break;
637 case 0xb: fprintf (file, "fintv"); break;
638 case 0xc: fprintf (file, "intb"); break;
639 default:
640 warning (0, "unrecognized control register number: %d - using 'psw'",
641 (int) INTVAL (op));
642 fprintf (file, "psw");
643 break;
645 break;
647 case 'F':
648 gcc_assert (CONST_INT_P (op));
649 switch (INTVAL (op))
651 case 0: case 'c': case 'C': fprintf (file, "C"); break;
652 case 1: case 'z': case 'Z': fprintf (file, "Z"); break;
653 case 2: case 's': case 'S': fprintf (file, "S"); break;
654 case 3: case 'o': case 'O': fprintf (file, "O"); break;
655 case 8: case 'i': case 'I': fprintf (file, "I"); break;
656 case 9: case 'u': case 'U': fprintf (file, "U"); break;
657 default:
658 gcc_unreachable ();
660 break;
662 case 'G':
663 fprintf (file, "%s", reg_names [rx_gp_base_regnum ()]);
664 break;
666 case 'H':
667 switch (GET_CODE (op))
669 case REG:
670 fprintf (file, "%s", reg_names [REGNO (op) + (WORDS_BIG_ENDIAN ? 0 : 1)]);
671 break;
672 case CONST_INT:
674 HOST_WIDE_INT v = INTVAL (op);
676 fprintf (file, "#");
677 /* Trickery to avoid problems with shifting 32 bits at a time. */
678 v = v >> 16;
679 v = v >> 16;
680 rx_print_integer (file, v);
681 break;
683 case CONST_DOUBLE:
684 fprintf (file, "#");
685 rx_print_integer (file, CONST_DOUBLE_HIGH (op));
686 break;
687 case MEM:
688 if (! WORDS_BIG_ENDIAN)
689 op = adjust_address (op, SImode, 4);
690 output_address (XEXP (op, 0));
691 break;
692 default:
693 gcc_unreachable ();
695 break;
697 case 'L':
698 switch (GET_CODE (op))
700 case REG:
701 fprintf (file, "%s", reg_names [REGNO (op) + (WORDS_BIG_ENDIAN ? 1 : 0)]);
702 break;
703 case CONST_INT:
704 fprintf (file, "#");
705 rx_print_integer (file, INTVAL (op) & 0xffffffff);
706 break;
707 case CONST_DOUBLE:
708 fprintf (file, "#");
709 rx_print_integer (file, CONST_DOUBLE_LOW (op));
710 break;
711 case MEM:
712 if (WORDS_BIG_ENDIAN)
713 op = adjust_address (op, SImode, 4);
714 output_address (XEXP (op, 0));
715 break;
716 default:
717 gcc_unreachable ();
719 break;
721 case 'N':
722 gcc_assert (CONST_INT_P (op));
723 fprintf (file, "#");
724 rx_print_integer (file, - INTVAL (op));
725 break;
727 case 'P':
728 fprintf (file, "%s", reg_names [rx_pid_base_regnum ()]);
729 break;
731 case 'R':
732 gcc_assert (GET_MODE_SIZE (GET_MODE (op)) < 4);
733 unsigned_load = true;
734 /* Fall through. */
735 case 'Q':
736 if (MEM_P (op))
738 HOST_WIDE_INT offset;
739 rtx mem = op;
741 op = XEXP (op, 0);
743 if (REG_P (op))
744 offset = 0;
745 else if (GET_CODE (op) == PLUS)
747 rtx displacement;
749 if (REG_P (XEXP (op, 0)))
751 displacement = XEXP (op, 1);
752 op = XEXP (op, 0);
754 else
756 displacement = XEXP (op, 0);
757 op = XEXP (op, 1);
758 gcc_assert (REG_P (op));
761 gcc_assert (CONST_INT_P (displacement));
762 offset = INTVAL (displacement);
763 gcc_assert (offset >= 0);
765 fprintf (file, "%ld", offset);
767 else
768 gcc_unreachable ();
770 fprintf (file, "[");
771 rx_print_operand (file, op, 0);
772 fprintf (file, "].");
774 switch (GET_MODE_SIZE (GET_MODE (mem)))
776 case 1:
777 gcc_assert (offset <= 65535 * 1);
778 fprintf (file, unsigned_load ? "UB" : "B");
779 break;
780 case 2:
781 gcc_assert (offset % 2 == 0);
782 gcc_assert (offset <= 65535 * 2);
783 fprintf (file, unsigned_load ? "UW" : "W");
784 break;
785 case 4:
786 gcc_assert (offset % 4 == 0);
787 gcc_assert (offset <= 65535 * 4);
788 fprintf (file, "L");
789 break;
790 default:
791 gcc_unreachable ();
793 break;
796 /* Fall through. */
798 default:
799 if (GET_CODE (op) == CONST
800 && GET_CODE (XEXP (op, 0)) == UNSPEC)
801 op = XEXP (op, 0);
802 else if (GET_CODE (op) == CONST
803 && GET_CODE (XEXP (op, 0)) == PLUS
804 && GET_CODE (XEXP (XEXP (op, 0), 0)) == UNSPEC
805 && GET_CODE (XEXP (XEXP (op, 0), 1)) == CONST_INT)
807 if (print_hash)
808 fprintf (file, "#");
809 fprintf (file, "(");
810 rx_print_operand (file, XEXP (XEXP (op, 0), 0), 'A');
811 fprintf (file, " + ");
812 output_addr_const (file, XEXP (XEXP (op, 0), 1));
813 fprintf (file, ")");
814 return;
817 switch (GET_CODE (op))
819 case MULT:
820 /* Should be the scaled part of an
821 indexed register indirect address. */
823 rtx base = XEXP (op, 0);
824 rtx index = XEXP (op, 1);
826 /* Check for a swaped index register and scaling factor.
827 Not sure if this can happen, but be prepared to handle it. */
828 if (CONST_INT_P (base) && REG_P (index))
830 rtx tmp = base;
831 base = index;
832 index = tmp;
835 gcc_assert (REG_P (base));
836 gcc_assert (REGNO (base) < FIRST_PSEUDO_REGISTER);
837 gcc_assert (CONST_INT_P (index));
838 /* Do not try to verify the value of the scalar as it is based
839 on the mode of the MEM not the mode of the MULT. (Which
840 will always be SImode). */
841 fprintf (file, "%s", reg_names [REGNO (base)]);
842 break;
845 case MEM:
846 output_address (XEXP (op, 0));
847 break;
849 case PLUS:
850 output_address (op);
851 break;
853 case REG:
854 gcc_assert (REGNO (op) < FIRST_PSEUDO_REGISTER);
855 fprintf (file, "%s", reg_names [REGNO (op)]);
856 break;
858 case SUBREG:
859 gcc_assert (subreg_regno (op) < FIRST_PSEUDO_REGISTER);
860 fprintf (file, "%s", reg_names [subreg_regno (op)]);
861 break;
863 /* This will only be single precision.... */
864 case CONST_DOUBLE:
866 unsigned long val;
867 REAL_VALUE_TYPE rv;
869 REAL_VALUE_FROM_CONST_DOUBLE (rv, op);
870 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
871 if (print_hash)
872 fprintf (file, "#");
873 fprintf (file, TARGET_AS100_SYNTAX ? "0%lxH" : "0x%lx", val);
874 break;
877 case CONST_INT:
878 if (print_hash)
879 fprintf (file, "#");
880 rx_print_integer (file, INTVAL (op));
881 break;
883 case UNSPEC:
884 switch (XINT (op, 1))
886 case UNSPEC_PID_ADDR:
888 rtx sym, add;
890 if (print_hash)
891 fprintf (file, "#");
892 sym = XVECEXP (op, 0, 0);
893 add = NULL_RTX;
894 fprintf (file, "(");
895 if (GET_CODE (sym) == PLUS)
897 add = XEXP (sym, 1);
898 sym = XEXP (sym, 0);
900 output_addr_const (file, sym);
901 if (add != NULL_RTX)
903 fprintf (file, "+");
904 output_addr_const (file, add);
906 fprintf (file, "-__pid_base");
907 fprintf (file, ")");
908 return;
911 /* Fall through */
913 case CONST:
914 case SYMBOL_REF:
915 case LABEL_REF:
916 case CODE_LABEL:
917 rx_print_operand_address (file, op);
918 break;
920 default:
921 gcc_unreachable ();
923 break;
927 /* Maybe convert an operand into its PID format. */
930 rx_maybe_pidify_operand (rtx op, int copy_to_reg)
932 if (rx_pid_data_operand (op) == PID_UNENCODED)
934 if (GET_CODE (op) == MEM)
936 rtx a = gen_pid_addr (gen_rtx_REG (SImode, rx_pid_base_regnum ()), XEXP (op, 0));
937 op = replace_equiv_address (op, a);
939 else
941 op = gen_pid_addr (gen_rtx_REG (SImode, rx_pid_base_regnum ()), op);
944 if (copy_to_reg)
945 op = copy_to_mode_reg (GET_MODE (op), op);
947 return op;
950 /* Returns an assembler template for a move instruction. */
952 char *
953 rx_gen_move_template (rtx * operands, bool is_movu)
955 static char out_template [64];
956 const char * extension = TARGET_AS100_SYNTAX ? ".L" : "";
957 const char * src_template;
958 const char * dst_template;
959 rtx dest = operands[0];
960 rtx src = operands[1];
962 /* Decide which extension, if any, should be given to the move instruction. */
963 switch (CONST_INT_P (src) ? GET_MODE (dest) : GET_MODE (src))
965 case QImode:
966 /* The .B extension is not valid when
967 loading an immediate into a register. */
968 if (! REG_P (dest) || ! CONST_INT_P (src))
969 extension = ".B";
970 break;
971 case HImode:
972 if (! REG_P (dest) || ! CONST_INT_P (src))
973 /* The .W extension is not valid when
974 loading an immediate into a register. */
975 extension = ".W";
976 break;
977 case SFmode:
978 case SImode:
979 extension = ".L";
980 break;
981 case VOIDmode:
982 /* This mode is used by constants. */
983 break;
984 default:
985 debug_rtx (src);
986 gcc_unreachable ();
989 if (MEM_P (src) && rx_pid_data_operand (XEXP (src, 0)) == PID_UNENCODED)
990 src_template = "(%A1-__pid_base)[%P1]";
991 else if (MEM_P (src) && rx_small_data_operand (XEXP (src, 0)))
992 src_template = "%%gp(%A1)[%G1]";
993 else
994 src_template = "%1";
996 if (MEM_P (dest) && rx_small_data_operand (XEXP (dest, 0)))
997 dst_template = "%%gp(%A0)[%G0]";
998 else
999 dst_template = "%0";
1001 sprintf (out_template, "%s%s\t%s, %s", is_movu ? "movu" : "mov",
1002 extension, src_template, dst_template);
1003 return out_template;
1006 /* Return VALUE rounded up to the next ALIGNMENT boundary. */
1008 static inline unsigned int
1009 rx_round_up (unsigned int value, unsigned int alignment)
1011 alignment -= 1;
1012 return (value + alignment) & (~ alignment);
1015 /* Return the number of bytes in the argument registers
1016 occupied by an argument of type TYPE and mode MODE. */
1018 static unsigned int
1019 rx_function_arg_size (enum machine_mode mode, const_tree type)
1021 unsigned int num_bytes;
1023 num_bytes = (mode == BLKmode)
1024 ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
1025 return rx_round_up (num_bytes, UNITS_PER_WORD);
1028 #define NUM_ARG_REGS 4
1029 #define MAX_NUM_ARG_BYTES (NUM_ARG_REGS * UNITS_PER_WORD)
1031 /* Return an RTL expression describing the register holding a function
1032 parameter of mode MODE and type TYPE or NULL_RTX if the parameter should
1033 be passed on the stack. CUM describes the previous parameters to the
1034 function and NAMED is false if the parameter is part of a variable
1035 parameter list, or the last named parameter before the start of a
1036 variable parameter list. */
1038 static rtx
1039 rx_function_arg (cumulative_args_t cum, enum machine_mode mode,
1040 const_tree type, bool named)
1042 unsigned int next_reg;
1043 unsigned int bytes_so_far = *get_cumulative_args (cum);
1044 unsigned int size;
1045 unsigned int rounded_size;
1047 /* An exploded version of rx_function_arg_size. */
1048 size = (mode == BLKmode) ? int_size_in_bytes (type) : GET_MODE_SIZE (mode);
1049 /* If the size is not known it cannot be passed in registers. */
1050 if (size < 1)
1051 return NULL_RTX;
1053 rounded_size = rx_round_up (size, UNITS_PER_WORD);
1055 /* Don't pass this arg via registers if there
1056 are insufficient registers to hold all of it. */
1057 if (rounded_size + bytes_so_far > MAX_NUM_ARG_BYTES)
1058 return NULL_RTX;
1060 /* Unnamed arguments and the last named argument in a
1061 variadic function are always passed on the stack. */
1062 if (!named)
1063 return NULL_RTX;
1065 /* Structures must occupy an exact number of registers,
1066 otherwise they are passed on the stack. */
1067 if ((type == NULL || AGGREGATE_TYPE_P (type))
1068 && (size % UNITS_PER_WORD) != 0)
1069 return NULL_RTX;
1071 next_reg = (bytes_so_far / UNITS_PER_WORD) + 1;
1073 return gen_rtx_REG (mode, next_reg);
1076 static void
1077 rx_function_arg_advance (cumulative_args_t cum, enum machine_mode mode,
1078 const_tree type, bool named ATTRIBUTE_UNUSED)
1080 *get_cumulative_args (cum) += rx_function_arg_size (mode, type);
1083 static unsigned int
1084 rx_function_arg_boundary (enum machine_mode mode ATTRIBUTE_UNUSED,
1085 const_tree type ATTRIBUTE_UNUSED)
1087 return 32;
1090 /* Return an RTL describing where a function return value of type RET_TYPE
1091 is held. */
1093 static rtx
1094 rx_function_value (const_tree ret_type,
1095 const_tree fn_decl_or_type ATTRIBUTE_UNUSED,
1096 bool outgoing ATTRIBUTE_UNUSED)
1098 enum machine_mode mode = TYPE_MODE (ret_type);
1100 /* RX ABI specifies that small integer types are
1101 promoted to int when returned by a function. */
1102 if (GET_MODE_SIZE (mode) > 0
1103 && GET_MODE_SIZE (mode) < 4
1104 && ! COMPLEX_MODE_P (mode)
1106 return gen_rtx_REG (SImode, FUNC_RETURN_REGNUM);
1108 return gen_rtx_REG (mode, FUNC_RETURN_REGNUM);
1111 /* TARGET_PROMOTE_FUNCTION_MODE must behave in the same way with
1112 regard to function returns as does TARGET_FUNCTION_VALUE. */
1114 static enum machine_mode
1115 rx_promote_function_mode (const_tree type ATTRIBUTE_UNUSED,
1116 enum machine_mode mode,
1117 int * punsignedp ATTRIBUTE_UNUSED,
1118 const_tree funtype ATTRIBUTE_UNUSED,
1119 int for_return)
1121 if (for_return != 1
1122 || GET_MODE_SIZE (mode) >= 4
1123 || COMPLEX_MODE_P (mode)
1124 || GET_MODE_SIZE (mode) < 1)
1125 return mode;
1127 return SImode;
1130 static bool
1131 rx_return_in_memory (const_tree type, const_tree fntype ATTRIBUTE_UNUSED)
1133 HOST_WIDE_INT size;
1135 if (TYPE_MODE (type) != BLKmode
1136 && ! AGGREGATE_TYPE_P (type))
1137 return false;
1139 size = int_size_in_bytes (type);
1140 /* Large structs and those whose size is not an
1141 exact multiple of 4 are returned in memory. */
1142 return size < 1
1143 || size > 16
1144 || (size % UNITS_PER_WORD) != 0;
1147 static rtx
1148 rx_struct_value_rtx (tree fndecl ATTRIBUTE_UNUSED,
1149 int incoming ATTRIBUTE_UNUSED)
1151 return gen_rtx_REG (Pmode, STRUCT_VAL_REGNUM);
1154 static bool
1155 rx_return_in_msb (const_tree valtype)
1157 return TARGET_BIG_ENDIAN_DATA
1158 && (AGGREGATE_TYPE_P (valtype) || TREE_CODE (valtype) == COMPLEX_TYPE);
1161 /* Returns true if the provided function has the specified attribute. */
1163 static inline bool
1164 has_func_attr (const_tree decl, const char * func_attr)
1166 if (decl == NULL_TREE)
1167 decl = current_function_decl;
1169 return lookup_attribute (func_attr, DECL_ATTRIBUTES (decl)) != NULL_TREE;
1172 /* Returns true if the provided function has the "fast_interrupt" attribute. */
1174 static inline bool
1175 is_fast_interrupt_func (const_tree decl)
1177 return has_func_attr (decl, "fast_interrupt");
1180 /* Returns true if the provided function has the "interrupt" attribute. */
1182 static inline bool
1183 is_interrupt_func (const_tree decl)
1185 return has_func_attr (decl, "interrupt");
1188 /* Returns true if the provided function has the "naked" attribute. */
1190 static inline bool
1191 is_naked_func (const_tree decl)
1193 return has_func_attr (decl, "naked");
1196 static bool use_fixed_regs = false;
1198 static void
1199 rx_conditional_register_usage (void)
1201 static bool using_fixed_regs = false;
1203 if (TARGET_PID)
1205 rx_pid_base_regnum_val = GP_BASE_REGNUM - rx_num_interrupt_regs;
1206 fixed_regs[rx_pid_base_regnum_val] = call_used_regs [rx_pid_base_regnum_val] = 1;
1209 if (rx_small_data_limit > 0)
1211 if (TARGET_PID)
1212 rx_gp_base_regnum_val = rx_pid_base_regnum_val - 1;
1213 else
1214 rx_gp_base_regnum_val = GP_BASE_REGNUM - rx_num_interrupt_regs;
1216 fixed_regs[rx_gp_base_regnum_val] = call_used_regs [rx_gp_base_regnum_val] = 1;
1219 if (use_fixed_regs != using_fixed_regs)
1221 static char saved_fixed_regs[FIRST_PSEUDO_REGISTER];
1222 static char saved_call_used_regs[FIRST_PSEUDO_REGISTER];
1224 if (use_fixed_regs)
1226 unsigned int r;
1228 memcpy (saved_fixed_regs, fixed_regs, sizeof fixed_regs);
1229 memcpy (saved_call_used_regs, call_used_regs, sizeof call_used_regs);
1231 /* This is for fast interrupt handlers. Any register in
1232 the range r10 to r13 (inclusive) that is currently
1233 marked as fixed is now a viable, call-used register. */
1234 for (r = 10; r <= 13; r++)
1235 if (fixed_regs[r])
1237 fixed_regs[r] = 0;
1238 call_used_regs[r] = 1;
1241 /* Mark r7 as fixed. This is just a hack to avoid
1242 altering the reg_alloc_order array so that the newly
1243 freed r10-r13 registers are the preferred registers. */
1244 fixed_regs[7] = call_used_regs[7] = 1;
1246 else
1248 /* Restore the normal register masks. */
1249 memcpy (fixed_regs, saved_fixed_regs, sizeof fixed_regs);
1250 memcpy (call_used_regs, saved_call_used_regs, sizeof call_used_regs);
1253 using_fixed_regs = use_fixed_regs;
1257 /* Perform any actions necessary before starting to compile FNDECL.
1258 For the RX we use this to make sure that we have the correct
1259 set of register masks selected. If FNDECL is NULL then we are
1260 compiling top level things. */
1262 static void
1263 rx_set_current_function (tree fndecl)
1265 /* Remember the last target of rx_set_current_function. */
1266 static tree rx_previous_fndecl;
1267 bool prev_was_fast_interrupt;
1268 bool current_is_fast_interrupt;
1270 /* Only change the context if the function changes. This hook is called
1271 several times in the course of compiling a function, and we don't want
1272 to slow things down too much or call target_reinit when it isn't safe. */
1273 if (fndecl == rx_previous_fndecl)
1274 return;
1276 prev_was_fast_interrupt
1277 = rx_previous_fndecl
1278 ? is_fast_interrupt_func (rx_previous_fndecl) : false;
1280 current_is_fast_interrupt
1281 = fndecl ? is_fast_interrupt_func (fndecl) : false;
1283 if (prev_was_fast_interrupt != current_is_fast_interrupt)
1285 use_fixed_regs = current_is_fast_interrupt;
1286 target_reinit ();
1289 rx_previous_fndecl = fndecl;
1292 /* Typical stack layout should looks like this after the function's prologue:
1295 -- ^
1296 | | \ |
1297 | | arguments saved | Increasing
1298 | | on the stack | addresses
1299 PARENT arg pointer -> | | /
1300 -------------------------- ---- -------------------
1301 CHILD |ret | return address
1303 | | \
1304 | | call saved
1305 | | registers
1306 | | /
1308 | | \
1309 | | local
1310 | | variables
1311 frame pointer -> | | /
1313 | | \
1314 | | outgoing | Decreasing
1315 | | arguments | addresses
1316 current stack pointer -> | | / |
1317 -------------------------- ---- ------------------ V
1318 | | */
1320 static unsigned int
1321 bit_count (unsigned int x)
1323 const unsigned int m1 = 0x55555555;
1324 const unsigned int m2 = 0x33333333;
1325 const unsigned int m4 = 0x0f0f0f0f;
1327 x -= (x >> 1) & m1;
1328 x = (x & m2) + ((x >> 2) & m2);
1329 x = (x + (x >> 4)) & m4;
1330 x += x >> 8;
1332 return (x + (x >> 16)) & 0x3f;
1335 #define MUST_SAVE_ACC_REGISTER \
1336 (TARGET_SAVE_ACC_REGISTER \
1337 && (is_interrupt_func (NULL_TREE) \
1338 || is_fast_interrupt_func (NULL_TREE)))
1340 /* Returns either the lowest numbered and highest numbered registers that
1341 occupy the call-saved area of the stack frame, if the registers are
1342 stored as a contiguous block, or else a bitmask of the individual
1343 registers if they are stored piecemeal.
1345 Also computes the size of the frame and the size of the outgoing
1346 arguments block (in bytes). */
1348 static void
1349 rx_get_stack_layout (unsigned int * lowest,
1350 unsigned int * highest,
1351 unsigned int * register_mask,
1352 unsigned int * frame_size,
1353 unsigned int * stack_size)
1355 unsigned int reg;
1356 unsigned int low;
1357 unsigned int high;
1358 unsigned int fixed_reg = 0;
1359 unsigned int save_mask;
1360 unsigned int pushed_mask;
1361 unsigned int unneeded_pushes;
1363 if (is_naked_func (NULL_TREE))
1365 /* Naked functions do not create their own stack frame.
1366 Instead the programmer must do that for us. */
1367 * lowest = 0;
1368 * highest = 0;
1369 * register_mask = 0;
1370 * frame_size = 0;
1371 * stack_size = 0;
1372 return;
1375 for (save_mask = high = low = 0, reg = 1; reg < CC_REGNUM; reg++)
1377 if ((df_regs_ever_live_p (reg)
1378 /* Always save all call clobbered registers inside non-leaf
1379 interrupt handlers, even if they are not live - they may
1380 be used in (non-interrupt aware) routines called from this one. */
1381 || (call_used_regs[reg]
1382 && is_interrupt_func (NULL_TREE)
1383 && ! current_function_is_leaf))
1384 && (! call_used_regs[reg]
1385 /* Even call clobbered registered must
1386 be pushed inside interrupt handlers. */
1387 || is_interrupt_func (NULL_TREE)
1388 /* Likewise for fast interrupt handlers, except registers r10 -
1389 r13. These are normally call-saved, but may have been set
1390 to call-used by rx_conditional_register_usage. If so then
1391 they can be used in the fast interrupt handler without
1392 saving them on the stack. */
1393 || (is_fast_interrupt_func (NULL_TREE)
1394 && ! IN_RANGE (reg, 10, 13))))
1396 if (low == 0)
1397 low = reg;
1398 high = reg;
1400 save_mask |= 1 << reg;
1403 /* Remember if we see a fixed register
1404 after having found the low register. */
1405 if (low != 0 && fixed_reg == 0 && fixed_regs [reg])
1406 fixed_reg = reg;
1409 /* If we have to save the accumulator register, make sure
1410 that at least two registers are pushed into the frame. */
1411 if (MUST_SAVE_ACC_REGISTER
1412 && bit_count (save_mask) < 2)
1414 save_mask |= (1 << 13) | (1 << 14);
1415 if (low == 0)
1416 low = 13;
1417 if (high == 0 || low == high)
1418 high = low + 1;
1421 /* Decide if it would be faster fill in the call-saved area of the stack
1422 frame using multiple PUSH instructions instead of a single PUSHM
1423 instruction.
1425 SAVE_MASK is a bitmask of the registers that must be stored in the
1426 call-save area. PUSHED_MASK is a bitmask of the registers that would
1427 be pushed into the area if we used a PUSHM instruction. UNNEEDED_PUSHES
1428 is a bitmask of those registers in pushed_mask that are not in
1429 save_mask.
1431 We use a simple heuristic that says that it is better to use
1432 multiple PUSH instructions if the number of unnecessary pushes is
1433 greater than the number of necessary pushes.
1435 We also use multiple PUSH instructions if there are any fixed registers
1436 between LOW and HIGH. The only way that this can happen is if the user
1437 has specified --fixed-<reg-name> on the command line and in such
1438 circumstances we do not want to touch the fixed registers at all.
1440 FIXME: Is it worth improving this heuristic ? */
1441 pushed_mask = (-1 << low) & ~(-1 << (high + 1));
1442 unneeded_pushes = (pushed_mask & (~ save_mask)) & pushed_mask;
1444 if ((fixed_reg && fixed_reg <= high)
1445 || (optimize_function_for_speed_p (cfun)
1446 && bit_count (save_mask) < bit_count (unneeded_pushes)))
1448 /* Use multiple pushes. */
1449 * lowest = 0;
1450 * highest = 0;
1451 * register_mask = save_mask;
1453 else
1455 /* Use one push multiple instruction. */
1456 * lowest = low;
1457 * highest = high;
1458 * register_mask = 0;
1461 * frame_size = rx_round_up
1462 (get_frame_size (), STACK_BOUNDARY / BITS_PER_UNIT);
1464 if (crtl->args.size > 0)
1465 * frame_size += rx_round_up
1466 (crtl->args.size, STACK_BOUNDARY / BITS_PER_UNIT);
1468 * stack_size = rx_round_up
1469 (crtl->outgoing_args_size, STACK_BOUNDARY / BITS_PER_UNIT);
1472 /* Generate a PUSHM instruction that matches the given operands. */
1474 void
1475 rx_emit_stack_pushm (rtx * operands)
1477 HOST_WIDE_INT last_reg;
1478 rtx first_push;
1480 gcc_assert (CONST_INT_P (operands[0]));
1481 last_reg = (INTVAL (operands[0]) / UNITS_PER_WORD) - 1;
1483 gcc_assert (GET_CODE (operands[1]) == PARALLEL);
1484 first_push = XVECEXP (operands[1], 0, 1);
1485 gcc_assert (SET_P (first_push));
1486 first_push = SET_SRC (first_push);
1487 gcc_assert (REG_P (first_push));
1489 asm_fprintf (asm_out_file, "\tpushm\t%s-%s\n",
1490 reg_names [REGNO (first_push) - last_reg],
1491 reg_names [REGNO (first_push)]);
1494 /* Generate a PARALLEL that will pass the rx_store_multiple_vector predicate. */
1496 static rtx
1497 gen_rx_store_vector (unsigned int low, unsigned int high)
1499 unsigned int i;
1500 unsigned int count = (high - low) + 2;
1501 rtx vector;
1503 vector = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1505 XVECEXP (vector, 0, 0) =
1506 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1507 gen_rtx_MINUS (SImode, stack_pointer_rtx,
1508 GEN_INT ((count - 1) * UNITS_PER_WORD)));
1510 for (i = 0; i < count - 1; i++)
1511 XVECEXP (vector, 0, i + 1) =
1512 gen_rtx_SET (VOIDmode,
1513 gen_rtx_MEM (SImode,
1514 gen_rtx_MINUS (SImode, stack_pointer_rtx,
1515 GEN_INT ((i + 1) * UNITS_PER_WORD))),
1516 gen_rtx_REG (SImode, high - i));
1517 return vector;
1520 /* Mark INSN as being frame related. If it is a PARALLEL
1521 then mark each element as being frame related as well. */
1523 static void
1524 mark_frame_related (rtx insn)
1526 RTX_FRAME_RELATED_P (insn) = 1;
1527 insn = PATTERN (insn);
1529 if (GET_CODE (insn) == PARALLEL)
1531 unsigned int i;
1533 for (i = 0; i < (unsigned) XVECLEN (insn, 0); i++)
1534 RTX_FRAME_RELATED_P (XVECEXP (insn, 0, i)) = 1;
1538 static bool
1539 ok_for_max_constant (HOST_WIDE_INT val)
1541 if (rx_max_constant_size == 0 || rx_max_constant_size == 4)
1542 /* If there is no constraint on the size of constants
1543 used as operands, then any value is legitimate. */
1544 return true;
1546 /* rx_max_constant_size specifies the maximum number
1547 of bytes that can be used to hold a signed value. */
1548 return IN_RANGE (val, (-1 << (rx_max_constant_size * 8)),
1549 ( 1 << (rx_max_constant_size * 8)));
1552 /* Generate an ADD of SRC plus VAL into DEST.
1553 Handles the case where VAL is too big for max_constant_value.
1554 Sets FRAME_RELATED_P on the insn if IS_FRAME_RELATED is true. */
1556 static void
1557 gen_safe_add (rtx dest, rtx src, rtx val, bool is_frame_related)
1559 rtx insn;
1561 if (val == NULL_RTX || INTVAL (val) == 0)
1563 gcc_assert (dest != src);
1565 insn = emit_move_insn (dest, src);
1567 else if (ok_for_max_constant (INTVAL (val)))
1568 insn = emit_insn (gen_addsi3 (dest, src, val));
1569 else
1571 /* Wrap VAL in an UNSPEC so that rx_is_legitimate_constant
1572 will not reject it. */
1573 val = gen_rtx_CONST (SImode, gen_rtx_UNSPEC (SImode, gen_rtvec (1, val), UNSPEC_CONST));
1574 insn = emit_insn (gen_addsi3 (dest, src, val));
1576 if (is_frame_related)
1577 /* We have to provide our own frame related note here
1578 as the dwarf2out code cannot be expected to grok
1579 our unspec. */
1580 add_reg_note (insn, REG_FRAME_RELATED_EXPR,
1581 gen_rtx_SET (SImode, dest,
1582 gen_rtx_PLUS (SImode, src, val)));
1583 return;
1586 if (is_frame_related)
1587 RTX_FRAME_RELATED_P (insn) = 1;
1588 return;
1591 void
1592 rx_expand_prologue (void)
1594 unsigned int stack_size;
1595 unsigned int frame_size;
1596 unsigned int mask;
1597 unsigned int low;
1598 unsigned int high;
1599 unsigned int reg;
1600 rtx insn;
1602 /* Naked functions use their own, programmer provided prologues. */
1603 if (is_naked_func (NULL_TREE))
1604 return;
1606 rx_get_stack_layout (& low, & high, & mask, & frame_size, & stack_size);
1608 /* If we use any of the callee-saved registers, save them now. */
1609 if (mask)
1611 /* Push registers in reverse order. */
1612 for (reg = CC_REGNUM; reg --;)
1613 if (mask & (1 << reg))
1615 insn = emit_insn (gen_stack_push (gen_rtx_REG (SImode, reg)));
1616 mark_frame_related (insn);
1619 else if (low)
1621 if (high == low)
1622 insn = emit_insn (gen_stack_push (gen_rtx_REG (SImode, low)));
1623 else
1624 insn = emit_insn (gen_stack_pushm (GEN_INT (((high - low) + 1)
1625 * UNITS_PER_WORD),
1626 gen_rx_store_vector (low, high)));
1627 mark_frame_related (insn);
1630 if (MUST_SAVE_ACC_REGISTER)
1632 unsigned int acc_high, acc_low;
1634 /* Interrupt handlers have to preserve the accumulator
1635 register if so requested by the user. Use the first
1636 two pushed registers as intermediaries. */
1637 if (mask)
1639 acc_low = acc_high = 0;
1641 for (reg = 1; reg < CC_REGNUM; reg ++)
1642 if (mask & (1 << reg))
1644 if (acc_low == 0)
1645 acc_low = reg;
1646 else
1648 acc_high = reg;
1649 break;
1653 /* We have assumed that there are at least two registers pushed... */
1654 gcc_assert (acc_high != 0);
1656 /* Note - the bottom 16 bits of the accumulator are inaccessible.
1657 We just assume that they are zero. */
1658 emit_insn (gen_mvfacmi (gen_rtx_REG (SImode, acc_low)));
1659 emit_insn (gen_mvfachi (gen_rtx_REG (SImode, acc_high)));
1660 emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_low)));
1661 emit_insn (gen_stack_push (gen_rtx_REG (SImode, acc_high)));
1663 else
1665 acc_low = low;
1666 acc_high = low + 1;
1668 /* We have assumed that there are at least two registers pushed... */
1669 gcc_assert (acc_high <= high);
1671 emit_insn (gen_mvfacmi (gen_rtx_REG (SImode, acc_low)));
1672 emit_insn (gen_mvfachi (gen_rtx_REG (SImode, acc_high)));
1673 emit_insn (gen_stack_pushm (GEN_INT (2 * UNITS_PER_WORD),
1674 gen_rx_store_vector (acc_low, acc_high)));
1678 /* If needed, set up the frame pointer. */
1679 if (frame_pointer_needed)
1680 gen_safe_add (frame_pointer_rtx, stack_pointer_rtx,
1681 GEN_INT (- (HOST_WIDE_INT) frame_size), true);
1683 /* Allocate space for the outgoing args.
1684 If the stack frame has not already been set up then handle this as well. */
1685 if (stack_size)
1687 if (frame_size)
1689 if (frame_pointer_needed)
1690 gen_safe_add (stack_pointer_rtx, frame_pointer_rtx,
1691 GEN_INT (- (HOST_WIDE_INT) stack_size), true);
1692 else
1693 gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
1694 GEN_INT (- (HOST_WIDE_INT) (frame_size + stack_size)),
1695 true);
1697 else
1698 gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
1699 GEN_INT (- (HOST_WIDE_INT) stack_size), true);
1701 else if (frame_size)
1703 if (! frame_pointer_needed)
1704 gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
1705 GEN_INT (- (HOST_WIDE_INT) frame_size), true);
1706 else
1707 gen_safe_add (stack_pointer_rtx, frame_pointer_rtx, NULL_RTX,
1708 true);
1712 static void
1713 rx_output_function_prologue (FILE * file,
1714 HOST_WIDE_INT frame_size ATTRIBUTE_UNUSED)
1716 if (is_fast_interrupt_func (NULL_TREE))
1717 asm_fprintf (file, "\t; Note: Fast Interrupt Handler\n");
1719 if (is_interrupt_func (NULL_TREE))
1720 asm_fprintf (file, "\t; Note: Interrupt Handler\n");
1722 if (is_naked_func (NULL_TREE))
1723 asm_fprintf (file, "\t; Note: Naked Function\n");
1725 if (cfun->static_chain_decl != NULL)
1726 asm_fprintf (file, "\t; Note: Nested function declared "
1727 "inside another function.\n");
1729 if (crtl->calls_eh_return)
1730 asm_fprintf (file, "\t; Note: Calls __builtin_eh_return.\n");
1733 /* Generate a POPM or RTSD instruction that matches the given operands. */
1735 void
1736 rx_emit_stack_popm (rtx * operands, bool is_popm)
1738 HOST_WIDE_INT stack_adjust;
1739 HOST_WIDE_INT last_reg;
1740 rtx first_push;
1742 gcc_assert (CONST_INT_P (operands[0]));
1743 stack_adjust = INTVAL (operands[0]);
1745 gcc_assert (GET_CODE (operands[1]) == PARALLEL);
1746 last_reg = XVECLEN (operands[1], 0) - (is_popm ? 2 : 3);
1748 first_push = XVECEXP (operands[1], 0, 1);
1749 gcc_assert (SET_P (first_push));
1750 first_push = SET_DEST (first_push);
1751 gcc_assert (REG_P (first_push));
1753 if (is_popm)
1754 asm_fprintf (asm_out_file, "\tpopm\t%s-%s\n",
1755 reg_names [REGNO (first_push)],
1756 reg_names [REGNO (first_push) + last_reg]);
1757 else
1758 asm_fprintf (asm_out_file, "\trtsd\t#%d, %s-%s\n",
1759 (int) stack_adjust,
1760 reg_names [REGNO (first_push)],
1761 reg_names [REGNO (first_push) + last_reg]);
1764 /* Generate a PARALLEL which will satisfy the rx_rtsd_vector predicate. */
1766 static rtx
1767 gen_rx_rtsd_vector (unsigned int adjust, unsigned int low, unsigned int high)
1769 unsigned int i;
1770 unsigned int bias = 3;
1771 unsigned int count = (high - low) + bias;
1772 rtx vector;
1774 vector = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1776 XVECEXP (vector, 0, 0) =
1777 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1778 plus_constant (stack_pointer_rtx, adjust));
1780 for (i = 0; i < count - 2; i++)
1781 XVECEXP (vector, 0, i + 1) =
1782 gen_rtx_SET (VOIDmode,
1783 gen_rtx_REG (SImode, low + i),
1784 gen_rtx_MEM (SImode,
1785 i == 0 ? stack_pointer_rtx
1786 : plus_constant (stack_pointer_rtx,
1787 i * UNITS_PER_WORD)));
1789 XVECEXP (vector, 0, count - 1) = ret_rtx;
1791 return vector;
1794 /* Generate a PARALLEL which will satisfy the rx_load_multiple_vector predicate. */
1796 static rtx
1797 gen_rx_popm_vector (unsigned int low, unsigned int high)
1799 unsigned int i;
1800 unsigned int count = (high - low) + 2;
1801 rtx vector;
1803 vector = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count));
1805 XVECEXP (vector, 0, 0) =
1806 gen_rtx_SET (VOIDmode, stack_pointer_rtx,
1807 plus_constant (stack_pointer_rtx,
1808 (count - 1) * UNITS_PER_WORD));
1810 for (i = 0; i < count - 1; i++)
1811 XVECEXP (vector, 0, i + 1) =
1812 gen_rtx_SET (VOIDmode,
1813 gen_rtx_REG (SImode, low + i),
1814 gen_rtx_MEM (SImode,
1815 i == 0 ? stack_pointer_rtx
1816 : plus_constant (stack_pointer_rtx,
1817 i * UNITS_PER_WORD)));
1819 return vector;
1822 void
1823 rx_expand_epilogue (bool is_sibcall)
1825 unsigned int low;
1826 unsigned int high;
1827 unsigned int frame_size;
1828 unsigned int stack_size;
1829 unsigned int register_mask;
1830 unsigned int regs_size;
1831 unsigned int reg;
1832 unsigned HOST_WIDE_INT total_size;
1834 /* FIXME: We do not support indirect sibcalls at the moment becaause we
1835 cannot guarantee that the register holding the function address is a
1836 call-used register. If it is a call-saved register then the stack
1837 pop instructions generated in the epilogue will corrupt the address
1838 before it is used.
1840 Creating a new call-used-only register class works but then the
1841 reload pass gets stuck because it cannot always find a call-used
1842 register for spilling sibcalls.
1844 The other possible solution is for this pass to scan forward for the
1845 sibcall instruction (if it has been generated) and work out if it
1846 is an indirect sibcall using a call-saved register. If it is then
1847 the address can copied into a call-used register in this epilogue
1848 code and the sibcall instruction modified to use that register. */
1850 if (is_naked_func (NULL_TREE))
1852 gcc_assert (! is_sibcall);
1854 /* Naked functions use their own, programmer provided epilogues.
1855 But, in order to keep gcc happy we have to generate some kind of
1856 epilogue RTL. */
1857 emit_jump_insn (gen_naked_return ());
1858 return;
1861 rx_get_stack_layout (& low, & high, & register_mask,
1862 & frame_size, & stack_size);
1864 total_size = frame_size + stack_size;
1865 regs_size = ((high - low) + 1) * UNITS_PER_WORD;
1867 /* See if we are unable to use the special stack frame deconstruct and
1868 return instructions. In most cases we can use them, but the exceptions
1869 are:
1871 - Sibling calling functions deconstruct the frame but do not return to
1872 their caller. Instead they branch to their sibling and allow their
1873 return instruction to return to this function's parent.
1875 - Fast and normal interrupt handling functions have to use special
1876 return instructions.
1878 - Functions where we have pushed a fragmented set of registers into the
1879 call-save area must have the same set of registers popped. */
1880 if (is_sibcall
1881 || is_fast_interrupt_func (NULL_TREE)
1882 || is_interrupt_func (NULL_TREE)
1883 || register_mask)
1885 /* Cannot use the special instructions - deconstruct by hand. */
1886 if (total_size)
1887 gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
1888 GEN_INT (total_size), false);
1890 if (MUST_SAVE_ACC_REGISTER)
1892 unsigned int acc_low, acc_high;
1894 /* Reverse the saving of the accumulator register onto the stack.
1895 Note we must adjust the saved "low" accumulator value as it
1896 is really the middle 32-bits of the accumulator. */
1897 if (register_mask)
1899 acc_low = acc_high = 0;
1901 for (reg = 1; reg < CC_REGNUM; reg ++)
1902 if (register_mask & (1 << reg))
1904 if (acc_low == 0)
1905 acc_low = reg;
1906 else
1908 acc_high = reg;
1909 break;
1912 emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_high)));
1913 emit_insn (gen_stack_pop (gen_rtx_REG (SImode, acc_low)));
1915 else
1917 acc_low = low;
1918 acc_high = low + 1;
1919 emit_insn (gen_stack_popm (GEN_INT (2 * UNITS_PER_WORD),
1920 gen_rx_popm_vector (acc_low, acc_high)));
1923 emit_insn (gen_ashlsi3 (gen_rtx_REG (SImode, acc_low),
1924 gen_rtx_REG (SImode, acc_low),
1925 GEN_INT (16)));
1926 emit_insn (gen_mvtaclo (gen_rtx_REG (SImode, acc_low)));
1927 emit_insn (gen_mvtachi (gen_rtx_REG (SImode, acc_high)));
1930 if (register_mask)
1932 for (reg = 0; reg < CC_REGNUM; reg ++)
1933 if (register_mask & (1 << reg))
1934 emit_insn (gen_stack_pop (gen_rtx_REG (SImode, reg)));
1936 else if (low)
1938 if (high == low)
1939 emit_insn (gen_stack_pop (gen_rtx_REG (SImode, low)));
1940 else
1941 emit_insn (gen_stack_popm (GEN_INT (regs_size),
1942 gen_rx_popm_vector (low, high)));
1945 if (is_fast_interrupt_func (NULL_TREE))
1947 gcc_assert (! is_sibcall);
1948 emit_jump_insn (gen_fast_interrupt_return ());
1950 else if (is_interrupt_func (NULL_TREE))
1952 gcc_assert (! is_sibcall);
1953 emit_jump_insn (gen_exception_return ());
1955 else if (! is_sibcall)
1956 emit_jump_insn (gen_simple_return ());
1958 return;
1961 /* If we allocated space on the stack, free it now. */
1962 if (total_size)
1964 unsigned HOST_WIDE_INT rtsd_size;
1966 /* See if we can use the RTSD instruction. */
1967 rtsd_size = total_size + regs_size;
1968 if (rtsd_size < 1024 && (rtsd_size % 4) == 0)
1970 if (low)
1971 emit_jump_insn (gen_pop_and_return
1972 (GEN_INT (rtsd_size),
1973 gen_rx_rtsd_vector (rtsd_size, low, high)));
1974 else
1975 emit_jump_insn (gen_deallocate_and_return (GEN_INT (total_size)));
1977 return;
1980 gen_safe_add (stack_pointer_rtx, stack_pointer_rtx,
1981 GEN_INT (total_size), false);
1984 if (low)
1985 emit_jump_insn (gen_pop_and_return (GEN_INT (regs_size),
1986 gen_rx_rtsd_vector (regs_size,
1987 low, high)));
1988 else
1989 emit_jump_insn (gen_simple_return ());
1993 /* Compute the offset (in words) between FROM (arg pointer
1994 or frame pointer) and TO (frame pointer or stack pointer).
1995 See ASCII art comment at the start of rx_expand_prologue
1996 for more information. */
1999 rx_initial_elimination_offset (int from, int to)
2001 unsigned int low;
2002 unsigned int high;
2003 unsigned int frame_size;
2004 unsigned int stack_size;
2005 unsigned int mask;
2007 rx_get_stack_layout (& low, & high, & mask, & frame_size, & stack_size);
2009 if (from == ARG_POINTER_REGNUM)
2011 /* Extend the computed size of the stack frame to
2012 include the registers pushed in the prologue. */
2013 if (low)
2014 frame_size += ((high - low) + 1) * UNITS_PER_WORD;
2015 else
2016 frame_size += bit_count (mask) * UNITS_PER_WORD;
2018 /* Remember to include the return address. */
2019 frame_size += 1 * UNITS_PER_WORD;
2021 if (to == FRAME_POINTER_REGNUM)
2022 return frame_size;
2024 gcc_assert (to == STACK_POINTER_REGNUM);
2025 return frame_size + stack_size;
2028 gcc_assert (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM);
2029 return stack_size;
2032 /* Decide if a variable should go into one of the small data sections. */
2034 static bool
2035 rx_in_small_data (const_tree decl)
2037 int size;
2038 const_tree section;
2040 if (rx_small_data_limit == 0)
2041 return false;
2043 if (TREE_CODE (decl) != VAR_DECL)
2044 return false;
2046 /* We do not put read-only variables into a small data area because
2047 they would be placed with the other read-only sections, far away
2048 from the read-write data sections, and we only have one small
2049 data area pointer.
2050 Similarly commons are placed in the .bss section which might be
2051 far away (and out of alignment with respect to) the .data section. */
2052 if (TREE_READONLY (decl) || DECL_COMMON (decl))
2053 return false;
2055 section = DECL_SECTION_NAME (decl);
2056 if (section)
2058 const char * const name = TREE_STRING_POINTER (section);
2060 return (strcmp (name, "D_2") == 0) || (strcmp (name, "B_2") == 0);
2063 size = int_size_in_bytes (TREE_TYPE (decl));
2065 return (size > 0) && (size <= rx_small_data_limit);
2068 /* Return a section for X.
2069 The only special thing we do here is to honor small data. */
2071 static section *
2072 rx_select_rtx_section (enum machine_mode mode,
2073 rtx x,
2074 unsigned HOST_WIDE_INT align)
2076 if (rx_small_data_limit > 0
2077 && GET_MODE_SIZE (mode) <= rx_small_data_limit
2078 && align <= (unsigned HOST_WIDE_INT) rx_small_data_limit * BITS_PER_UNIT)
2079 return sdata_section;
2081 return default_elf_select_rtx_section (mode, x, align);
2084 static section *
2085 rx_select_section (tree decl,
2086 int reloc,
2087 unsigned HOST_WIDE_INT align)
2089 if (rx_small_data_limit > 0)
2091 switch (categorize_decl_for_section (decl, reloc))
2093 case SECCAT_SDATA: return sdata_section;
2094 case SECCAT_SBSS: return sbss_section;
2095 case SECCAT_SRODATA:
2096 /* Fall through. We do not put small, read only
2097 data into the C_2 section because we are not
2098 using the C_2 section. We do not use the C_2
2099 section because it is located with the other
2100 read-only data sections, far away from the read-write
2101 data sections and we only have one small data
2102 pointer (r13). */
2103 default:
2104 break;
2108 /* If we are supporting the Renesas assembler
2109 we cannot use mergeable sections. */
2110 if (TARGET_AS100_SYNTAX)
2111 switch (categorize_decl_for_section (decl, reloc))
2113 case SECCAT_RODATA_MERGE_CONST:
2114 case SECCAT_RODATA_MERGE_STR_INIT:
2115 case SECCAT_RODATA_MERGE_STR:
2116 return readonly_data_section;
2118 default:
2119 break;
2122 return default_elf_select_section (decl, reloc, align);
2125 enum rx_builtin
2127 RX_BUILTIN_BRK,
2128 RX_BUILTIN_CLRPSW,
2129 RX_BUILTIN_INT,
2130 RX_BUILTIN_MACHI,
2131 RX_BUILTIN_MACLO,
2132 RX_BUILTIN_MULHI,
2133 RX_BUILTIN_MULLO,
2134 RX_BUILTIN_MVFACHI,
2135 RX_BUILTIN_MVFACMI,
2136 RX_BUILTIN_MVFC,
2137 RX_BUILTIN_MVTACHI,
2138 RX_BUILTIN_MVTACLO,
2139 RX_BUILTIN_MVTC,
2140 RX_BUILTIN_MVTIPL,
2141 RX_BUILTIN_RACW,
2142 RX_BUILTIN_REVW,
2143 RX_BUILTIN_RMPA,
2144 RX_BUILTIN_ROUND,
2145 RX_BUILTIN_SETPSW,
2146 RX_BUILTIN_WAIT,
2147 RX_BUILTIN_max
2150 static GTY(()) tree rx_builtins[(int) RX_BUILTIN_max];
2152 static void
2153 rx_init_builtins (void)
2155 #define ADD_RX_BUILTIN1(UC_NAME, LC_NAME, RET_TYPE, ARG_TYPE) \
2156 rx_builtins[RX_BUILTIN_##UC_NAME] = \
2157 add_builtin_function ("__builtin_rx_" LC_NAME, \
2158 build_function_type_list (RET_TYPE##_type_node, \
2159 ARG_TYPE##_type_node, \
2160 NULL_TREE), \
2161 RX_BUILTIN_##UC_NAME, \
2162 BUILT_IN_MD, NULL, NULL_TREE)
2164 #define ADD_RX_BUILTIN2(UC_NAME, LC_NAME, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
2165 rx_builtins[RX_BUILTIN_##UC_NAME] = \
2166 add_builtin_function ("__builtin_rx_" LC_NAME, \
2167 build_function_type_list (RET_TYPE##_type_node, \
2168 ARG_TYPE1##_type_node,\
2169 ARG_TYPE2##_type_node,\
2170 NULL_TREE), \
2171 RX_BUILTIN_##UC_NAME, \
2172 BUILT_IN_MD, NULL, NULL_TREE)
2174 #define ADD_RX_BUILTIN3(UC_NAME,LC_NAME,RET_TYPE,ARG_TYPE1,ARG_TYPE2,ARG_TYPE3) \
2175 rx_builtins[RX_BUILTIN_##UC_NAME] = \
2176 add_builtin_function ("__builtin_rx_" LC_NAME, \
2177 build_function_type_list (RET_TYPE##_type_node, \
2178 ARG_TYPE1##_type_node,\
2179 ARG_TYPE2##_type_node,\
2180 ARG_TYPE3##_type_node,\
2181 NULL_TREE), \
2182 RX_BUILTIN_##UC_NAME, \
2183 BUILT_IN_MD, NULL, NULL_TREE)
2185 ADD_RX_BUILTIN1 (BRK, "brk", void, void);
2186 ADD_RX_BUILTIN1 (CLRPSW, "clrpsw", void, integer);
2187 ADD_RX_BUILTIN1 (SETPSW, "setpsw", void, integer);
2188 ADD_RX_BUILTIN1 (INT, "int", void, integer);
2189 ADD_RX_BUILTIN2 (MACHI, "machi", void, intSI, intSI);
2190 ADD_RX_BUILTIN2 (MACLO, "maclo", void, intSI, intSI);
2191 ADD_RX_BUILTIN2 (MULHI, "mulhi", void, intSI, intSI);
2192 ADD_RX_BUILTIN2 (MULLO, "mullo", void, intSI, intSI);
2193 ADD_RX_BUILTIN1 (MVFACHI, "mvfachi", intSI, void);
2194 ADD_RX_BUILTIN1 (MVFACMI, "mvfacmi", intSI, void);
2195 ADD_RX_BUILTIN1 (MVTACHI, "mvtachi", void, intSI);
2196 ADD_RX_BUILTIN1 (MVTACLO, "mvtaclo", void, intSI);
2197 ADD_RX_BUILTIN1 (RMPA, "rmpa", void, void);
2198 ADD_RX_BUILTIN1 (MVFC, "mvfc", intSI, integer);
2199 ADD_RX_BUILTIN2 (MVTC, "mvtc", void, integer, integer);
2200 ADD_RX_BUILTIN1 (MVTIPL, "mvtipl", void, integer);
2201 ADD_RX_BUILTIN1 (RACW, "racw", void, integer);
2202 ADD_RX_BUILTIN1 (ROUND, "round", intSI, float);
2203 ADD_RX_BUILTIN1 (REVW, "revw", intSI, intSI);
2204 ADD_RX_BUILTIN1 (WAIT, "wait", void, void);
2207 /* Return the RX builtin for CODE. */
2209 static tree
2210 rx_builtin_decl (unsigned code, bool initialize_p ATTRIBUTE_UNUSED)
2212 if (code >= RX_BUILTIN_max)
2213 return error_mark_node;
2215 return rx_builtins[code];
2218 static rtx
2219 rx_expand_void_builtin_1_arg (rtx arg, rtx (* gen_func)(rtx), bool reg)
2221 if (reg && ! REG_P (arg))
2222 arg = force_reg (SImode, arg);
2224 emit_insn (gen_func (arg));
2226 return NULL_RTX;
2229 static rtx
2230 rx_expand_builtin_mvtc (tree exp)
2232 rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2233 rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2235 if (! CONST_INT_P (arg1))
2236 return NULL_RTX;
2238 if (! REG_P (arg2))
2239 arg2 = force_reg (SImode, arg2);
2241 emit_insn (gen_mvtc (arg1, arg2));
2243 return NULL_RTX;
2246 static rtx
2247 rx_expand_builtin_mvfc (tree t_arg, rtx target)
2249 rtx arg = expand_normal (t_arg);
2251 if (! CONST_INT_P (arg))
2252 return NULL_RTX;
2254 if (target == NULL_RTX)
2255 return NULL_RTX;
2257 if (! REG_P (target))
2258 target = force_reg (SImode, target);
2260 emit_insn (gen_mvfc (target, arg));
2262 return target;
2265 static rtx
2266 rx_expand_builtin_mvtipl (rtx arg)
2268 /* The RX610 does not support the MVTIPL instruction. */
2269 if (rx_cpu_type == RX610)
2270 return NULL_RTX;
2272 if (! CONST_INT_P (arg) || ! IN_RANGE (INTVAL (arg), 0, (1 << 4) - 1))
2273 return NULL_RTX;
2275 emit_insn (gen_mvtipl (arg));
2277 return NULL_RTX;
2280 static rtx
2281 rx_expand_builtin_mac (tree exp, rtx (* gen_func)(rtx, rtx))
2283 rtx arg1 = expand_normal (CALL_EXPR_ARG (exp, 0));
2284 rtx arg2 = expand_normal (CALL_EXPR_ARG (exp, 1));
2286 if (! REG_P (arg1))
2287 arg1 = force_reg (SImode, arg1);
2289 if (! REG_P (arg2))
2290 arg2 = force_reg (SImode, arg2);
2292 emit_insn (gen_func (arg1, arg2));
2294 return NULL_RTX;
2297 static rtx
2298 rx_expand_int_builtin_1_arg (rtx arg,
2299 rtx target,
2300 rtx (* gen_func)(rtx, rtx),
2301 bool mem_ok)
2303 if (! REG_P (arg))
2304 if (!mem_ok || ! MEM_P (arg))
2305 arg = force_reg (SImode, arg);
2307 if (target == NULL_RTX || ! REG_P (target))
2308 target = gen_reg_rtx (SImode);
2310 emit_insn (gen_func (target, arg));
2312 return target;
2315 static rtx
2316 rx_expand_int_builtin_0_arg (rtx target, rtx (* gen_func)(rtx))
2318 if (target == NULL_RTX || ! REG_P (target))
2319 target = gen_reg_rtx (SImode);
2321 emit_insn (gen_func (target));
2323 return target;
2326 static rtx
2327 rx_expand_builtin_round (rtx arg, rtx target)
2329 if ((! REG_P (arg) && ! MEM_P (arg))
2330 || GET_MODE (arg) != SFmode)
2331 arg = force_reg (SFmode, arg);
2333 if (target == NULL_RTX || ! REG_P (target))
2334 target = gen_reg_rtx (SImode);
2336 emit_insn (gen_lrintsf2 (target, arg));
2338 return target;
2341 static int
2342 valid_psw_flag (rtx op, const char *which)
2344 static int mvtc_inform_done = 0;
2346 if (GET_CODE (op) == CONST_INT)
2347 switch (INTVAL (op))
2349 case 0: case 'c': case 'C':
2350 case 1: case 'z': case 'Z':
2351 case 2: case 's': case 'S':
2352 case 3: case 'o': case 'O':
2353 case 8: case 'i': case 'I':
2354 case 9: case 'u': case 'U':
2355 return 1;
2358 error ("__builtin_rx_%s takes 'C', 'Z', 'S', 'O', 'I', or 'U'", which);
2359 if (!mvtc_inform_done)
2360 error ("use __builtin_rx_mvtc (0, ... ) to write arbitrary values to PSW");
2361 mvtc_inform_done = 1;
2363 return 0;
2366 static rtx
2367 rx_expand_builtin (tree exp,
2368 rtx target,
2369 rtx subtarget ATTRIBUTE_UNUSED,
2370 enum machine_mode mode ATTRIBUTE_UNUSED,
2371 int ignore ATTRIBUTE_UNUSED)
2373 tree fndecl = TREE_OPERAND (CALL_EXPR_FN (exp), 0);
2374 tree arg = call_expr_nargs (exp) >= 1 ? CALL_EXPR_ARG (exp, 0) : NULL_TREE;
2375 rtx op = arg ? expand_normal (arg) : NULL_RTX;
2376 unsigned int fcode = DECL_FUNCTION_CODE (fndecl);
2378 switch (fcode)
2380 case RX_BUILTIN_BRK: emit_insn (gen_brk ()); return NULL_RTX;
2381 case RX_BUILTIN_CLRPSW:
2382 if (!valid_psw_flag (op, "clrpsw"))
2383 return NULL_RTX;
2384 return rx_expand_void_builtin_1_arg (op, gen_clrpsw, false);
2385 case RX_BUILTIN_SETPSW:
2386 if (!valid_psw_flag (op, "setpsw"))
2387 return NULL_RTX;
2388 return rx_expand_void_builtin_1_arg (op, gen_setpsw, false);
2389 case RX_BUILTIN_INT: return rx_expand_void_builtin_1_arg
2390 (op, gen_int, false);
2391 case RX_BUILTIN_MACHI: return rx_expand_builtin_mac (exp, gen_machi);
2392 case RX_BUILTIN_MACLO: return rx_expand_builtin_mac (exp, gen_maclo);
2393 case RX_BUILTIN_MULHI: return rx_expand_builtin_mac (exp, gen_mulhi);
2394 case RX_BUILTIN_MULLO: return rx_expand_builtin_mac (exp, gen_mullo);
2395 case RX_BUILTIN_MVFACHI: return rx_expand_int_builtin_0_arg
2396 (target, gen_mvfachi);
2397 case RX_BUILTIN_MVFACMI: return rx_expand_int_builtin_0_arg
2398 (target, gen_mvfacmi);
2399 case RX_BUILTIN_MVTACHI: return rx_expand_void_builtin_1_arg
2400 (op, gen_mvtachi, true);
2401 case RX_BUILTIN_MVTACLO: return rx_expand_void_builtin_1_arg
2402 (op, gen_mvtaclo, true);
2403 case RX_BUILTIN_RMPA: emit_insn (gen_rmpa ()); return NULL_RTX;
2404 case RX_BUILTIN_MVFC: return rx_expand_builtin_mvfc (arg, target);
2405 case RX_BUILTIN_MVTC: return rx_expand_builtin_mvtc (exp);
2406 case RX_BUILTIN_MVTIPL: return rx_expand_builtin_mvtipl (op);
2407 case RX_BUILTIN_RACW: return rx_expand_void_builtin_1_arg
2408 (op, gen_racw, false);
2409 case RX_BUILTIN_ROUND: return rx_expand_builtin_round (op, target);
2410 case RX_BUILTIN_REVW: return rx_expand_int_builtin_1_arg
2411 (op, target, gen_revw, false);
2412 case RX_BUILTIN_WAIT: emit_insn (gen_wait ()); return NULL_RTX;
2414 default:
2415 internal_error ("bad builtin code");
2416 break;
2419 return NULL_RTX;
2422 /* Place an element into a constructor or destructor section.
2423 Like default_ctor_section_asm_out_constructor in varasm.c
2424 except that it uses .init_array (or .fini_array) and it
2425 handles constructor priorities. */
2427 static void
2428 rx_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
2430 section * s;
2432 if (priority != DEFAULT_INIT_PRIORITY)
2434 char buf[18];
2436 sprintf (buf, "%s.%.5u",
2437 is_ctor ? ".init_array" : ".fini_array",
2438 priority);
2439 s = get_section (buf, SECTION_WRITE, NULL_TREE);
2441 else if (is_ctor)
2442 s = ctors_section;
2443 else
2444 s = dtors_section;
2446 switch_to_section (s);
2447 assemble_align (POINTER_SIZE);
2448 assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
2451 static void
2452 rx_elf_asm_constructor (rtx symbol, int priority)
2454 rx_elf_asm_cdtor (symbol, priority, /* is_ctor= */true);
2457 static void
2458 rx_elf_asm_destructor (rtx symbol, int priority)
2460 rx_elf_asm_cdtor (symbol, priority, /* is_ctor= */false);
2463 /* Check "fast_interrupt", "interrupt" and "naked" attributes. */
2465 static tree
2466 rx_handle_func_attribute (tree * node,
2467 tree name,
2468 tree args,
2469 int flags ATTRIBUTE_UNUSED,
2470 bool * no_add_attrs)
2472 gcc_assert (DECL_P (* node));
2473 gcc_assert (args == NULL_TREE);
2475 if (TREE_CODE (* node) != FUNCTION_DECL)
2477 warning (OPT_Wattributes, "%qE attribute only applies to functions",
2478 name);
2479 * no_add_attrs = true;
2482 /* FIXME: We ought to check for conflicting attributes. */
2484 /* FIXME: We ought to check that the interrupt and exception
2485 handler attributes have been applied to void functions. */
2486 return NULL_TREE;
2489 /* Table of RX specific attributes. */
2490 const struct attribute_spec rx_attribute_table[] =
2492 /* Name, min_len, max_len, decl_req, type_req, fn_type_req, handler,
2493 affects_type_identity. */
2494 { "fast_interrupt", 0, 0, true, false, false, rx_handle_func_attribute,
2495 false },
2496 { "interrupt", 0, 0, true, false, false, rx_handle_func_attribute,
2497 false },
2498 { "naked", 0, 0, true, false, false, rx_handle_func_attribute,
2499 false },
2500 { NULL, 0, 0, false, false, false, NULL, false }
2503 /* Implement TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE. */
2505 static void
2506 rx_override_options_after_change (void)
2508 static bool first_time = TRUE;
2510 if (first_time)
2512 /* If this is the first time through and the user has not disabled
2513 the use of RX FPU hardware then enable -ffinite-math-only,
2514 since the FPU instructions do not support NaNs and infinities. */
2515 if (TARGET_USE_FPU)
2516 flag_finite_math_only = 1;
2518 first_time = FALSE;
2520 else
2522 /* Alert the user if they are changing the optimization options
2523 to use IEEE compliant floating point arithmetic with RX FPU insns. */
2524 if (TARGET_USE_FPU
2525 && !flag_finite_math_only)
2526 warning (0, "RX FPU instructions do not support NaNs and infinities");
2530 static void
2531 rx_option_override (void)
2533 unsigned int i;
2534 cl_deferred_option *opt;
2535 VEC(cl_deferred_option,heap) *vec
2536 = (VEC(cl_deferred_option,heap) *) rx_deferred_options;
2538 FOR_EACH_VEC_ELT (cl_deferred_option, vec, i, opt)
2540 switch (opt->opt_index)
2542 case OPT_mint_register_:
2543 switch (opt->value)
2545 case 4:
2546 fixed_regs[10] = call_used_regs [10] = 1;
2547 /* Fall through. */
2548 case 3:
2549 fixed_regs[11] = call_used_regs [11] = 1;
2550 /* Fall through. */
2551 case 2:
2552 fixed_regs[12] = call_used_regs [12] = 1;
2553 /* Fall through. */
2554 case 1:
2555 fixed_regs[13] = call_used_regs [13] = 1;
2556 /* Fall through. */
2557 case 0:
2558 rx_num_interrupt_regs = opt->value;
2559 break;
2560 default:
2561 rx_num_interrupt_regs = 0;
2562 /* Error message already given because rx_handle_option
2563 returned false. */
2564 break;
2566 break;
2568 default:
2569 gcc_unreachable ();
2573 /* This target defaults to strict volatile bitfields. */
2574 if (flag_strict_volatile_bitfields < 0)
2575 flag_strict_volatile_bitfields = 1;
2577 rx_override_options_after_change ();
2579 if (align_jumps == 0 && ! optimize_size)
2580 align_jumps = 3;
2581 if (align_loops == 0 && ! optimize_size)
2582 align_loops = 3;
2583 if (align_labels == 0 && ! optimize_size)
2584 align_labels = 3;
2588 static bool
2589 rx_allocate_stack_slots_for_args (void)
2591 /* Naked functions should not allocate stack slots for arguments. */
2592 return ! is_naked_func (NULL_TREE);
2595 static bool
2596 rx_func_attr_inlinable (const_tree decl)
2598 return ! is_fast_interrupt_func (decl)
2599 && ! is_interrupt_func (decl)
2600 && ! is_naked_func (decl);
2603 /* Return nonzero if it is ok to make a tail-call to DECL,
2604 a function_decl or NULL if this is an indirect call, using EXP */
2606 static bool
2607 rx_function_ok_for_sibcall (tree decl, tree exp ATTRIBUTE_UNUSED)
2609 /* Do not allow indirect tailcalls. The
2610 sibcall patterns do not support them. */
2611 if (decl == NULL)
2612 return false;
2614 /* Never tailcall from inside interrupt handlers or naked functions. */
2615 if (is_fast_interrupt_func (NULL_TREE)
2616 || is_interrupt_func (NULL_TREE)
2617 || is_naked_func (NULL_TREE))
2618 return false;
2620 return true;
2623 static void
2624 rx_file_start (void)
2626 if (! TARGET_AS100_SYNTAX)
2627 default_file_start ();
2630 static bool
2631 rx_is_ms_bitfield_layout (const_tree record_type ATTRIBUTE_UNUSED)
2633 /* The packed attribute overrides the MS behaviour. */
2634 return ! TYPE_PACKED (record_type);
2637 /* Returns true if X a legitimate constant for an immediate
2638 operand on the RX. X is already known to satisfy CONSTANT_P. */
2640 bool
2641 rx_is_legitimate_constant (enum machine_mode mode ATTRIBUTE_UNUSED, rtx x)
2643 switch (GET_CODE (x))
2645 case CONST:
2646 x = XEXP (x, 0);
2648 if (GET_CODE (x) == PLUS)
2650 if (! CONST_INT_P (XEXP (x, 1)))
2651 return false;
2653 /* GCC would not pass us CONST_INT + CONST_INT so we
2654 know that we have {SYMBOL|LABEL} + CONST_INT. */
2655 x = XEXP (x, 0);
2656 gcc_assert (! CONST_INT_P (x));
2659 switch (GET_CODE (x))
2661 case LABEL_REF:
2662 case SYMBOL_REF:
2663 return true;
2665 case UNSPEC:
2666 return XINT (x, 1) == UNSPEC_CONST || XINT (x, 1) == UNSPEC_PID_ADDR;
2668 default:
2669 /* FIXME: Can this ever happen ? */
2670 gcc_unreachable ();
2672 break;
2674 case LABEL_REF:
2675 case SYMBOL_REF:
2676 return true;
2677 case CONST_DOUBLE:
2678 return (rx_max_constant_size == 0 || rx_max_constant_size == 4);
2679 case CONST_VECTOR:
2680 return false;
2681 default:
2682 gcc_assert (CONST_INT_P (x));
2683 break;
2686 return ok_for_max_constant (INTVAL (x));
2689 static int
2690 rx_address_cost (rtx addr, bool speed)
2692 rtx a, b;
2694 if (GET_CODE (addr) != PLUS)
2695 return COSTS_N_INSNS (1);
2697 a = XEXP (addr, 0);
2698 b = XEXP (addr, 1);
2700 if (REG_P (a) && REG_P (b))
2701 /* Try to discourage REG+REG addressing as it keeps two registers live. */
2702 return COSTS_N_INSNS (4);
2704 if (speed)
2705 /* [REG+OFF] is just as fast as [REG]. */
2706 return COSTS_N_INSNS (1);
2708 if (CONST_INT_P (b)
2709 && ((INTVAL (b) > 128) || INTVAL (b) < -127))
2710 /* Try to discourage REG + <large OFF> when optimizing for size. */
2711 return COSTS_N_INSNS (2);
2713 return COSTS_N_INSNS (1);
2716 static bool
2717 rx_can_eliminate (const int from ATTRIBUTE_UNUSED, const int to)
2719 /* We can always eliminate to the frame pointer.
2720 We can eliminate to the stack pointer unless a frame
2721 pointer is needed. */
2723 return to == FRAME_POINTER_REGNUM
2724 || ( to == STACK_POINTER_REGNUM && ! frame_pointer_needed);
2728 static void
2729 rx_trampoline_template (FILE * file)
2731 /* Output assembler code for a block containing the constant
2732 part of a trampoline, leaving space for the variable parts.
2734 On the RX, (where r8 is the static chain regnum) the trampoline
2735 looks like:
2737 mov #<static chain value>, r8
2738 mov #<function's address>, r9
2739 jmp r9
2741 In big-endian-data-mode however instructions are read into the CPU
2742 4 bytes at a time. These bytes are then swapped around before being
2743 passed to the decoder. So...we must partition our trampoline into
2744 4 byte packets and swap these packets around so that the instruction
2745 reader will reverse the process. But, in order to avoid splitting
2746 the 32-bit constants across these packet boundaries, (making inserting
2747 them into the constructed trampoline very difficult) we have to pad the
2748 instruction sequence with NOP insns. ie:
2752 mov.l #<...>, r8
2755 mov.l #<...>, r9
2756 jmp r9
2758 nop */
2760 if (! TARGET_BIG_ENDIAN_DATA)
2762 asm_fprintf (file, "\tmov.L\t#0deadbeefH, r%d\n", STATIC_CHAIN_REGNUM);
2763 asm_fprintf (file, "\tmov.L\t#0deadbeefH, r%d\n", TRAMPOLINE_TEMP_REGNUM);
2764 asm_fprintf (file, "\tjmp\tr%d\n", TRAMPOLINE_TEMP_REGNUM);
2766 else
2768 char r8 = '0' + STATIC_CHAIN_REGNUM;
2769 char r9 = '0' + TRAMPOLINE_TEMP_REGNUM;
2771 if (TARGET_AS100_SYNTAX)
2773 asm_fprintf (file, "\t.BYTE 0%c2H, 0fbH, 003H, 003H\n", r8);
2774 asm_fprintf (file, "\t.BYTE 0deH, 0adH, 0beH, 0efH\n");
2775 asm_fprintf (file, "\t.BYTE 0%c2H, 0fbH, 003H, 003H\n", r9);
2776 asm_fprintf (file, "\t.BYTE 0deH, 0adH, 0beH, 0efH\n");
2777 asm_fprintf (file, "\t.BYTE 003H, 003H, 00%cH, 07fH\n", r9);
2779 else
2781 asm_fprintf (file, "\t.byte 0x%c2, 0xfb, 0x03, 0x03\n", r8);
2782 asm_fprintf (file, "\t.byte 0xde, 0xad, 0xbe, 0xef\n");
2783 asm_fprintf (file, "\t.byte 0x%c2, 0xfb, 0x03, 0x03\n", r9);
2784 asm_fprintf (file, "\t.byte 0xde, 0xad, 0xbe, 0xef\n");
2785 asm_fprintf (file, "\t.byte 0x03, 0x03, 0x0%c, 0x7f\n", r9);
2790 static void
2791 rx_trampoline_init (rtx tramp, tree fndecl, rtx chain)
2793 rtx fnaddr = XEXP (DECL_RTL (fndecl), 0);
2795 emit_block_move (tramp, assemble_trampoline_template (),
2796 GEN_INT (TRAMPOLINE_SIZE), BLOCK_OP_NORMAL);
2798 if (TARGET_BIG_ENDIAN_DATA)
2800 emit_move_insn (adjust_address (tramp, SImode, 4), chain);
2801 emit_move_insn (adjust_address (tramp, SImode, 12), fnaddr);
2803 else
2805 emit_move_insn (adjust_address (tramp, SImode, 2), chain);
2806 emit_move_insn (adjust_address (tramp, SImode, 6 + 2), fnaddr);
2810 static int
2811 rx_memory_move_cost (enum machine_mode mode ATTRIBUTE_UNUSED,
2812 reg_class_t regclass ATTRIBUTE_UNUSED,
2813 bool in)
2815 return (in ? 2 : 0) + REGISTER_MOVE_COST (mode, regclass, regclass);
2818 /* Convert a CC_MODE to the set of flags that it represents. */
2820 static unsigned int
2821 flags_from_mode (enum machine_mode mode)
2823 switch (mode)
2825 case CC_ZSmode:
2826 return CC_FLAG_S | CC_FLAG_Z;
2827 case CC_ZSOmode:
2828 return CC_FLAG_S | CC_FLAG_Z | CC_FLAG_O;
2829 case CC_ZSCmode:
2830 return CC_FLAG_S | CC_FLAG_Z | CC_FLAG_C;
2831 case CCmode:
2832 return CC_FLAG_S | CC_FLAG_Z | CC_FLAG_O | CC_FLAG_C;
2833 case CC_Fmode:
2834 return CC_FLAG_FP;
2835 default:
2836 gcc_unreachable ();
2840 /* Convert a set of flags to a CC_MODE that can implement it. */
2842 static enum machine_mode
2843 mode_from_flags (unsigned int f)
2845 if (f & CC_FLAG_FP)
2846 return CC_Fmode;
2847 if (f & CC_FLAG_O)
2849 if (f & CC_FLAG_C)
2850 return CCmode;
2851 else
2852 return CC_ZSOmode;
2854 else if (f & CC_FLAG_C)
2855 return CC_ZSCmode;
2856 else
2857 return CC_ZSmode;
2860 /* Convert an RTX_CODE to the set of flags needed to implement it.
2861 This assumes an integer comparison. */
2863 static unsigned int
2864 flags_from_code (enum rtx_code code)
2866 switch (code)
2868 case LT:
2869 case GE:
2870 return CC_FLAG_S;
2871 case GT:
2872 case LE:
2873 return CC_FLAG_S | CC_FLAG_O | CC_FLAG_Z;
2874 case GEU:
2875 case LTU:
2876 return CC_FLAG_C;
2877 case GTU:
2878 case LEU:
2879 return CC_FLAG_C | CC_FLAG_Z;
2880 case EQ:
2881 case NE:
2882 return CC_FLAG_Z;
2883 default:
2884 gcc_unreachable ();
2888 /* Return a CC_MODE of which both M1 and M2 are subsets. */
2890 static enum machine_mode
2891 rx_cc_modes_compatible (enum machine_mode m1, enum machine_mode m2)
2893 unsigned f;
2895 /* Early out for identical modes. */
2896 if (m1 == m2)
2897 return m1;
2899 /* There's no valid combination for FP vs non-FP. */
2900 f = flags_from_mode (m1) | flags_from_mode (m2);
2901 if (f & CC_FLAG_FP)
2902 return VOIDmode;
2904 /* Otherwise, see what mode can implement all the flags. */
2905 return mode_from_flags (f);
2908 /* Return the minimal CC mode needed to implement (CMP_CODE X Y). */
2910 enum machine_mode
2911 rx_select_cc_mode (enum rtx_code cmp_code, rtx x, rtx y)
2913 if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
2914 return CC_Fmode;
2916 if (y != const0_rtx)
2917 return CCmode;
2919 return mode_from_flags (flags_from_code (cmp_code));
2922 /* Split the conditional branch. Emit (COMPARE C1 C2) into CC_REG with
2923 CC_MODE, and use that in branches based on that compare. */
2925 void
2926 rx_split_cbranch (enum machine_mode cc_mode, enum rtx_code cmp1,
2927 rtx c1, rtx c2, rtx label)
2929 rtx flags, x;
2931 flags = gen_rtx_REG (cc_mode, CC_REG);
2932 x = gen_rtx_COMPARE (cc_mode, c1, c2);
2933 x = gen_rtx_SET (VOIDmode, flags, x);
2934 emit_insn (x);
2936 x = gen_rtx_fmt_ee (cmp1, VOIDmode, flags, const0_rtx);
2937 x = gen_rtx_IF_THEN_ELSE (VOIDmode, x, label, pc_rtx);
2938 x = gen_rtx_SET (VOIDmode, pc_rtx, x);
2939 emit_jump_insn (x);
2942 /* A helper function for matching parallels that set the flags. */
2944 bool
2945 rx_match_ccmode (rtx insn, enum machine_mode cc_mode)
2947 rtx op1, flags;
2948 enum machine_mode flags_mode;
2950 gcc_checking_assert (XVECLEN (PATTERN (insn), 0) == 2);
2952 op1 = XVECEXP (PATTERN (insn), 0, 1);
2953 gcc_checking_assert (GET_CODE (SET_SRC (op1)) == COMPARE);
2955 flags = SET_DEST (op1);
2956 flags_mode = GET_MODE (flags);
2958 if (GET_MODE (SET_SRC (op1)) != flags_mode)
2959 return false;
2960 if (GET_MODE_CLASS (flags_mode) != MODE_CC)
2961 return false;
2963 /* Ensure that the mode of FLAGS is compatible with CC_MODE. */
2964 if (flags_from_mode (flags_mode) & ~flags_from_mode (cc_mode))
2965 return false;
2967 return true;
2971 rx_align_for_label (rtx lab, int uses_threshold)
2973 /* This is a simple heuristic to guess when an alignment would not be useful
2974 because the delay due to the inserted NOPs would be greater than the delay
2975 due to the misaligned branch. If uses_threshold is zero then the alignment
2976 is always useful. */
2977 if (LABEL_P (lab) && LABEL_NUSES (lab) < uses_threshold)
2978 return 0;
2980 return optimize_size ? 1 : 3;
2983 static int
2984 rx_max_skip_for_label (rtx lab)
2986 int opsize;
2987 rtx op;
2989 if (lab == NULL_RTX)
2990 return 0;
2992 op = lab;
2995 op = next_nonnote_nondebug_insn (op);
2997 while (op && (LABEL_P (op)
2998 || (INSN_P (op) && GET_CODE (PATTERN (op)) == USE)));
2999 if (!op)
3000 return 0;
3002 opsize = get_attr_length (op);
3003 if (opsize >= 0 && opsize < 8)
3004 return opsize - 1;
3005 return 0;
3008 /* Compute the real length of the extending load-and-op instructions. */
3011 rx_adjust_insn_length (rtx insn, int current_length)
3013 rtx extend, mem, offset;
3014 bool zero;
3015 int factor;
3017 switch (INSN_CODE (insn))
3019 default:
3020 return current_length;
3022 case CODE_FOR_plussi3_zero_extendhi:
3023 case CODE_FOR_andsi3_zero_extendhi:
3024 case CODE_FOR_iorsi3_zero_extendhi:
3025 case CODE_FOR_xorsi3_zero_extendhi:
3026 case CODE_FOR_divsi3_zero_extendhi:
3027 case CODE_FOR_udivsi3_zero_extendhi:
3028 case CODE_FOR_minussi3_zero_extendhi:
3029 case CODE_FOR_smaxsi3_zero_extendhi:
3030 case CODE_FOR_sminsi3_zero_extendhi:
3031 case CODE_FOR_multsi3_zero_extendhi:
3032 case CODE_FOR_comparesi3_zero_extendhi:
3033 zero = true;
3034 factor = 2;
3035 break;
3037 case CODE_FOR_plussi3_sign_extendhi:
3038 case CODE_FOR_andsi3_sign_extendhi:
3039 case CODE_FOR_iorsi3_sign_extendhi:
3040 case CODE_FOR_xorsi3_sign_extendhi:
3041 case CODE_FOR_divsi3_sign_extendhi:
3042 case CODE_FOR_udivsi3_sign_extendhi:
3043 case CODE_FOR_minussi3_sign_extendhi:
3044 case CODE_FOR_smaxsi3_sign_extendhi:
3045 case CODE_FOR_sminsi3_sign_extendhi:
3046 case CODE_FOR_multsi3_sign_extendhi:
3047 case CODE_FOR_comparesi3_sign_extendhi:
3048 zero = false;
3049 factor = 2;
3050 break;
3052 case CODE_FOR_plussi3_zero_extendqi:
3053 case CODE_FOR_andsi3_zero_extendqi:
3054 case CODE_FOR_iorsi3_zero_extendqi:
3055 case CODE_FOR_xorsi3_zero_extendqi:
3056 case CODE_FOR_divsi3_zero_extendqi:
3057 case CODE_FOR_udivsi3_zero_extendqi:
3058 case CODE_FOR_minussi3_zero_extendqi:
3059 case CODE_FOR_smaxsi3_zero_extendqi:
3060 case CODE_FOR_sminsi3_zero_extendqi:
3061 case CODE_FOR_multsi3_zero_extendqi:
3062 case CODE_FOR_comparesi3_zero_extendqi:
3063 zero = true;
3064 factor = 1;
3065 break;
3067 case CODE_FOR_plussi3_sign_extendqi:
3068 case CODE_FOR_andsi3_sign_extendqi:
3069 case CODE_FOR_iorsi3_sign_extendqi:
3070 case CODE_FOR_xorsi3_sign_extendqi:
3071 case CODE_FOR_divsi3_sign_extendqi:
3072 case CODE_FOR_udivsi3_sign_extendqi:
3073 case CODE_FOR_minussi3_sign_extendqi:
3074 case CODE_FOR_smaxsi3_sign_extendqi:
3075 case CODE_FOR_sminsi3_sign_extendqi:
3076 case CODE_FOR_multsi3_sign_extendqi:
3077 case CODE_FOR_comparesi3_sign_extendqi:
3078 zero = false;
3079 factor = 1;
3080 break;
3083 /* We are expecting: (SET (REG) (<OP> (REG) (<EXTEND> (MEM)))). */
3084 extend = single_set (insn);
3085 gcc_assert (extend != NULL_RTX);
3087 extend = SET_SRC (extend);
3088 if (GET_CODE (XEXP (extend, 0)) == ZERO_EXTEND
3089 || GET_CODE (XEXP (extend, 0)) == SIGN_EXTEND)
3090 extend = XEXP (extend, 0);
3091 else
3092 extend = XEXP (extend, 1);
3094 gcc_assert ((zero && (GET_CODE (extend) == ZERO_EXTEND))
3095 || (! zero && (GET_CODE (extend) == SIGN_EXTEND)));
3097 mem = XEXP (extend, 0);
3098 gcc_checking_assert (MEM_P (mem));
3099 if (REG_P (XEXP (mem, 0)))
3100 return (zero && factor == 1) ? 2 : 3;
3102 /* We are expecting: (MEM (PLUS (REG) (CONST_INT))). */
3103 gcc_checking_assert (GET_CODE (XEXP (mem, 0)) == PLUS);
3104 gcc_checking_assert (REG_P (XEXP (XEXP (mem, 0), 0)));
3106 offset = XEXP (XEXP (mem, 0), 1);
3107 gcc_checking_assert (GET_CODE (offset) == CONST_INT);
3109 if (IN_RANGE (INTVAL (offset), 0, 255 * factor))
3110 return (zero && factor == 1) ? 3 : 4;
3112 return (zero && factor == 1) ? 4 : 5;
3115 #undef TARGET_ASM_JUMP_ALIGN_MAX_SKIP
3116 #define TARGET_ASM_JUMP_ALIGN_MAX_SKIP rx_max_skip_for_label
3117 #undef TARGET_ASM_LOOP_ALIGN_MAX_SKIP
3118 #define TARGET_ASM_LOOP_ALIGN_MAX_SKIP rx_max_skip_for_label
3119 #undef TARGET_LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP
3120 #define TARGET_LABEL_ALIGN_AFTER_BARRIER_MAX_SKIP rx_max_skip_for_label
3121 #undef TARGET_ASM_LABEL_ALIGN_MAX_SKIP
3122 #define TARGET_ASM_LABEL_ALIGN_MAX_SKIP rx_max_skip_for_label
3124 #undef TARGET_FUNCTION_VALUE
3125 #define TARGET_FUNCTION_VALUE rx_function_value
3127 #undef TARGET_RETURN_IN_MSB
3128 #define TARGET_RETURN_IN_MSB rx_return_in_msb
3130 #undef TARGET_IN_SMALL_DATA_P
3131 #define TARGET_IN_SMALL_DATA_P rx_in_small_data
3133 #undef TARGET_RETURN_IN_MEMORY
3134 #define TARGET_RETURN_IN_MEMORY rx_return_in_memory
3136 #undef TARGET_HAVE_SRODATA_SECTION
3137 #define TARGET_HAVE_SRODATA_SECTION true
3139 #undef TARGET_ASM_SELECT_RTX_SECTION
3140 #define TARGET_ASM_SELECT_RTX_SECTION rx_select_rtx_section
3142 #undef TARGET_ASM_SELECT_SECTION
3143 #define TARGET_ASM_SELECT_SECTION rx_select_section
3145 #undef TARGET_INIT_BUILTINS
3146 #define TARGET_INIT_BUILTINS rx_init_builtins
3148 #undef TARGET_BUILTIN_DECL
3149 #define TARGET_BUILTIN_DECL rx_builtin_decl
3151 #undef TARGET_EXPAND_BUILTIN
3152 #define TARGET_EXPAND_BUILTIN rx_expand_builtin
3154 #undef TARGET_ASM_CONSTRUCTOR
3155 #define TARGET_ASM_CONSTRUCTOR rx_elf_asm_constructor
3157 #undef TARGET_ASM_DESTRUCTOR
3158 #define TARGET_ASM_DESTRUCTOR rx_elf_asm_destructor
3160 #undef TARGET_STRUCT_VALUE_RTX
3161 #define TARGET_STRUCT_VALUE_RTX rx_struct_value_rtx
3163 #undef TARGET_ATTRIBUTE_TABLE
3164 #define TARGET_ATTRIBUTE_TABLE rx_attribute_table
3166 #undef TARGET_ASM_FILE_START
3167 #define TARGET_ASM_FILE_START rx_file_start
3169 #undef TARGET_MS_BITFIELD_LAYOUT_P
3170 #define TARGET_MS_BITFIELD_LAYOUT_P rx_is_ms_bitfield_layout
3172 #undef TARGET_LEGITIMATE_ADDRESS_P
3173 #define TARGET_LEGITIMATE_ADDRESS_P rx_is_legitimate_address
3175 #undef TARGET_MODE_DEPENDENT_ADDRESS_P
3176 #define TARGET_MODE_DEPENDENT_ADDRESS_P rx_mode_dependent_address_p
3178 #undef TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS
3179 #define TARGET_ALLOCATE_STACK_SLOTS_FOR_ARGS rx_allocate_stack_slots_for_args
3181 #undef TARGET_ASM_FUNCTION_PROLOGUE
3182 #define TARGET_ASM_FUNCTION_PROLOGUE rx_output_function_prologue
3184 #undef TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P
3185 #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P rx_func_attr_inlinable
3187 #undef TARGET_FUNCTION_OK_FOR_SIBCALL
3188 #define TARGET_FUNCTION_OK_FOR_SIBCALL rx_function_ok_for_sibcall
3190 #undef TARGET_FUNCTION_ARG
3191 #define TARGET_FUNCTION_ARG rx_function_arg
3193 #undef TARGET_FUNCTION_ARG_ADVANCE
3194 #define TARGET_FUNCTION_ARG_ADVANCE rx_function_arg_advance
3196 #undef TARGET_FUNCTION_ARG_BOUNDARY
3197 #define TARGET_FUNCTION_ARG_BOUNDARY rx_function_arg_boundary
3199 #undef TARGET_SET_CURRENT_FUNCTION
3200 #define TARGET_SET_CURRENT_FUNCTION rx_set_current_function
3202 #undef TARGET_ASM_INTEGER
3203 #define TARGET_ASM_INTEGER rx_assemble_integer
3205 #undef TARGET_USE_BLOCKS_FOR_CONSTANT_P
3206 #define TARGET_USE_BLOCKS_FOR_CONSTANT_P hook_bool_mode_const_rtx_true
3208 #undef TARGET_MAX_ANCHOR_OFFSET
3209 #define TARGET_MAX_ANCHOR_OFFSET 32
3211 #undef TARGET_ADDRESS_COST
3212 #define TARGET_ADDRESS_COST rx_address_cost
3214 #undef TARGET_CAN_ELIMINATE
3215 #define TARGET_CAN_ELIMINATE rx_can_eliminate
3217 #undef TARGET_CONDITIONAL_REGISTER_USAGE
3218 #define TARGET_CONDITIONAL_REGISTER_USAGE rx_conditional_register_usage
3220 #undef TARGET_ASM_TRAMPOLINE_TEMPLATE
3221 #define TARGET_ASM_TRAMPOLINE_TEMPLATE rx_trampoline_template
3223 #undef TARGET_TRAMPOLINE_INIT
3224 #define TARGET_TRAMPOLINE_INIT rx_trampoline_init
3226 #undef TARGET_PRINT_OPERAND
3227 #define TARGET_PRINT_OPERAND rx_print_operand
3229 #undef TARGET_PRINT_OPERAND_ADDRESS
3230 #define TARGET_PRINT_OPERAND_ADDRESS rx_print_operand_address
3232 #undef TARGET_CC_MODES_COMPATIBLE
3233 #define TARGET_CC_MODES_COMPATIBLE rx_cc_modes_compatible
3235 #undef TARGET_MEMORY_MOVE_COST
3236 #define TARGET_MEMORY_MOVE_COST rx_memory_move_cost
3238 #undef TARGET_OPTION_OVERRIDE
3239 #define TARGET_OPTION_OVERRIDE rx_option_override
3241 #undef TARGET_PROMOTE_FUNCTION_MODE
3242 #define TARGET_PROMOTE_FUNCTION_MODE rx_promote_function_mode
3244 #undef TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE
3245 #define TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE rx_override_options_after_change
3247 #undef TARGET_FLAGS_REGNUM
3248 #define TARGET_FLAGS_REGNUM CC_REG
3250 #undef TARGET_LEGITIMATE_CONSTANT_P
3251 #define TARGET_LEGITIMATE_CONSTANT_P rx_is_legitimate_constant
3253 #undef TARGET_LEGITIMIZE_ADDRESS
3254 #define TARGET_LEGITIMIZE_ADDRESS rx_legitimize_address
3256 struct gcc_target targetm = TARGET_INITIALIZER;
3258 #include "gt-rx.h"