1 /* Subroutines for insn-output.c for Matsushita MN10300 series
2 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Contributed by Jeff Law (law@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
25 #include "coretypes.h"
30 #include "hard-reg-set.h"
32 #include "insn-config.h"
33 #include "conditions.h"
35 #include "insn-attr.h"
45 #include "target-def.h"
47 /* This is used by GOTaddr2picreg to uniquely identify
49 int mn10300_unspec_int_label_counter;
51 /* This is used in the am33_2.0-linux-gnu port, in which global symbol
52 names are not prefixed by underscores, to tell whether to prefix a
53 label with a plus sign or not, so that the assembler can tell
54 symbol names from register names. */
55 int mn10300_protect_label;
57 /* The size of the callee register save area. Right now we save everything
58 on entry since it costs us nothing in code size. It does cost us from a
59 speed standpoint, so we want to optimize this sooner or later. */
60 #define REG_SAVE_BYTES (4 * regs_ever_live[2] \
61 + 4 * regs_ever_live[3] \
62 + 4 * regs_ever_live[6] \
63 + 4 * regs_ever_live[7] \
64 + 16 * (regs_ever_live[14] || regs_ever_live[15] \
65 || regs_ever_live[16] || regs_ever_live[17]))
68 static int mn10300_address_cost_1 (rtx, int *);
69 static int mn10300_address_cost (rtx);
70 static bool mn10300_rtx_costs (rtx, int, int, int *);
71 static void mn10300_file_start (void);
72 static bool mn10300_return_in_memory (tree, tree);
73 static rtx mn10300_builtin_saveregs (void);
74 static bool mn10300_pass_by_reference (CUMULATIVE_ARGS *, enum machine_mode,
77 /* Initialize the GCC target structure. */
78 #undef TARGET_ASM_ALIGNED_HI_OP
79 #define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
81 #undef TARGET_RTX_COSTS
82 #define TARGET_RTX_COSTS mn10300_rtx_costs
83 #undef TARGET_ADDRESS_COST
84 #define TARGET_ADDRESS_COST mn10300_address_cost
86 #undef TARGET_ASM_FILE_START
87 #define TARGET_ASM_FILE_START mn10300_file_start
88 #undef TARGET_ASM_FILE_START_FILE_DIRECTIVE
89 #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
91 #undef TARGET_ENCODE_SECTION_INFO
92 #define TARGET_ENCODE_SECTION_INFO mn10300_encode_section_info
94 #undef TARGET_PROMOTE_PROTOTYPES
95 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_true
96 #undef TARGET_RETURN_IN_MEMORY
97 #define TARGET_RETURN_IN_MEMORY mn10300_return_in_memory
98 #undef TARGET_PASS_BY_REFERENCE
99 #define TARGET_PASS_BY_REFERENCE mn10300_pass_by_reference
100 #undef TARGET_CALLEE_COPIES
101 #define TARGET_CALLEE_COPIES hook_bool_CUMULATIVE_ARGS_mode_tree_bool_true
103 #undef TARGET_EXPAND_BUILTIN_SAVEREGS
104 #define TARGET_EXPAND_BUILTIN_SAVEREGS mn10300_builtin_saveregs
106 static void mn10300_encode_section_info (tree, rtx, int);
107 struct gcc_target targetm = TARGET_INITIALIZER;
110 mn10300_file_start (void)
112 default_file_start ();
115 fprintf (asm_out_file, "\t.am33_2\n");
116 else if (TARGET_AM33)
117 fprintf (asm_out_file, "\t.am33\n");
121 /* Print operand X using operand code CODE to assembly language output file
125 print_operand (FILE *file, rtx x, int code)
131 if (cc_status.mdep.fpCC)
133 switch (code == 'b' ? GET_CODE (x)
134 : reverse_condition_maybe_unordered (GET_CODE (x)))
137 fprintf (file, "ne");
140 fprintf (file, "eq");
143 fprintf (file, "ge");
146 fprintf (file, "gt");
149 fprintf (file, "le");
152 fprintf (file, "lt");
155 fprintf (file, "lge");
158 fprintf (file, "uo");
161 fprintf (file, "lg");
164 fprintf (file, "ue");
167 fprintf (file, "uge");
170 fprintf (file, "ug");
173 fprintf (file, "ule");
176 fprintf (file, "ul");
183 /* These are normal and reversed branches. */
184 switch (code == 'b' ? GET_CODE (x) : reverse_condition (GET_CODE (x)))
187 fprintf (file, "ne");
190 fprintf (file, "eq");
193 fprintf (file, "ge");
196 fprintf (file, "gt");
199 fprintf (file, "le");
202 fprintf (file, "lt");
205 fprintf (file, "cc");
208 fprintf (file, "hi");
211 fprintf (file, "ls");
214 fprintf (file, "cs");
221 /* This is used for the operand to a call instruction;
222 if it's a REG, enclose it in parens, else output
223 the operand normally. */
224 if (GET_CODE (x) == REG)
227 print_operand (file, x, 0);
231 print_operand (file, x, 0);
235 switch (GET_CODE (x))
239 output_address (XEXP (x, 0));
244 fprintf (file, "fd%d", REGNO (x) - 18);
252 /* These are the least significant word in a 64bit value. */
254 switch (GET_CODE (x))
258 output_address (XEXP (x, 0));
263 fprintf (file, "%s", reg_names[REGNO (x)]);
267 fprintf (file, "%s", reg_names[subreg_regno (x)]);
275 switch (GET_MODE (x))
278 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
279 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
280 fprintf (file, "0x%lx", val[0]);
283 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
284 REAL_VALUE_TO_TARGET_SINGLE (rv, val[0]);
285 fprintf (file, "0x%lx", val[0]);
289 print_operand_address (file,
290 GEN_INT (CONST_DOUBLE_LOW (x)));
301 split_double (x, &low, &high);
302 fprintf (file, "%ld", (long)INTVAL (low));
311 /* Similarly, but for the most significant word. */
313 switch (GET_CODE (x))
317 x = adjust_address (x, SImode, 4);
318 output_address (XEXP (x, 0));
323 fprintf (file, "%s", reg_names[REGNO (x) + 1]);
327 fprintf (file, "%s", reg_names[subreg_regno (x) + 1]);
335 switch (GET_MODE (x))
338 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
339 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
340 fprintf (file, "0x%lx", val[1]);
346 print_operand_address (file,
347 GEN_INT (CONST_DOUBLE_HIGH (x)));
358 split_double (x, &low, &high);
359 fprintf (file, "%ld", (long)INTVAL (high));
370 if (GET_CODE (XEXP (x, 0)) == REG)
371 output_address (gen_rtx_PLUS (SImode, XEXP (x, 0), const0_rtx));
373 output_address (XEXP (x, 0));
378 if (INTVAL (x) < -128 || INTVAL (x) > 255)
380 fprintf (file, "%d", (int)((~INTVAL (x)) & 0xff));
384 if (INTVAL (x) < -128 || INTVAL (x) > 255)
386 fprintf (file, "%d", (int)(INTVAL (x) & 0xff));
389 /* For shift counts. The hardware ignores the upper bits of
390 any immediate, but the assembler will flag an out of range
391 shift count as an error. So we mask off the high bits
392 of the immediate here. */
394 if (GET_CODE (x) == CONST_INT)
396 fprintf (file, "%d", (int)(INTVAL (x) & 0x1f));
402 switch (GET_CODE (x))
406 output_address (XEXP (x, 0));
415 fprintf (file, "%s", reg_names[REGNO (x)]);
419 fprintf (file, "%s", reg_names[subreg_regno (x)]);
422 /* This will only be single precision.... */
428 REAL_VALUE_FROM_CONST_DOUBLE (rv, x);
429 REAL_VALUE_TO_TARGET_SINGLE (rv, val);
430 fprintf (file, "0x%lx", val);
440 print_operand_address (file, x);
449 /* Output assembly language output for the address ADDR to FILE. */
452 print_operand_address (FILE *file, rtx addr)
454 switch (GET_CODE (addr))
457 print_operand_address (file, XEXP (addr, 0));
461 print_operand (file, addr, 0);
466 if (REG_P (XEXP (addr, 0))
467 && REG_OK_FOR_BASE_P (XEXP (addr, 0)))
468 base = XEXP (addr, 0), index = XEXP (addr, 1);
469 else if (REG_P (XEXP (addr, 1))
470 && REG_OK_FOR_BASE_P (XEXP (addr, 1)))
471 base = XEXP (addr, 1), index = XEXP (addr, 0);
474 print_operand (file, index, 0);
476 print_operand (file, base, 0);;
480 output_addr_const (file, addr);
483 output_addr_const (file, addr);
488 /* Count the number of FP registers that have to be saved. */
490 fp_regs_to_save (void)
497 for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
498 if (regs_ever_live[i] && ! call_used_regs[i])
504 /* Print a set of registers in the format required by "movm" and "ret".
505 Register K is saved if bit K of MASK is set. The data and address
506 registers can be stored individually, but the extended registers cannot.
507 We assume that the mask alread takes that into account. For instance,
508 bits 14 to 17 must have the same value. */
511 mn10300_print_reg_list (FILE *file, int mask)
519 for (i = 0; i < FIRST_EXTENDED_REGNUM; i++)
520 if ((mask & (1 << i)) != 0)
524 fputs (reg_names [i], file);
528 if ((mask & 0x3c000) != 0)
530 if ((mask & 0x3c000) != 0x3c000)
534 fputs ("exreg1", file);
542 can_use_return_insn (void)
544 /* size includes the fixed stack space needed for function calls. */
545 int size = get_frame_size () + current_function_outgoing_args_size;
547 /* And space for the return pointer. */
548 size += current_function_outgoing_args_size ? 4 : 0;
550 return (reload_completed
552 && !regs_ever_live[2]
553 && !regs_ever_live[3]
554 && !regs_ever_live[6]
555 && !regs_ever_live[7]
556 && !regs_ever_live[14]
557 && !regs_ever_live[15]
558 && !regs_ever_live[16]
559 && !regs_ever_live[17]
560 && fp_regs_to_save () == 0
561 && !frame_pointer_needed);
564 /* Returns the set of live, callee-saved registers as a bitmask. The
565 callee-saved extended registers cannot be stored individually, so
566 all of them will be included in the mask if any one of them is used. */
569 mn10300_get_live_callee_saved_regs (void)
575 for (i = 0; i <= LAST_EXTENDED_REGNUM; i++)
576 if (regs_ever_live[i] && ! call_used_regs[i])
578 if ((mask & 0x3c000) != 0)
584 /* Generate an instruction that pushes several registers onto the stack.
585 Register K will be saved if bit K in MASK is set. The function does
586 nothing if MASK is zero.
588 To be compatible with the "movm" instruction, the lowest-numbered
589 register must be stored in the lowest slot. If MASK is the set
590 { R1,...,RN }, where R1...RN are ordered least first, the generated
591 instruction will have the form:
594 (set (reg:SI 9) (plus:SI (reg:SI 9) (const_int -N*4)))
595 (set (mem:SI (plus:SI (reg:SI 9)
599 (set (mem:SI (plus:SI (reg:SI 9)
604 mn10300_gen_multiple_store (int mask)
613 /* Count how many registers need to be saved. */
615 for (i = 0; i <= LAST_EXTENDED_REGNUM; i++)
616 if ((mask & (1 << i)) != 0)
619 /* We need one PARALLEL element to update the stack pointer and
620 an additional element for each register that is stored. */
621 par = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count + 1));
623 /* Create the instruction that updates the stack pointer. */
625 = gen_rtx_SET (SImode,
627 gen_rtx_PLUS (SImode,
629 GEN_INT (-count * 4)));
631 /* Create each store. */
633 for (i = LAST_EXTENDED_REGNUM; i >= 0; i--)
634 if ((mask & (1 << i)) != 0)
636 rtx address = gen_rtx_PLUS (SImode,
638 GEN_INT (-pari * 4));
639 XVECEXP(par, 0, pari)
640 = gen_rtx_SET (VOIDmode,
641 gen_rtx_MEM (SImode, address),
642 gen_rtx_REG (SImode, i));
646 par = emit_insn (par);
647 RTX_FRAME_RELATED_P (par) = 1;
652 expand_prologue (void)
656 /* SIZE includes the fixed stack space needed for function calls. */
657 size = get_frame_size () + current_function_outgoing_args_size;
658 size += (current_function_outgoing_args_size ? 4 : 0);
660 /* If we use any of the callee-saved registers, save them now. */
661 mn10300_gen_multiple_store (mn10300_get_live_callee_saved_regs ());
663 if (TARGET_AM33_2 && fp_regs_to_save ())
665 int num_regs_to_save = fp_regs_to_save (), i;
667 enum { save_sp_merge,
669 save_sp_partial_merge,
671 save_a0_no_merge } strategy;
672 unsigned int strategy_size = (unsigned)-1, this_strategy_size;
676 /* We have several different strategies to save FP registers.
677 We can store them using SP offsets, which is beneficial if
678 there are just a few registers to save, or we can use `a0' in
679 post-increment mode (`a0' is the only call-clobbered address
680 register that is never used to pass information to a
681 function). Furthermore, if we don't need a frame pointer, we
682 can merge the two SP adds into a single one, but this isn't
683 always beneficial; sometimes we can just split the two adds
684 so that we don't exceed a 16-bit constant size. The code
685 below will select which strategy to use, so as to generate
686 smallest code. Ties are broken in favor or shorter sequences
687 (in terms of number of instructions). */
689 #define SIZE_ADD_AX(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
690 : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 2)
691 #define SIZE_ADD_SP(S) ((((S) >= (1 << 15)) || ((S) < -(1 << 15))) ? 6 \
692 : (((S) >= (1 << 7)) || ((S) < -(1 << 7))) ? 4 : 3)
693 #define SIZE_FMOV_LIMIT(S,N,L,SIZE1,SIZE2,ELSE) \
694 (((S) >= (L)) ? (SIZE1) * (N) \
695 : ((S) + 4 * (N) >= (L)) ? (((L) - (S)) / 4 * (SIZE2) \
696 + ((S) + 4 * (N) - (L)) / 4 * (SIZE1)) \
698 #define SIZE_FMOV_SP_(S,N) \
699 (SIZE_FMOV_LIMIT ((S), (N), (1 << 24), 7, 6, \
700 SIZE_FMOV_LIMIT ((S), (N), (1 << 8), 6, 4, \
701 (S) ? 4 * (N) : 3 + 4 * ((N) - 1))))
702 #define SIZE_FMOV_SP(S,N) (SIZE_FMOV_SP_ ((unsigned HOST_WIDE_INT)(S), (N)))
704 /* Consider alternative save_sp_merge only if we don't need the
705 frame pointer and size is nonzero. */
706 if (! frame_pointer_needed && size)
708 /* Insn: add -(size + 4 * num_regs_to_save), sp. */
709 this_strategy_size = SIZE_ADD_SP (-(size + 4 * num_regs_to_save));
710 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
711 this_strategy_size += SIZE_FMOV_SP (size, num_regs_to_save);
713 if (this_strategy_size < strategy_size)
715 strategy = save_sp_merge;
716 strategy_size = this_strategy_size;
720 /* Consider alternative save_sp_no_merge unconditionally. */
721 /* Insn: add -4 * num_regs_to_save, sp. */
722 this_strategy_size = SIZE_ADD_SP (-4 * num_regs_to_save);
723 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
724 this_strategy_size += SIZE_FMOV_SP (0, num_regs_to_save);
727 /* Insn: add -size, sp. */
728 this_strategy_size += SIZE_ADD_SP (-size);
731 if (this_strategy_size < strategy_size)
733 strategy = save_sp_no_merge;
734 strategy_size = this_strategy_size;
737 /* Consider alternative save_sp_partial_merge only if we don't
738 need a frame pointer and size is reasonably large. */
739 if (! frame_pointer_needed && size + 4 * num_regs_to_save > 128)
741 /* Insn: add -128, sp. */
742 this_strategy_size = SIZE_ADD_SP (-128);
743 /* Insn: fmov fs#, (##, sp), for each fs# to be saved. */
744 this_strategy_size += SIZE_FMOV_SP (128 - 4 * num_regs_to_save,
748 /* Insn: add 128-size, sp. */
749 this_strategy_size += SIZE_ADD_SP (128 - size);
752 if (this_strategy_size < strategy_size)
754 strategy = save_sp_partial_merge;
755 strategy_size = this_strategy_size;
759 /* Consider alternative save_a0_merge only if we don't need a
760 frame pointer, size is nonzero and the user hasn't
761 changed the calling conventions of a0. */
762 if (! frame_pointer_needed && size
763 && call_used_regs[FIRST_ADDRESS_REGNUM]
764 && ! fixed_regs[FIRST_ADDRESS_REGNUM])
766 /* Insn: add -(size + 4 * num_regs_to_save), sp. */
767 this_strategy_size = SIZE_ADD_SP (-(size + 4 * num_regs_to_save));
768 /* Insn: mov sp, a0. */
769 this_strategy_size++;
772 /* Insn: add size, a0. */
773 this_strategy_size += SIZE_ADD_AX (size);
775 /* Insn: fmov fs#, (a0+), for each fs# to be saved. */
776 this_strategy_size += 3 * num_regs_to_save;
778 if (this_strategy_size < strategy_size)
780 strategy = save_a0_merge;
781 strategy_size = this_strategy_size;
785 /* Consider alternative save_a0_no_merge if the user hasn't
786 changed the calling conventions of a0. */
787 if (call_used_regs[FIRST_ADDRESS_REGNUM]
788 && ! fixed_regs[FIRST_ADDRESS_REGNUM])
790 /* Insn: add -4 * num_regs_to_save, sp. */
791 this_strategy_size = SIZE_ADD_SP (-4 * num_regs_to_save);
792 /* Insn: mov sp, a0. */
793 this_strategy_size++;
794 /* Insn: fmov fs#, (a0+), for each fs# to be saved. */
795 this_strategy_size += 3 * num_regs_to_save;
798 /* Insn: add -size, sp. */
799 this_strategy_size += SIZE_ADD_SP (-size);
802 if (this_strategy_size < strategy_size)
804 strategy = save_a0_no_merge;
805 strategy_size = this_strategy_size;
809 /* Emit the initial SP add, common to all strategies. */
812 case save_sp_no_merge:
813 case save_a0_no_merge:
814 emit_insn (gen_addsi3 (stack_pointer_rtx,
816 GEN_INT (-4 * num_regs_to_save)));
820 case save_sp_partial_merge:
821 emit_insn (gen_addsi3 (stack_pointer_rtx,
824 xsize = 128 - 4 * num_regs_to_save;
830 emit_insn (gen_addsi3 (stack_pointer_rtx,
832 GEN_INT (-(size + 4 * num_regs_to_save))));
833 /* We'll have to adjust FP register saves according to the
836 /* Since we've already created the stack frame, don't do it
837 again at the end of the function. */
845 /* Now prepare register a0, if we have decided to use it. */
849 case save_sp_no_merge:
850 case save_sp_partial_merge:
855 case save_a0_no_merge:
856 reg = gen_rtx_REG (SImode, FIRST_ADDRESS_REGNUM);
857 emit_insn (gen_movsi (reg, stack_pointer_rtx));
859 emit_insn (gen_addsi3 (reg, reg, GEN_INT (xsize)));
860 reg = gen_rtx_POST_INC (SImode, reg);
867 /* Now actually save the FP registers. */
868 for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
869 if (regs_ever_live[i] && ! call_used_regs[i])
877 /* If we aren't using `a0', use an SP offset. */
880 addr = gen_rtx_PLUS (SImode,
885 addr = stack_pointer_rtx;
890 insn = emit_insn (gen_movsi (gen_rtx_MEM (SImode, addr),
891 gen_rtx_REG (SImode, i)));
893 RTX_FRAME_RELATED_P (insn) = 1;
897 /* Now put the frame pointer into the frame pointer register. */
898 if (frame_pointer_needed)
899 emit_move_insn (frame_pointer_rtx, stack_pointer_rtx);
901 /* Allocate stack for this frame. */
903 emit_insn (gen_addsi3 (stack_pointer_rtx,
906 if (flag_pic && regs_ever_live[PIC_OFFSET_TABLE_REGNUM])
908 rtx insn = get_last_insn ();
909 rtx last = emit_insn (gen_GOTaddr2picreg ());
911 /* Mark these insns as possibly dead. Sometimes, flow2 may
912 delete all uses of the PIC register. In this case, let it
913 delete the initialization too. */
916 insn = NEXT_INSN (insn);
918 REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_MAYBE_DEAD,
922 while (insn != last);
927 expand_epilogue (void)
931 /* SIZE includes the fixed stack space needed for function calls. */
932 size = get_frame_size () + current_function_outgoing_args_size;
933 size += (current_function_outgoing_args_size ? 4 : 0);
935 if (TARGET_AM33_2 && fp_regs_to_save ())
937 int num_regs_to_save = fp_regs_to_save (), i;
940 /* We have several options to restore FP registers. We could
941 load them from SP offsets, but, if there are enough FP
942 registers to restore, we win if we use a post-increment
945 /* If we have a frame pointer, it's the best option, because we
946 already know it has the value we want. */
947 if (frame_pointer_needed)
948 reg = gen_rtx_REG (SImode, FRAME_POINTER_REGNUM);
949 /* Otherwise, we may use `a1', since it's call-clobbered and
950 it's never used for return values. But only do so if it's
951 smaller than using SP offsets. */
954 enum { restore_sp_post_adjust,
955 restore_sp_pre_adjust,
956 restore_sp_partial_adjust,
957 restore_a1 } strategy;
958 unsigned int this_strategy_size, strategy_size = (unsigned)-1;
960 /* Consider using sp offsets before adjusting sp. */
961 /* Insn: fmov (##,sp),fs#, for each fs# to be restored. */
962 this_strategy_size = SIZE_FMOV_SP (size, num_regs_to_save);
963 /* If size is too large, we'll have to adjust SP with an
965 if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
967 /* Insn: add size + 4 * num_regs_to_save, sp. */
968 this_strategy_size += SIZE_ADD_SP (size + 4 * num_regs_to_save);
970 /* If we don't have to restore any non-FP registers,
971 we'll be able to save one byte by using rets. */
972 if (! REG_SAVE_BYTES)
973 this_strategy_size--;
975 if (this_strategy_size < strategy_size)
977 strategy = restore_sp_post_adjust;
978 strategy_size = this_strategy_size;
981 /* Consider using sp offsets after adjusting sp. */
982 /* Insn: add size, sp. */
983 this_strategy_size = SIZE_ADD_SP (size);
984 /* Insn: fmov (##,sp),fs#, for each fs# to be restored. */
985 this_strategy_size += SIZE_FMOV_SP (0, num_regs_to_save);
986 /* We're going to use ret to release the FP registers
987 save area, so, no savings. */
989 if (this_strategy_size < strategy_size)
991 strategy = restore_sp_pre_adjust;
992 strategy_size = this_strategy_size;
995 /* Consider using sp offsets after partially adjusting sp.
996 When size is close to 32Kb, we may be able to adjust SP
997 with an imm16 add instruction while still using fmov
999 if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
1001 /* Insn: add size + 4 * num_regs_to_save
1002 + REG_SAVE_BYTES - 252,sp. */
1003 this_strategy_size = SIZE_ADD_SP (size + 4 * num_regs_to_save
1004 + REG_SAVE_BYTES - 252);
1005 /* Insn: fmov (##,sp),fs#, fo each fs# to be restored. */
1006 this_strategy_size += SIZE_FMOV_SP (252 - REG_SAVE_BYTES
1007 - 4 * num_regs_to_save,
1009 /* We're going to use ret to release the FP registers
1010 save area, so, no savings. */
1012 if (this_strategy_size < strategy_size)
1014 strategy = restore_sp_partial_adjust;
1015 strategy_size = this_strategy_size;
1019 /* Consider using a1 in post-increment mode, as long as the
1020 user hasn't changed the calling conventions of a1. */
1021 if (call_used_regs[FIRST_ADDRESS_REGNUM+1]
1022 && ! fixed_regs[FIRST_ADDRESS_REGNUM+1])
1024 /* Insn: mov sp,a1. */
1025 this_strategy_size = 1;
1028 /* Insn: add size,a1. */
1029 this_strategy_size += SIZE_ADD_AX (size);
1031 /* Insn: fmov (a1+),fs#, for each fs# to be restored. */
1032 this_strategy_size += 3 * num_regs_to_save;
1033 /* If size is large enough, we may be able to save a
1035 if (size + 4 * num_regs_to_save + REG_SAVE_BYTES > 255)
1037 /* Insn: mov a1,sp. */
1038 this_strategy_size += 2;
1040 /* If we don't have to restore any non-FP registers,
1041 we'll be able to save one byte by using rets. */
1042 if (! REG_SAVE_BYTES)
1043 this_strategy_size--;
1045 if (this_strategy_size < strategy_size)
1047 strategy = restore_a1;
1048 strategy_size = this_strategy_size;
1054 case restore_sp_post_adjust:
1057 case restore_sp_pre_adjust:
1058 emit_insn (gen_addsi3 (stack_pointer_rtx,
1064 case restore_sp_partial_adjust:
1065 emit_insn (gen_addsi3 (stack_pointer_rtx,
1067 GEN_INT (size + 4 * num_regs_to_save
1068 + REG_SAVE_BYTES - 252)));
1069 size = 252 - REG_SAVE_BYTES - 4 * num_regs_to_save;
1073 reg = gen_rtx_REG (SImode, FIRST_ADDRESS_REGNUM + 1);
1074 emit_insn (gen_movsi (reg, stack_pointer_rtx));
1076 emit_insn (gen_addsi3 (reg, reg, GEN_INT (size)));
1084 /* Adjust the selected register, if any, for post-increment. */
1086 reg = gen_rtx_POST_INC (SImode, reg);
1088 for (i = FIRST_FP_REGNUM; i <= LAST_FP_REGNUM; ++i)
1089 if (regs_ever_live[i] && ! call_used_regs[i])
1097 /* If we aren't using a post-increment register, use an
1099 addr = gen_rtx_PLUS (SImode,
1104 addr = stack_pointer_rtx;
1108 emit_insn (gen_movsi (gen_rtx_REG (SImode, i),
1109 gen_rtx_MEM (SImode, addr)));
1112 /* If we were using the restore_a1 strategy and the number of
1113 bytes to be released won't fit in the `ret' byte, copy `a1'
1114 to `sp', to avoid having to use `add' to adjust it. */
1115 if (! frame_pointer_needed && reg && size + REG_SAVE_BYTES > 255)
1117 emit_move_insn (stack_pointer_rtx, XEXP (reg, 0));
1122 /* Maybe cut back the stack, except for the register save area.
1124 If the frame pointer exists, then use the frame pointer to
1127 If the stack size + register save area is more than 255 bytes,
1128 then the stack must be cut back here since the size + register
1129 save size is too big for a ret/retf instruction.
1131 Else leave it alone, it will be cut back as part of the
1132 ret/retf instruction, or there wasn't any stack to begin with.
1134 Under no circumstances should the register save area be
1135 deallocated here, that would leave a window where an interrupt
1136 could occur and trash the register save area. */
1137 if (frame_pointer_needed)
1139 emit_move_insn (stack_pointer_rtx, frame_pointer_rtx);
1142 else if (size + REG_SAVE_BYTES > 255)
1144 emit_insn (gen_addsi3 (stack_pointer_rtx,
1150 /* Adjust the stack and restore callee-saved registers, if any. */
1151 if (size || regs_ever_live[2] || regs_ever_live[3]
1152 || regs_ever_live[6] || regs_ever_live[7]
1153 || regs_ever_live[14] || regs_ever_live[15]
1154 || regs_ever_live[16] || regs_ever_live[17]
1155 || frame_pointer_needed)
1156 emit_jump_insn (gen_return_internal_regs
1157 (GEN_INT (size + REG_SAVE_BYTES)));
1159 emit_jump_insn (gen_return_internal ());
1162 /* Update the condition code from the insn. */
1165 notice_update_cc (rtx body, rtx insn)
1167 switch (get_attr_cc (insn))
1170 /* Insn does not affect CC at all. */
1174 /* Insn does not change CC, but the 0'th operand has been changed. */
1175 if (cc_status.value1 != 0
1176 && reg_overlap_mentioned_p (recog_data.operand[0], cc_status.value1))
1177 cc_status.value1 = 0;
1181 /* Insn sets the Z,N flags of CC to recog_data.operand[0].
1182 V,C are unusable. */
1184 cc_status.flags |= CC_NO_CARRY | CC_OVERFLOW_UNUSABLE;
1185 cc_status.value1 = recog_data.operand[0];
1189 /* Insn sets the Z,N,V flags of CC to recog_data.operand[0].
1192 cc_status.flags |= CC_NO_CARRY;
1193 cc_status.value1 = recog_data.operand[0];
1197 /* The insn is a compare instruction. */
1199 cc_status.value1 = SET_SRC (body);
1200 if (GET_CODE (cc_status.value1) == COMPARE
1201 && GET_MODE (XEXP (cc_status.value1, 0)) == SFmode)
1202 cc_status.mdep.fpCC = 1;
1206 /* Insn doesn't leave CC in a usable state. */
1215 /* Recognize the PARALLEL rtx generated by mn10300_gen_multiple_store().
1216 This function is for MATCH_PARALLEL and so assumes OP is known to be
1217 parallel. If OP is a multiple store, return a mask indicating which
1218 registers it saves. Return 0 otherwise. */
1221 store_multiple_operation (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1229 count = XVECLEN (op, 0);
1233 /* Check that first instruction has the form (set (sp) (plus A B)) */
1234 elt = XVECEXP (op, 0, 0);
1235 if (GET_CODE (elt) != SET
1236 || GET_CODE (SET_DEST (elt)) != REG
1237 || REGNO (SET_DEST (elt)) != STACK_POINTER_REGNUM
1238 || GET_CODE (SET_SRC (elt)) != PLUS)
1241 /* Check that A is the stack pointer and B is the expected stack size.
1242 For OP to match, each subsequent instruction should push a word onto
1243 the stack. We therefore expect the first instruction to create
1244 COUNT-1 stack slots. */
1245 elt = SET_SRC (elt);
1246 if (GET_CODE (XEXP (elt, 0)) != REG
1247 || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM
1248 || GET_CODE (XEXP (elt, 1)) != CONST_INT
1249 || INTVAL (XEXP (elt, 1)) != -(count - 1) * 4)
1252 /* Now go through the rest of the vector elements. They must be
1253 ordered so that the first instruction stores the highest-numbered
1254 register to the highest stack slot and that subsequent instructions
1255 store a lower-numbered register to the slot below.
1257 LAST keeps track of the smallest-numbered register stored so far.
1258 MASK is the set of stored registers. */
1259 last = LAST_EXTENDED_REGNUM + 1;
1261 for (i = 1; i < count; i++)
1263 /* Check that element i is a (set (mem M) R) and that R is valid. */
1264 elt = XVECEXP (op, 0, i);
1265 if (GET_CODE (elt) != SET
1266 || GET_CODE (SET_DEST (elt)) != MEM
1267 || GET_CODE (SET_SRC (elt)) != REG
1268 || REGNO (SET_SRC (elt)) >= last)
1271 /* R was OK, so provisionally add it to MASK. We return 0 in any
1272 case if the rest of the instruction has a flaw. */
1273 last = REGNO (SET_SRC (elt));
1274 mask |= (1 << last);
1276 /* Check that M has the form (plus (sp) (const_int -I*4)) */
1277 elt = XEXP (SET_DEST (elt), 0);
1278 if (GET_CODE (elt) != PLUS
1279 || GET_CODE (XEXP (elt, 0)) != REG
1280 || REGNO (XEXP (elt, 0)) != STACK_POINTER_REGNUM
1281 || GET_CODE (XEXP (elt, 1)) != CONST_INT
1282 || INTVAL (XEXP (elt, 1)) != -i * 4)
1286 /* All or none of the callee-saved extended registers must be in the set. */
1287 if ((mask & 0x3c000) != 0
1288 && (mask & 0x3c000) != 0x3c000)
1294 /* Return true if OP is a valid call operand. */
1297 call_address_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1300 return (EXTRA_CONSTRAINT (op, 'S') || GET_CODE (op) == REG);
1302 return (GET_CODE (op) == SYMBOL_REF || GET_CODE (op) == REG);
1305 /* What (if any) secondary registers are needed to move IN with mode
1306 MODE into a register in register class CLASS.
1308 We might be able to simplify this. */
1310 secondary_reload_class (enum reg_class class, enum machine_mode mode, rtx in)
1312 /* Memory loads less than a full word wide can't have an
1313 address or stack pointer destination. They must use
1314 a data register as an intermediate register. */
1315 if ((GET_CODE (in) == MEM
1316 || (GET_CODE (in) == REG
1317 && REGNO (in) >= FIRST_PSEUDO_REGISTER)
1318 || (GET_CODE (in) == SUBREG
1319 && GET_CODE (SUBREG_REG (in)) == REG
1320 && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER))
1321 && (mode == QImode || mode == HImode)
1322 && (class == ADDRESS_REGS || class == SP_REGS
1323 || class == SP_OR_ADDRESS_REGS))
1326 return DATA_OR_EXTENDED_REGS;
1330 /* We can't directly load sp + const_int into a data register;
1331 we must use an address register as an intermediate. */
1332 if (class != SP_REGS
1333 && class != ADDRESS_REGS
1334 && class != SP_OR_ADDRESS_REGS
1335 && class != SP_OR_EXTENDED_REGS
1336 && class != ADDRESS_OR_EXTENDED_REGS
1337 && class != SP_OR_ADDRESS_OR_EXTENDED_REGS
1338 && (in == stack_pointer_rtx
1339 || (GET_CODE (in) == PLUS
1340 && (XEXP (in, 0) == stack_pointer_rtx
1341 || XEXP (in, 1) == stack_pointer_rtx))))
1342 return ADDRESS_REGS;
1344 if (GET_CODE (in) == PLUS
1345 && (XEXP (in, 0) == stack_pointer_rtx
1346 || XEXP (in, 1) == stack_pointer_rtx))
1349 return DATA_OR_EXTENDED_REGS;
1353 if (TARGET_AM33_2 && class == FP_REGS
1354 && GET_CODE (in) == MEM && ! OK_FOR_Q (in))
1357 return DATA_OR_EXTENDED_REGS;
1361 /* Otherwise assume no secondary reloads are needed. */
1366 initial_offset (int from, int to)
1368 /* The difference between the argument pointer and the frame pointer
1369 is the size of the callee register save area. */
1370 if (from == ARG_POINTER_REGNUM && to == FRAME_POINTER_REGNUM)
1372 if (regs_ever_live[2] || regs_ever_live[3]
1373 || regs_ever_live[6] || regs_ever_live[7]
1374 || regs_ever_live[14] || regs_ever_live[15]
1375 || regs_ever_live[16] || regs_ever_live[17]
1376 || fp_regs_to_save ()
1377 || frame_pointer_needed)
1378 return REG_SAVE_BYTES
1379 + 4 * fp_regs_to_save ();
1384 /* The difference between the argument pointer and the stack pointer is
1385 the sum of the size of this function's frame, the callee register save
1386 area, and the fixed stack space needed for function calls (if any). */
1387 if (from == ARG_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1389 if (regs_ever_live[2] || regs_ever_live[3]
1390 || regs_ever_live[6] || regs_ever_live[7]
1391 || regs_ever_live[14] || regs_ever_live[15]
1392 || regs_ever_live[16] || regs_ever_live[17]
1393 || fp_regs_to_save ()
1394 || frame_pointer_needed)
1395 return (get_frame_size () + REG_SAVE_BYTES
1396 + 4 * fp_regs_to_save ()
1397 + (current_function_outgoing_args_size
1398 ? current_function_outgoing_args_size + 4 : 0));
1400 return (get_frame_size ()
1401 + (current_function_outgoing_args_size
1402 ? current_function_outgoing_args_size + 4 : 0));
1405 /* The difference between the frame pointer and stack pointer is the sum
1406 of the size of this function's frame and the fixed stack space needed
1407 for function calls (if any). */
1408 if (from == FRAME_POINTER_REGNUM && to == STACK_POINTER_REGNUM)
1409 return (get_frame_size ()
1410 + (current_function_outgoing_args_size
1411 ? current_function_outgoing_args_size + 4 : 0));
1416 /* Worker function for TARGET_RETURN_IN_MEMORY. */
1419 mn10300_return_in_memory (tree type, tree fntype ATTRIBUTE_UNUSED)
1421 /* Return values > 8 bytes in length in memory. */
1422 return int_size_in_bytes (type) > 8 || TYPE_MODE (type) == BLKmode;
1425 /* Flush the argument registers to the stack for a stdarg function;
1426 return the new argument pointer. */
1428 mn10300_builtin_saveregs (void)
1431 tree fntype = TREE_TYPE (current_function_decl);
1432 int argadj = ((!(TYPE_ARG_TYPES (fntype) != 0
1433 && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
1434 != void_type_node)))
1435 ? UNITS_PER_WORD : 0);
1436 int set = get_varargs_alias_set ();
1439 offset = plus_constant (current_function_arg_offset_rtx, argadj);
1441 offset = current_function_arg_offset_rtx;
1443 mem = gen_rtx_MEM (SImode, current_function_internal_arg_pointer);
1444 set_mem_alias_set (mem, set);
1445 emit_move_insn (mem, gen_rtx_REG (SImode, 0));
1447 mem = gen_rtx_MEM (SImode,
1448 plus_constant (current_function_internal_arg_pointer, 4));
1449 set_mem_alias_set (mem, set);
1450 emit_move_insn (mem, gen_rtx_REG (SImode, 1));
1452 return copy_to_reg (expand_binop (Pmode, add_optab,
1453 current_function_internal_arg_pointer,
1454 offset, 0, 0, OPTAB_LIB_WIDEN));
1458 mn10300_va_start (tree valist, rtx nextarg)
1460 nextarg = expand_builtin_saveregs ();
1461 std_expand_builtin_va_start (valist, nextarg);
1464 /* Return true when a parameter should be passed by reference. */
1467 mn10300_pass_by_reference (CUMULATIVE_ARGS *cum ATTRIBUTE_UNUSED,
1468 enum machine_mode mode, tree type,
1469 bool named ATTRIBUTE_UNUSED)
1471 unsigned HOST_WIDE_INT size;
1474 size = int_size_in_bytes (type);
1476 size = GET_MODE_SIZE (mode);
1481 /* Return an RTX to represent where a value with mode MODE will be returned
1482 from a function. If the result is 0, the argument is pushed. */
1485 function_arg (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1486 tree type, int named ATTRIBUTE_UNUSED)
1491 /* We only support using 2 data registers as argument registers. */
1494 /* Figure out the size of the object to be passed. */
1495 if (mode == BLKmode)
1496 size = int_size_in_bytes (type);
1498 size = GET_MODE_SIZE (mode);
1500 /* Figure out the alignment of the object to be passed. */
1503 cum->nbytes = (cum->nbytes + 3) & ~3;
1505 /* Don't pass this arg via a register if all the argument registers
1507 if (cum->nbytes > nregs * UNITS_PER_WORD)
1510 /* Don't pass this arg via a register if it would be split between
1511 registers and memory. */
1512 if (type == NULL_TREE
1513 && cum->nbytes + size > nregs * UNITS_PER_WORD)
1516 switch (cum->nbytes / UNITS_PER_WORD)
1519 result = gen_rtx_REG (mode, 0);
1522 result = gen_rtx_REG (mode, 1);
1531 /* Return the number of registers to use for an argument passed partially
1532 in registers and partially in memory. */
1535 function_arg_partial_nregs (CUMULATIVE_ARGS *cum, enum machine_mode mode,
1536 tree type, int named ATTRIBUTE_UNUSED)
1540 /* We only support using 2 data registers as argument registers. */
1543 /* Figure out the size of the object to be passed. */
1544 if (mode == BLKmode)
1545 size = int_size_in_bytes (type);
1547 size = GET_MODE_SIZE (mode);
1549 /* Figure out the alignment of the object to be passed. */
1552 cum->nbytes = (cum->nbytes + 3) & ~3;
1554 /* Don't pass this arg via a register if all the argument registers
1556 if (cum->nbytes > nregs * UNITS_PER_WORD)
1559 if (cum->nbytes + size <= nregs * UNITS_PER_WORD)
1562 /* Don't pass this arg via a register if it would be split between
1563 registers and memory. */
1564 if (type == NULL_TREE
1565 && cum->nbytes + size > nregs * UNITS_PER_WORD)
1568 return (nregs * UNITS_PER_WORD - cum->nbytes) / UNITS_PER_WORD;
1571 /* Output a tst insn. */
1573 output_tst (rtx operand, rtx insn)
1578 /* We can save a byte if we can find a register which has the value
1580 temp = PREV_INSN (insn);
1581 while (optimize && temp)
1585 /* We allow the search to go through call insns. We record
1586 the fact that we've past a CALL_INSN and reject matches which
1587 use call clobbered registers. */
1588 if (GET_CODE (temp) == CODE_LABEL
1589 || GET_CODE (temp) == JUMP_INSN
1590 || GET_CODE (temp) == BARRIER)
1593 if (GET_CODE (temp) == CALL_INSN)
1596 if (GET_CODE (temp) == NOTE)
1598 temp = PREV_INSN (temp);
1602 /* It must be an insn, see if it is a simple set. */
1603 set = single_set (temp);
1606 temp = PREV_INSN (temp);
1610 /* Are we setting a data register to zero (this does not win for
1613 If it's a call clobbered register, have we past a call?
1615 Make sure the register we find isn't the same as ourself;
1616 the mn10300 can't encode that.
1618 ??? reg_set_between_p return nonzero anytime we pass a CALL_INSN
1619 so the code to detect calls here isn't doing anything useful. */
1620 if (REG_P (SET_DEST (set))
1621 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
1622 && !reg_set_between_p (SET_DEST (set), temp, insn)
1623 && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
1624 == REGNO_REG_CLASS (REGNO (operand)))
1625 && REGNO_REG_CLASS (REGNO (SET_DEST (set))) != EXTENDED_REGS
1626 && REGNO (SET_DEST (set)) != REGNO (operand)
1628 || !call_used_regs[REGNO (SET_DEST (set))]))
1631 xoperands[0] = operand;
1632 xoperands[1] = SET_DEST (set);
1634 output_asm_insn ("cmp %1,%0", xoperands);
1638 if (REGNO_REG_CLASS (REGNO (operand)) == EXTENDED_REGS
1639 && REG_P (SET_DEST (set))
1640 && SET_SRC (set) == CONST0_RTX (GET_MODE (SET_DEST (set)))
1641 && !reg_set_between_p (SET_DEST (set), temp, insn)
1642 && (REGNO_REG_CLASS (REGNO (SET_DEST (set)))
1643 != REGNO_REG_CLASS (REGNO (operand)))
1644 && REGNO_REG_CLASS (REGNO (SET_DEST (set))) == EXTENDED_REGS
1645 && REGNO (SET_DEST (set)) != REGNO (operand)
1647 || !call_used_regs[REGNO (SET_DEST (set))]))
1650 xoperands[0] = operand;
1651 xoperands[1] = SET_DEST (set);
1653 output_asm_insn ("cmp %1,%0", xoperands);
1656 temp = PREV_INSN (temp);
1662 impossible_plus_operand (rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1664 if (GET_CODE (op) != PLUS)
1667 if (XEXP (op, 0) == stack_pointer_rtx
1668 || XEXP (op, 1) == stack_pointer_rtx)
1674 /* Return 1 if X is a CONST_INT that is only 8 bits wide. This is used
1675 for the btst insn which may examine memory or a register (the memory
1676 variant only allows an unsigned 8 bit integer). */
1678 const_8bit_operand (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1680 return (GET_CODE (op) == CONST_INT
1682 && INTVAL (op) < 256);
1685 /* Return true if the operand is the 1.0f constant. */
1687 const_1f_operand (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1689 return (op == CONST1_RTX (SFmode));
1692 /* Similarly, but when using a zero_extract pattern for a btst where
1693 the source operand might end up in memory. */
1695 mask_ok_for_mem_btst (int len, int bit)
1697 unsigned int mask = 0;
1706 /* MASK must bit into an 8bit value. */
1707 return (((mask & 0xff) == mask)
1708 || ((mask & 0xff00) == mask)
1709 || ((mask & 0xff0000) == mask)
1710 || ((mask & 0xff000000) == mask));
1713 /* Return 1 if X contains a symbolic expression. We know these
1714 expressions will have one of a few well defined forms, so
1715 we need only check those forms. */
1717 symbolic_operand (register rtx op, enum machine_mode mode ATTRIBUTE_UNUSED)
1719 switch (GET_CODE (op))
1726 return ((GET_CODE (XEXP (op, 0)) == SYMBOL_REF
1727 || GET_CODE (XEXP (op, 0)) == LABEL_REF)
1728 && GET_CODE (XEXP (op, 1)) == CONST_INT);
1734 /* Try machine dependent ways of modifying an illegitimate address
1735 to be legitimate. If we find one, return the new valid address.
1736 This macro is used in only one place: `memory_address' in explow.c.
1738 OLDX is the address as it was before break_out_memory_refs was called.
1739 In some cases it is useful to look at this to decide what needs to be done.
1741 MODE and WIN are passed so that this macro can use
1742 GO_IF_LEGITIMATE_ADDRESS.
1744 Normally it is always safe for this macro to do nothing. It exists to
1745 recognize opportunities to optimize the output.
1747 But on a few ports with segmented architectures and indexed addressing
1748 (mn10300, hppa) it is used to rewrite certain problematical addresses. */
1750 legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED,
1751 enum machine_mode mode ATTRIBUTE_UNUSED)
1753 if (flag_pic && ! legitimate_pic_operand_p (x))
1754 x = legitimize_pic_address (oldx, NULL_RTX);
1756 /* Uh-oh. We might have an address for x[n-100000]. This needs
1757 special handling to avoid creating an indexed memory address
1758 with x-100000 as the base. */
1759 if (GET_CODE (x) == PLUS
1760 && symbolic_operand (XEXP (x, 1), VOIDmode))
1762 /* Ugly. We modify things here so that the address offset specified
1763 by the index expression is computed first, then added to x to form
1764 the entire address. */
1766 rtx regx1, regy1, regy2, y;
1768 /* Strip off any CONST. */
1770 if (GET_CODE (y) == CONST)
1773 if (GET_CODE (y) == PLUS || GET_CODE (y) == MINUS)
1775 regx1 = force_reg (Pmode, force_operand (XEXP (x, 0), 0));
1776 regy1 = force_reg (Pmode, force_operand (XEXP (y, 0), 0));
1777 regy2 = force_reg (Pmode, force_operand (XEXP (y, 1), 0));
1778 regx1 = force_reg (Pmode,
1779 gen_rtx_fmt_ee (GET_CODE (y), Pmode, regx1, regy2));
1780 return force_reg (Pmode, gen_rtx_PLUS (Pmode, regx1, regy1));
1786 /* Convert a non-PIC address in `orig' to a PIC address using @GOT or
1787 @GOTOFF in `reg'. */
1789 legitimize_pic_address (rtx orig, rtx reg)
1791 if (GET_CODE (orig) == LABEL_REF
1792 || (GET_CODE (orig) == SYMBOL_REF
1793 && (CONSTANT_POOL_ADDRESS_P (orig)
1794 || ! MN10300_GLOBAL_P (orig))))
1797 reg = gen_reg_rtx (Pmode);
1799 emit_insn (gen_symGOTOFF2reg (reg, orig));
1802 else if (GET_CODE (orig) == SYMBOL_REF)
1805 reg = gen_reg_rtx (Pmode);
1807 emit_insn (gen_symGOT2reg (reg, orig));
1813 /* Return zero if X references a SYMBOL_REF or LABEL_REF whose symbol
1814 isn't protected by a PIC unspec; nonzero otherwise. */
1816 legitimate_pic_operand_p (rtx x)
1818 register const char *fmt;
1821 if (GET_CODE (x) == SYMBOL_REF || GET_CODE (x) == LABEL_REF)
1824 if (GET_CODE (x) == UNSPEC
1825 && (XINT (x, 1) == UNSPEC_PIC
1826 || XINT (x, 1) == UNSPEC_GOT
1827 || XINT (x, 1) == UNSPEC_GOTOFF
1828 || XINT (x, 1) == UNSPEC_PLT))
1831 fmt = GET_RTX_FORMAT (GET_CODE (x));
1832 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1838 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1839 if (! legitimate_pic_operand_p (XVECEXP (x, i, j)))
1842 else if (fmt[i] == 'e' && ! legitimate_pic_operand_p (XEXP (x, i)))
1849 /* Return TRUE if the address X, taken from a (MEM:MODE X) rtx, is
1850 legitimate, and FALSE otherwise. */
1852 legitimate_address_p (enum machine_mode mode, rtx x, int strict)
1854 if (CONSTANT_ADDRESS_P (x)
1855 && (! flag_pic || legitimate_pic_operand_p (x)))
1858 if (RTX_OK_FOR_BASE_P (x, strict))
1862 && GET_CODE (x) == POST_INC
1863 && RTX_OK_FOR_BASE_P (XEXP (x, 0), strict)
1864 && (mode == SImode || mode == SFmode || mode == HImode))
1867 if (GET_CODE (x) == PLUS)
1869 rtx base = 0, index = 0;
1871 if (REG_P (XEXP (x, 0))
1872 && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x, 0)), strict))
1875 index = XEXP (x, 1);
1878 if (REG_P (XEXP (x, 1))
1879 && REGNO_STRICT_OK_FOR_BASE_P (REGNO (XEXP (x, 1)), strict))
1882 index = XEXP (x, 0);
1885 if (base != 0 && index != 0)
1887 if (GET_CODE (index) == CONST_INT)
1889 if (GET_CODE (index) == CONST
1891 || legitimate_pic_operand_p (index)))
1900 mn10300_address_cost_1 (rtx x, int *unsig)
1902 switch (GET_CODE (x))
1905 switch (REGNO_REG_CLASS (REGNO (x)))
1931 return (mn10300_address_cost_1 (XEXP (x, 0), unsig)
1932 + mn10300_address_cost_1 (XEXP (x, 1), unsig));
1937 return mn10300_address_cost (XEXP (x, 0));
1941 return mn10300_address_cost_1 (XEXP (x, 0), unsig);
1944 if (INTVAL (x) == 0)
1946 if (INTVAL (x) + (*unsig ? 0 : 0x80) < 0x100)
1948 if (INTVAL (x) + (*unsig ? 0 : 0x8000) < 0x10000)
1950 if (INTVAL (x) + (*unsig ? 0 : 0x800000) < 0x1000000)
1966 mn10300_address_cost (rtx x)
1969 return mn10300_address_cost_1 (x, &s);
1973 mn10300_rtx_costs (rtx x, int code, int outer_code, int *total)
1978 /* Zeros are extremely cheap. */
1979 if (INTVAL (x) == 0 && outer_code == SET)
1981 /* If it fits in 8 bits, then it's still relatively cheap. */
1982 else if (INT_8_BITS (INTVAL (x)))
1984 /* This is the "base" cost, includes constants where either the
1985 upper or lower 16bits are all zeros. */
1986 else if (INT_16_BITS (INTVAL (x))
1987 || (INTVAL (x) & 0xffff) == 0
1988 || (INTVAL (x) & 0xffff0000) == 0)
1997 /* These are more costly than a CONST_INT, but we can relax them,
1998 so they're less costly than a CONST_DOUBLE. */
2003 /* We don't optimize CONST_DOUBLEs well nor do we relax them well,
2004 so their cost is very high. */
2008 /* ??? This probably needs more work. */
2020 /* Check whether a constant used to initialize a DImode or DFmode can
2021 use a clr instruction. The code here must be kept in sync with
2025 mn10300_wide_const_load_uses_clr (rtx operands[2])
2029 if (GET_CODE (operands[0]) != REG
2030 || REGNO_REG_CLASS (REGNO (operands[0])) != DATA_REGS)
2033 switch (GET_CODE (operands[1]))
2038 split_double (operands[1], &low, &high);
2039 val[0] = INTVAL (low);
2040 val[1] = INTVAL (high);
2045 if (GET_MODE (operands[1]) == DFmode)
2049 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
2050 REAL_VALUE_TO_TARGET_DOUBLE (rv, val);
2052 else if (GET_MODE (operands[1]) == VOIDmode
2053 || GET_MODE (operands[1]) == DImode)
2055 val[0] = CONST_DOUBLE_LOW (operands[1]);
2056 val[1] = CONST_DOUBLE_HIGH (operands[1]);
2064 return val[0] == 0 || val[1] == 0;
2066 /* If using PIC, mark a SYMBOL_REF for a non-global symbol so that we
2067 may access it using GOTOFF instead of GOT. */
2070 mn10300_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
2074 if (GET_CODE (rtl) != MEM)
2076 symbol = XEXP (rtl, 0);
2077 if (GET_CODE (symbol) != SYMBOL_REF)
2081 SYMBOL_REF_FLAG (symbol) = (*targetm.binds_local_p) (decl);