Revision | 2c5d8f7b95da577e030a8d61c81c0550887d28c4 (tree) |
---|---|
Time | 2022-11-25 21:00:18 |
Author | Yoshinori Sato <yo-satoh@sios...> |
Commiter | Yoshinori Sato |
Merge branch 'rx-pic' into rx-fdpic
@@ -172,6 +172,7 @@ rx_find_use_of_reg (rtx reg, rtx_insn* insn, F stepfunc) | ||
172 | 172 | #endif |
173 | 173 | |
174 | 174 | bool nonpic_symbol_mentioned_p (rtx x); |
175 | -void rx_expand_sym_label2reg (rtx reg, rtx sym, rtx lab, bool sibcall_p); | |
175 | +rtx legitimize_pic_address (rtx orig, | |
176 | + machine_mode mode ATTRIBUTE_UNUSED, rtx reg); | |
176 | 177 | |
177 | 178 | #endif /* GCC_RX_PROTOS_H */ |
@@ -143,11 +143,9 @@ rx_pid_data_operand (rtx op) | ||
143 | 143 | return PID_NOT_PID; |
144 | 144 | } |
145 | 145 | |
146 | -rtx | |
147 | -legitimize_pic_address (rtx orig, machine_mode mode ATTRIBUTE_UNUSED, rtx reg); | |
148 | - | |
149 | 146 | static rtx |
150 | -rx_legitimize_address (rtx x, rtx oldx , | |
147 | +rx_legitimize_address (rtx x, | |
148 | + rtx oldx ATTRIBUTE_UNUSED, | |
151 | 149 | machine_mode mode ATTRIBUTE_UNUSED) |
152 | 150 | { |
153 | 151 | if (flag_pic) |
@@ -168,6 +166,32 @@ rx_legitimize_address (rtx x, rtx oldx , | ||
168 | 166 | return x; |
169 | 167 | } |
170 | 168 | |
169 | +/* Convert a non-PIC address in `orig' to a PIC address using @GOT or | |
170 | + @GOTOFF in `reg'. */ | |
171 | +rtx | |
172 | +legitimize_pic_address (rtx orig, machine_mode mode ATTRIBUTE_UNUSED, rtx reg) | |
173 | +{ | |
174 | + if (GET_CODE (orig) == LABEL_REF || GET_CODE (orig) == SYMBOL_REF) | |
175 | + { | |
176 | + if (reg == NULL_RTX) | |
177 | + reg = gen_reg_rtx (Pmode); | |
178 | + | |
179 | + emit_insn (gen_symGOTOFF2reg (reg, orig)); | |
180 | + crtl->uses_pic_offset_table = 1; | |
181 | + return reg; | |
182 | + } | |
183 | + else if (GET_CODE (orig) == SYMBOL_REF) | |
184 | + { | |
185 | + if (reg == NULL_RTX) | |
186 | + reg = gen_reg_rtx (Pmode); | |
187 | + | |
188 | + emit_insn (gen_symGOT2reg (reg, orig)); | |
189 | + crtl->uses_pic_offset_table = 1; | |
190 | + return reg; | |
191 | + } | |
192 | + return orig; | |
193 | +} | |
194 | + | |
171 | 195 | /* Return true if OP is a reference to an object in a small data area. */ |
172 | 196 | |
173 | 197 | static bool |
@@ -303,44 +327,18 @@ nonpic_symbol_mentioned_p (rtx x) | ||
303 | 327 | for (int i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) |
304 | 328 | { |
305 | 329 | if (fmt[i] == 'E') |
306 | - { | |
330 | + { | |
307 | 331 | for (int j = XVECLEN (x, i) - 1; j >= 0; j--) |
308 | 332 | if (nonpic_symbol_mentioned_p (XVECEXP (x, i, j))) |
309 | 333 | return true; |
310 | - } | |
334 | + } | |
311 | 335 | else if (fmt[i] == 'e' && nonpic_symbol_mentioned_p (XEXP (x, i))) |
312 | - return true; | |
336 | + return true; | |
313 | 337 | } |
314 | 338 | |
315 | 339 | return false; |
316 | 340 | } |
317 | 341 | |
318 | -/* Convert a non-PIC address in `orig' to a PIC address using @GOT or | |
319 | - @GOTOFF in `reg'. */ | |
320 | -rtx | |
321 | -legitimize_pic_address (rtx orig, machine_mode mode ATTRIBUTE_UNUSED, rtx reg) | |
322 | -{ | |
323 | - if (GET_CODE (orig) == LABEL_REF || GET_CODE (orig) == SYMBOL_REF) | |
324 | - { | |
325 | - if (reg == NULL_RTX) | |
326 | - reg = gen_reg_rtx (Pmode); | |
327 | - | |
328 | - emit_insn (gen_symGOTOFF2reg (reg, orig)); | |
329 | - crtl->uses_pic_offset_table = 1; | |
330 | - return reg; | |
331 | - } | |
332 | - else if (GET_CODE (orig) == SYMBOL_REF) | |
333 | - { | |
334 | - if (reg == NULL_RTX) | |
335 | - reg = gen_reg_rtx (Pmode); | |
336 | - | |
337 | - emit_insn (gen_symGOT2reg (reg, orig)); | |
338 | - crtl->uses_pic_offset_table = 1; | |
339 | - return reg; | |
340 | - } | |
341 | - return orig; | |
342 | -} | |
343 | - | |
344 | 342 | /* Returns TRUE for simple memory addresses, ie ones |
345 | 343 | that do not involve register indirect addressing |
346 | 344 | or pre/post increment/decrement. */ |
@@ -536,10 +534,8 @@ rx_print_operand_address (FILE * file, machine_mode /*mode*/, rtx addr) | ||
536 | 534 | switch (post) |
537 | 535 | { |
538 | 536 | case UNSPEC_GOTOFF: |
539 | - fprintf (file, "#"); | |
540 | 537 | output_addr_const (file, addr); |
541 | 538 | fprintf (file, "@GOTOFF"); |
542 | - crtl->uses_pic_offset_table = 1; | |
543 | 539 | return; |
544 | 540 | } |
545 | 541 | } |
@@ -598,8 +594,8 @@ rx_assemble_integer (rtx x, unsigned int size, int is_aligned) | ||
598 | 594 | %P Register used for PID addressing |
599 | 595 | %Q If the operand is a MEM, then correctly generate |
600 | 596 | register indirect or register relative addressing. |
601 | - %R Like %Q but for zero-extending loads. | |
602 | - %T symbol@PLT */ | |
597 | + %R Like %Q but for zero-extending loads. */ | |
598 | + | |
603 | 599 | |
604 | 600 | static void |
605 | 601 | rx_print_operand (FILE * file, rtx op, int letter) |
@@ -886,20 +882,6 @@ rx_print_operand (FILE * file, rtx op, int letter) | ||
886 | 882 | } |
887 | 883 | break; |
888 | 884 | } |
889 | - case 'T': | |
890 | - /* Print an operand and @PLT. */ | |
891 | - if (MEM_P (op)) | |
892 | - op = XEXP (op, 0); | |
893 | - | |
894 | - switch (GET_CODE (op)) | |
895 | - { | |
896 | - case LABEL_REF: | |
897 | - case SYMBOL_REF: | |
898 | - output_addr_const (file, op); | |
899 | - fprintf (file, "@PLT"); | |
900 | - break; | |
901 | - } | |
902 | - break; | |
903 | 885 | |
904 | 886 | /* Fall through. */ |
905 | 887 |
@@ -1030,47 +1012,6 @@ rx_print_operand (FILE * file, rtx op, int letter) | ||
1030 | 1012 | } |
1031 | 1013 | } |
1032 | 1014 | |
1033 | -/* Implement TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA. */ | |
1034 | -static bool | |
1035 | -rx_asm_output_addr_const_extra (FILE *file, rtx x) | |
1036 | -{ | |
1037 | - if (GET_CODE (x) == UNSPEC) | |
1038 | - { | |
1039 | - switch (XINT (x, 1)) | |
1040 | - { | |
1041 | - case UNSPEC_PIC: | |
1042 | - /* GLOBAL_OFFSET_TABLE or local symbols, no suffix. */ | |
1043 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1044 | - break; | |
1045 | - case UNSPEC_GOT: | |
1046 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1047 | - fputs ("@GOT", file); | |
1048 | - break; | |
1049 | - case UNSPEC_GOTOFF: | |
1050 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1051 | - fputs ("@GOTOFF", file); | |
1052 | - break; | |
1053 | - case UNSPEC_PLT: | |
1054 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1055 | - fputs ("@PLT", file); | |
1056 | - break; | |
1057 | - case UNSPEC_GOTPLT: | |
1058 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1059 | - fputs ("@GOTPLT", file); | |
1060 | - break; | |
1061 | - case UNSPEC_PCREL: | |
1062 | - output_addr_const (file, XVECEXP (x, 0, 0)); | |
1063 | - fputs ("@PCREL", file); | |
1064 | - break; | |
1065 | - default: | |
1066 | - return false; | |
1067 | - } | |
1068 | - return true; | |
1069 | - } | |
1070 | - else | |
1071 | - return false; | |
1072 | -} | |
1073 | - | |
1074 | 1015 | /* Maybe convert an operand into its PID format. */ |
1075 | 1016 | |
1076 | 1017 | rtx |
@@ -1634,8 +1575,8 @@ rx_get_stack_layout (unsigned int * lowest, | ||
1634 | 1575 | they can be used in the fast interrupt handler without |
1635 | 1576 | saving them on the stack. */ |
1636 | 1577 | || (is_fast_interrupt_func (NULL_TREE) |
1637 | - && ! IN_RANGE (reg, 10, 13))) | |
1638 | 1578 | || (flag_pic && reg == PIC_REGNUM)) |
1579 | + && ! IN_RANGE (reg, 10, 13))) | |
1639 | 1580 | { |
1640 | 1581 | if (low == 0) |
1641 | 1582 | low = reg; |
@@ -1906,9 +1847,6 @@ rx_expand_prologue (void) | ||
1906 | 1847 | else if (low) |
1907 | 1848 | push_regs (high, low); |
1908 | 1849 | |
1909 | - // if (flag_pic && df_regs_ever_live_p (PIC_REGNUM)) | |
1910 | - // emit_insn (gen_GOTaddr2picreg (const0_rtx)); | |
1911 | - | |
1912 | 1850 | if (MUST_SAVE_ACC_REGISTER) |
1913 | 1851 | { |
1914 | 1852 | unsigned int acc_high, acc_low; |
@@ -3103,9 +3041,9 @@ rx_is_legitimate_constant (machine_mode mode ATTRIBUTE_UNUSED, rtx x) | ||
3103 | 3041 | |
3104 | 3042 | case UNSPEC: |
3105 | 3043 | return XINT (x, 1) == UNSPEC_CONST || |
3106 | - XINT (x, 1) == UNSPEC_PID_ADDR || | |
3107 | - XINT (x, 1) == UNSPEC_GOTOFF || | |
3108 | - XINT (x, 1) == UNSPEC_PLT; | |
3044 | + XINT (x, 1) == UNSPEC_PID_ADDR || | |
3045 | + XINT (x, 1) == UNSPEC_GOTOFF || | |
3046 | + XINT (x, 1) == UNSPEC_PLT; | |
3109 | 3047 | |
3110 | 3048 | default: |
3111 | 3049 | /* FIXME: Can this ever happen ? */ |
@@ -3807,11 +3745,6 @@ int rx_legitimate_pic_operand_p(rtx x) | ||
3807 | 3745 | || ! nonpic_symbol_mentioned_p (get_pool_constant (x))))); |
3808 | 3746 | } |
3809 | 3747 | |
3810 | -static void | |
3811 | -rx_asm_final_postscan_insn (FILE *, rtx_insn *insn, rtx operands[], int num_rtx) | |
3812 | -{ | |
3813 | - return; | |
3814 | -} | |
3815 | 3748 | |
3816 | 3749 | #undef TARGET_NARROW_VOLATILE_BITFIELD |
3817 | 3750 | #define TARGET_NARROW_VOLATILE_BITFIELD rx_narrow_volatile_bitfield |
@@ -3971,13 +3904,6 @@ rx_asm_final_postscan_insn (FILE *, rtx_insn *insn, rtx operands[], int num_rtx) | ||
3971 | 3904 | #undef TARGET_HAVE_SPECULATION_SAFE_VALUE |
3972 | 3905 | #define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed |
3973 | 3906 | |
3974 | -#undef TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA | |
3975 | -#define TARGET_ASM_OUTPUT_ADDR_CONST_EXTRA rx_asm_output_addr_const_extra | |
3976 | - | |
3977 | -#undef TARGET_ASM_FINAL_POSTSCAN_INSN | |
3978 | -#define TARGET_ASM_FINAL_POSTSCAN_INSN rx_asm_final_postscan_insn | |
3979 | - | |
3980 | 3907 | struct gcc_target targetm = TARGET_INITIALIZER; |
3981 | 3908 | |
3982 | 3909 | #include "gt-rx.h" |
3983 | - |
@@ -650,7 +650,7 @@ typedef unsigned int CUMULATIVE_ARGS; | ||
650 | 650 | /* We can't directly access anything that contains a symbol, |
651 | 651 | nor can we indirect via the constant pool. */ |
652 | 652 | int rx_legitimate_pic_operand_p(rtx x); |
653 | -#define LEGITIMATE_PIC_OPERAND_P(X) \ | |
653 | +#define LEGITIMATE_PIC_OPERAND_P(X) \ | |
654 | 654 | rx_legitimate_pic_operand_p (X) |
655 | 655 | |
656 | 656 | #define SYMBOLIC_CONST_P(X) \ |
@@ -460,39 +460,31 @@ | ||
460 | 460 | (set_attr "timings" "33")] |
461 | 461 | ) |
462 | 462 | |
463 | -(define_expand "call_site" | |
464 | - [(unspec [(match_dup 0)] 0)] | |
465 | - "" | |
466 | -{ | |
467 | - static HOST_WIDE_INT i = 0; | |
468 | - operands[0] = GEN_INT (i); | |
469 | - i++; | |
470 | -}) | |
471 | - | |
472 | 463 | (define_expand "call_value" |
473 | 464 | [(set (match_operand 0 "register_operand") |
474 | 465 | (call (match_operand:QI 1 "general_operand") |
475 | 466 | (match_operand:SI 2 "general_operand")))] |
476 | 467 | "" |
477 | - { | |
478 | - rtx dest = XEXP (operands[1], 0); | |
468 | +{ | |
469 | + rtx dest = XEXP (operands[1], 0); | |
479 | 470 | |
480 | - if (! rx_call_operand (dest, Pmode)) | |
481 | - dest = force_reg (Pmode, dest); | |
482 | - if (1 || !flag_pic || !(GET_CODE (dest) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (dest))) | |
483 | - emit_call_insn (gen_call_value_internal (operands[0], dest)); | |
484 | - else | |
485 | - { | |
486 | - if (TARGET_JSR) | |
487 | - emit_call_insn (gen_call_value_got (operands[0], dest)); | |
488 | - else { | |
489 | - printf("%s\n", __func__); | |
490 | - emit_call_insn (gen_call_value_plt (dest)); | |
491 | - } | |
492 | - } | |
493 | - DONE; | |
494 | - } | |
495 | -) | |
471 | + if (flag_pic && | |
472 | + (GET_CODE (dest) == SYMBOL_REF) && (!SYMBOL_REF_LOCAL_P (dest))) | |
473 | + { | |
474 | + if (flag_plt) | |
475 | + emit_call_insn (gen_call_value_internal_plt (operands[0], dest)); | |
476 | + else | |
477 | + emit_call_insn (gen_call_value_internal_got (operands[0], dest)); | |
478 | + DONE; | |
479 | + } | |
480 | + else | |
481 | + { | |
482 | + if (! rx_call_operand (dest, Pmode)) | |
483 | + dest = force_reg (Pmode, dest); | |
484 | + emit_call_insn (gen_call_value_internal (operands[0], dest)); | |
485 | + } | |
486 | + DONE; | |
487 | +}) | |
496 | 488 | |
497 | 489 | (define_insn "call_value_internal" |
498 | 490 | [(set (match_operand 0 "register_operand" "=r,r") |
@@ -2924,45 +2916,73 @@ | ||
2924 | 2916 | "" |
2925 | 2917 | "") |
2926 | 2918 | |
2927 | -(define_insn "mov_from_rirb" | |
2928 | - [(match_operand 0 "" "") (match_operand 1 "" "")] | |
2929 | - "" | |
2930 | -{ | |
2931 | - return "mov.l\t[%0,%1],%0"; | |
2932 | -} | |
2933 | -) | |
2934 | - | |
2935 | 2919 | (define_expand "symGOTOFF2reg" |
2936 | 2920 | [(match_operand 0 "" "") (match_operand 1 "" "")] |
2937 | 2921 | "" |
2938 | 2922 | { |
2939 | 2923 | rtx gotoffsym; |
2940 | 2924 | rtx t = (!can_create_pseudo_p () |
2941 | - ? operands[0] | |
2942 | - : gen_reg_rtx (GET_MODE (operands[0]))); | |
2925 | + ? operands[0] | |
2926 | + : gen_reg_rtx (GET_MODE (operands[0]))); | |
2943 | 2927 | |
2944 | 2928 | rtx picreg = gen_rtx_REG (Pmode, PIC_REG); |
2945 | 2929 | |
2946 | 2930 | gotoffsym = gen_sym2GOTOFF (operands[1]); |
2947 | - emit_move_insn (t, gotoffsym); | |
2931 | + emit_insn (gen_mov_from_got(t, picreg, gotoffsym)); | |
2948 | 2932 | emit_move_insn (operands[0], t); |
2949 | - emit_insn(gen_mov_from_rirb(operands[0], picreg)); | |
2933 | + //emit_insn(gen_mov_from_rirb(operands[0], picreg)); | |
2950 | 2934 | // set_unique_reg_note (insn, REG_EQUAL, operands[1]); |
2951 | 2935 | DONE; |
2952 | 2936 | }) |
2953 | 2937 | |
2954 | -(define_expand "sym2PIC" | |
2955 | - [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PIC))] | |
2938 | +(define_insn "mov_from_got" | |
2939 | + [(match_operand 0 "register_operand" "r") | |
2940 | + (match_operand 1 "register_operand" "r") | |
2941 | + (match_operand 2 "" "g")] | |
2956 | 2942 | "" |
2957 | - "") | |
2943 | + "mov.l\t%A2[%1],%0" | |
2944 | +) | |
2958 | 2945 | |
2959 | 2946 | (define_insn "loadGOT" |
2960 | 2947 | [(set (match_operand:SI 0 "register_operand" "=r") |
2961 | - (unspec:SI [(const_int 0)] UNSPEC_GOT))] | |
2948 | + (unspec:SI [(const_int 0)] UNSPEC_GOT))] | |
2962 | 2949 | "" |
2963 | 2950 | { |
2964 | 2951 | return "mvfc\tpc,%0\n\tadd\t#_GLOBAL_OFFSET_TABLE_,%0"; |
2965 | -} | |
2952 | +}) | |
2953 | + | |
2954 | +(define_expand "call_value_internal_got" | |
2955 | + [(set (match_operand 0 "register_operand" "=r,r") | |
2956 | + (call (mem:QI (match_operand:SI 1 "rx_call_operand" "r,CALL_OP_SYMBOL_REF")) | |
2957 | + (const_int 0))) | |
2958 | + (clobber (reg:CC CC_REG))] | |
2959 | + "" | |
2960 | +{ | |
2961 | + rtx gotoffsym; | |
2962 | + rtx t = (!can_create_pseudo_p () | |
2963 | + ? operands[0] | |
2964 | + : gen_reg_rtx (GET_MODE (operands[0]))); | |
2965 | + | |
2966 | + rtx picreg = gen_rtx_REG (Pmode, PIC_REG); | |
2967 | + | |
2968 | + gotoffsym = gen_sym2GOTOFF (operands[1]); | |
2969 | + emit_move_insn (t, gotoffsym); | |
2970 | + emit_insn (gen_mov_from_got(t, picreg, gotoffsym)); | |
2971 | + emit_move_insn (operands[0], t); | |
2972 | + emit_call_insn (gen_call_internal (operands[0])); | |
2973 | + DONE; | |
2974 | +}) | |
2975 | + | |
2976 | +(define_insn "call_value_internal_plt" | |
2977 | + [(set (match_operand 0 "register_operand" "=r") | |
2978 | + (call (mem:QI (match_operand:SI 1 "rx_symbolic_call_operand" "")) | |
2979 | + (const_int 0))) | |
2980 | + (use (reg:SI PIC_REG)) | |
2981 | + (clobber (reg:CC CC_REG))] | |
2982 | + "" | |
2983 | + "bsr\t%A1@PLT" | |
2984 | + [(set_attr "length" "4") | |
2985 | + (set_attr "timings" "33")] | |
2966 | 2986 | ) |
2967 | 2987 | |
2968 | 2988 | (define_expand "call_value_got" |
@@ -2981,8 +3001,8 @@ | ||
2981 | 3001 | |
2982 | 3002 | gotoffsym = gen_sym2GOTOFF (operands[1]); |
2983 | 3003 | emit_move_insn (t, gotoffsym); |
3004 | + emit_insn (gen_mov_from_got(t, picreg, gotoffsym)); | |
2984 | 3005 | emit_move_insn (operands[0], t); |
2985 | - emit_insn(gen_mov_from_rirb(operands[0], picreg)); | |
2986 | 3006 | emit_call_insn (gen_call_internal (operands[0])); |
2987 | 3007 | DONE; |
2988 | 3008 | }) |