Révision | 2269d21b750f07d15e95905ad14d3f3886c64566 (tree) |
---|---|
l'heure | 2022-11-24 19:25:15 |
Auteur | Yoshinori Sato <yo-satoh@sios...> |
Commiter | Yoshinori Sato |
WIP: rx plt
Signed-off-by: Yoshinori Sato <yo-satoh@sios.com>
@@ -172,5 +172,6 @@ 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 | 176 | |
176 | 177 | #endif /* GCC_RX_PROTOS_H */ |
@@ -540,7 +540,6 @@ rx_print_operand_address (FILE * file, machine_mode /*mode*/, rtx addr) | ||
540 | 540 | output_addr_const (file, addr); |
541 | 541 | fprintf (file, "@GOTOFF"); |
542 | 542 | crtl->uses_pic_offset_table = 1; |
543 | - printf("%s %p %d\n", __func__, &(crtl->uses_pic_offset_table), crtl->uses_pic_offset_table); | |
544 | 543 | return; |
545 | 544 | } |
546 | 545 | } |
@@ -599,7 +598,8 @@ rx_assemble_integer (rtx x, unsigned int size, int is_aligned) | ||
599 | 598 | %P Register used for PID addressing |
600 | 599 | %Q If the operand is a MEM, then correctly generate |
601 | 600 | register indirect or register relative addressing. |
602 | - %R Like %Q but for zero-extending loads. */ | |
601 | + %R Like %Q but for zero-extending loads. | |
602 | + %T symbol@PLT */ | |
603 | 603 | |
604 | 604 | static void |
605 | 605 | rx_print_operand (FILE * file, rtx op, int letter) |
@@ -886,6 +886,20 @@ rx_print_operand (FILE * file, rtx op, int letter) | ||
886 | 886 | } |
887 | 887 | break; |
888 | 888 | } |
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; | |
889 | 903 | |
890 | 904 | /* Fall through. */ |
891 | 905 |
@@ -1092,7 +1106,6 @@ rx_gen_move_template (rtx * operands, bool is_movu) | ||
1092 | 1106 | rtx dest = operands[0]; |
1093 | 1107 | rtx src = operands[1]; |
1094 | 1108 | |
1095 | - printf("%s\n", __func__); | |
1096 | 1109 | /* Decide which extension, if any, should be given to the move instruction. */ |
1097 | 1110 | switch (CONST_INT_P (src) ? GET_MODE (dest) : GET_MODE (src)) |
1098 | 1111 | { |
@@ -2483,6 +2496,7 @@ rx_select_section (tree decl, | ||
2483 | 2496 | |
2484 | 2497 | return default_elf_select_section (decl, reloc, align); |
2485 | 2498 | } |
2499 | + | |
2486 | 2500 | |
2487 | 2501 | enum rx_builtin |
2488 | 2502 | { |
@@ -3090,7 +3104,8 @@ rx_is_legitimate_constant (machine_mode mode ATTRIBUTE_UNUSED, rtx x) | ||
3090 | 3104 | case UNSPEC: |
3091 | 3105 | return XINT (x, 1) == UNSPEC_CONST || |
3092 | 3106 | XINT (x, 1) == UNSPEC_PID_ADDR || |
3093 | - XINT (x, 1) == UNSPEC_GOTOFF; | |
3107 | + XINT (x, 1) == UNSPEC_GOTOFF || | |
3108 | + XINT (x, 1) == UNSPEC_PLT; | |
3094 | 3109 | |
3095 | 3110 | default: |
3096 | 3111 | /* FIXME: Can this ever happen ? */ |
@@ -460,6 +460,15 @@ | ||
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 | + | |
463 | 472 | (define_expand "call_value" |
464 | 473 | [(set (match_operand 0 "register_operand") |
465 | 474 | (call (match_operand:QI 1 "general_operand") |
@@ -470,10 +479,17 @@ | ||
470 | 479 | |
471 | 480 | if (! rx_call_operand (dest, Pmode)) |
472 | 481 | dest = force_reg (Pmode, dest); |
473 | - if (!flag_pic || !(GET_CODE (dest) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (dest))) | |
482 | + if (1 || !flag_pic || !(GET_CODE (dest) == SYMBOL_REF && !SYMBOL_REF_LOCAL_P (dest))) | |
474 | 483 | emit_call_insn (gen_call_value_internal (operands[0], dest)); |
475 | 484 | else |
476 | - emit_call_insn (gen_call_value_pcrel (operands[0], dest)); | |
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 | + } | |
477 | 493 | DONE; |
478 | 494 | } |
479 | 495 | ) |
@@ -2889,26 +2905,6 @@ | ||
2889 | 2905 | ) |
2890 | 2906 | |
2891 | 2907 | ;; PIC stuff |
2892 | - | |
2893 | -(define_expand "sym_label2reg" | |
2894 | - [(set (match_operand:SI 0 "" "") | |
2895 | - (const:SI (unspec:SI [(match_operand:SI 1 "" "") | |
2896 | - (const (plus:SI (match_operand:SI 2 "" "") | |
2897 | - (const_int 2)))] | |
2898 | - UNSPEC_SYMOFF)))] | |
2899 | - "" | |
2900 | - "") | |
2901 | - | |
2902 | -(define_expand "symPCREL_label2reg" | |
2903 | - [(set (match_operand:SI 0 "" "") | |
2904 | - (const:SI | |
2905 | - (unspec:SI | |
2906 | - [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PCREL)) | |
2907 | - (const:SI (plus:SI (match_operand:SI 2 "" "") | |
2908 | - (const_int 2)))] UNSPEC_PCREL_SYMOFF)))] | |
2909 | - "" | |
2910 | - "") | |
2911 | - | |
2912 | 2908 | (define_expand "sym2GOT" |
2913 | 2909 | [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOT))] |
2914 | 2910 | "" |
@@ -2923,17 +2919,6 @@ | ||
2923 | 2919 | DONE; |
2924 | 2920 | }) |
2925 | 2921 | |
2926 | -(define_expand "symGOTPLT2reg" | |
2927 | - [(match_operand 0 "" "") (match_operand 1 "" "")] | |
2928 | - "" | |
2929 | -{ | |
2930 | - rtx pltsym = gen_rtx_CONST (Pmode, | |
2931 | - gen_rtx_UNSPEC (Pmode, | |
2932 | - gen_rtvec (1, operands[1]), | |
2933 | - UNSPEC_GOTPLT)); | |
2934 | - DONE; | |
2935 | -}) | |
2936 | - | |
2937 | 2922 | (define_expand "sym2GOTOFF" |
2938 | 2923 | [(const (unspec [(match_operand 0 "" "")] UNSPEC_GOTOFF))] |
2939 | 2924 | "" |
@@ -2966,28 +2951,6 @@ | ||
2966 | 2951 | DONE; |
2967 | 2952 | }) |
2968 | 2953 | |
2969 | -(define_expand "symPLT_label2reg" | |
2970 | - [(set (match_operand:SI 0 "" "") | |
2971 | - (const:SI | |
2972 | - (unspec:SI | |
2973 | - [(const:SI (unspec:SI [(match_operand:SI 1 "" "")] UNSPEC_PLT)) | |
2974 | - (const:SI (plus:SI (match_operand:SI 2 "" "") | |
2975 | - (const_int 2)))] UNSPEC_PCREL_SYMOFF))) | |
2976 | - ;; Even though the PIC register is not really used by the call | |
2977 | - ;; sequence in which this is expanded, the PLT code assumes the PIC | |
2978 | - ;; register is set, so we must not skip its initialization. Since | |
2979 | - ;; we only use this expand as part of calling sequences, and never | |
2980 | - ;; to take the address of a function, this is the best point to | |
2981 | - ;; insert the (use). Using the PLT to take the address of a | |
2982 | - ;; function would be wrong, not only because the PLT entry could | |
2983 | - ;; then be called from a function that doesn't initialize the PIC | |
2984 | - ;; register to the proper GOT, but also because pointers to the | |
2985 | - ;; same function might not compare equal, should they be set by | |
2986 | - ;; different shared libraries. | |
2987 | - (use (reg:SI PIC_REG))] | |
2988 | - "" | |
2989 | - "") | |
2990 | - | |
2991 | 2954 | (define_expand "sym2PIC" |
2992 | 2955 | [(const (unspec [(match_operand:SI 0 "" "")] UNSPEC_PIC))] |
2993 | 2956 | "" |
@@ -3002,7 +2965,7 @@ | ||
3002 | 2965 | } |
3003 | 2966 | ) |
3004 | 2967 | |
3005 | -(define_expand "call_value_pcrel" | |
2968 | +(define_expand "call_value_got" | |
3006 | 2969 | [(set (match_operand 0 "register_operand" "=r,r") |
3007 | 2970 | (call (mem:QI (match_operand:SI 1 "rx_call_operand" "r,CALL_OP_SYMBOL_REF")) |
3008 | 2971 | (const_int 0))) |
@@ -3023,3 +2986,13 @@ | ||
3023 | 2986 | emit_call_insn (gen_call_internal (operands[0])); |
3024 | 2987 | DONE; |
3025 | 2988 | }) |
2989 | + | |
2990 | +(define_insn "call_value_plt" | |
2991 | + [(call (mem:QI (match_operand:SI 0 "rx_call_operand" "CALL_OP_SYMBOL_REF")) | |
2992 | + (const_int 0)) | |
2993 | + (clobber (reg:CC CC_REG))] | |
2994 | + "" | |
2995 | + "bsr\t%T0" | |
2996 | + [(set_attr "length" "4") | |
2997 | + (set_attr "timings" "33")] | |
2998 | +) |