Core parts adding the new hooks. BUILT_IN_THREAD_POINTER and
BUILT_IN_SET_THREAD_POINTER are different hooks, as some targets only
implement one of them (thread pointer read).

Thanks,
Chung-Lin

        * targhooks.c (default_expand_builtin_thread_pointer): New.
        (default_expand_builtin_set_thread_pointer): New.
        * targhooks.h (default_expand_builtin_thread_pointer): New.
        (default_expand_builtin_set_thread_pointer): New.
        * target.def (expand_builtin_thread_pointer): New target hook.
        (expand_builtin_set_thread_pointer): New target hook.
        * builtins.c (expand_builtin_thread_pointer): New.
        (expand_builtin_set_thread_pointer): New.
        (expand_builtin): Add BUILT_IN_THREAD_POINTER,
        BUILT_IN_SET_THREAD_POINTER expand cases.
        * builtins.def (BUILT_IN_THREAD_POINTER):
        New __builtin_thread_pointer builtin.
        (BUILT_IN_SET_THREAD_POINTER):
        New __builtin_set_thread_pointer builtin.
        * doc/tm.texi.in: Add BUILT_IN_THREAD_POINTER,
        BUILT_IN_SET_THREAD_POINTER hook entries.
        * doc/tm.texi: Update.
Index: target.def
===================================================================
--- target.def  (revision 189431)
+++ target.def  (working copy)
@@ -2668,6 +2668,22 @@ DEFHOOK
  enum unwind_info_type, (void),
  default_debug_unwind_info)
 
+/* Expand builtin function for returning TLS thread pointer.  */
+DEFHOOK
+(expand_builtin_thread_pointer,
+ "This hook expands the built-in function for reading\
+ the TLS thread pointer, if supported on the target.",
+ rtx, (rtx),
+ default_expand_builtin_thread_pointer)
+
+/* Expand builtin function for setting TLS thread pointer.  */
+DEFHOOK
+(expand_builtin_set_thread_pointer,
+ "This hook expands the built-in function for setting\
+ the TLS thread pointer, if supported on the target.",
+ void, (rtx),
+ default_expand_builtin_set_thread_pointer)
+
 DEFHOOKPOD
 (atomic_test_and_set_trueval,
  "This value should be set if the result written by\
Index: targhooks.c
===================================================================
--- targhooks.c (revision 189431)
+++ targhooks.c (working copy)
@@ -1456,4 +1456,17 @@ default_pch_valid_p (const void *data_p, size_t le
   return NULL;
 }
 
+rtx
+default_expand_builtin_thread_pointer (rtx target ATTRIBUTE_UNUSED)
+{
+  sorry ("__builtin_thread_pointer() not available for this target");
+  return NULL;
+}
+
+void
+default_expand_builtin_set_thread_pointer (rtx val ATTRIBUTE_UNUSED)
+{
+  sorry ("__builtin_set_thread_pointer() not available for this target");
+}
+
 #include "gt-targhooks.h"
Index: targhooks.h
===================================================================
--- targhooks.h (revision 189431)
+++ targhooks.h (working copy)
@@ -179,5 +179,8 @@ extern enum machine_mode default_get_reg_raw_mode(
 extern void *default_get_pch_validity (size_t *);
 extern const char *default_pch_valid_p (const void *, size_t);
 
+extern rtx default_expand_builtin_thread_pointer (rtx);
+extern void default_expand_builtin_set_thread_pointer (rtx);
+
 extern void default_asm_output_ident_directive (const char*);
 
Index: builtins.c
===================================================================
--- builtins.c  (revision 189431)
+++ builtins.c  (working copy)
@@ -5760,6 +5760,27 @@ expand_builtin_sync_synchronize (void)
   expand_mem_thread_fence (MEMMODEL_SEQ_CST);
 }
 
+static rtx
+expand_builtin_thread_pointer (tree exp, rtx target)
+{
+  if (!validate_arglist (exp, VOID_TYPE))
+    return const0_rtx;
+  if (!REG_P (target) || GET_MODE (target) != Pmode)
+    target = gen_reg_rtx (Pmode);
+  target = targetm.expand_builtin_thread_pointer (target);
+  return (target ? target : const0_rtx);
+}
+
+static void
+expand_builtin_set_thread_pointer (tree exp)
+{
+  rtx val;
+  if (!validate_arglist (exp, POINTER_TYPE, VOID_TYPE))
+    return;
+  val = expand_expr (CALL_EXPR_ARG (exp, 0), NULL_RTX, Pmode, EXPAND_NORMAL);
+  targetm.expand_builtin_set_thread_pointer (val);
+}
+
 
 /* Expand an expression EXP that calls a built-in function,
    with result going to TARGET if that's convenient
@@ -6825,6 +6846,13 @@ expand_builtin (tree exp, rtx target, rtx subtarge
        maybe_emit_free_warning (exp);
       break;
 
+    case BUILT_IN_THREAD_POINTER:
+      return expand_builtin_thread_pointer (exp, target);
+
+    case BUILT_IN_SET_THREAD_POINTER:
+      expand_builtin_set_thread_pointer (exp);
+      return const0_rtx;
+
     default:   /* just do library call, if unknown builtin */
       break;
     }
Index: builtins.def
===================================================================
--- builtins.def        (revision 189431)
+++ builtins.def        (working copy)
@@ -782,6 +782,17 @@ DEF_BUILTIN (BUILT_IN_PROFILE_FUNC_ENTER, "__cyg_p
 DEF_BUILTIN (BUILT_IN_PROFILE_FUNC_EXIT, "__cyg_profile_func_exit", 
BUILT_IN_NORMAL, BT_FN_VOID_PTR_PTR, BT_LAST,
             false, false, false, ATTR_NULL, true, true)
 
+/* TLS thread pointer related builtins.  */
+DEF_BUILTIN (BUILT_IN_THREAD_POINTER, "__builtin_thread_pointer",
+            BUILT_IN_NORMAL, BT_FN_PTR, BT_LAST,
+            false, false, true, ATTR_CONST_NOTHROW_LIST, true,
+            targetm.have_tls)
+
+DEF_BUILTIN (BUILT_IN_SET_THREAD_POINTER, "__builtin_set_thread_pointer",
+            BUILT_IN_NORMAL, BT_FN_VOID_PTR, BT_LAST,
+            false, false, true, ATTR_NOTHROW_LIST, true,
+            targetm.have_tls)
+
 /* TLS emulation.  */
 DEF_BUILTIN (BUILT_IN_EMUTLS_GET_ADDRESS, targetm.emutls.get_address,
             BUILT_IN_NORMAL,
Index: doc/tm.texi
===================================================================
--- doc/tm.texi (revision 189431)
+++ doc/tm.texi (working copy)
@@ -11293,3 +11293,11 @@ memory model bits are allowed.
 @deftypevr {Target Hook} {unsigned char} TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
 This value should be set if the result written by @code{atomic_test_and_set} 
is not exactly 1, i.e. the @code{bool} @code{true}.
 @end deftypevr
+
+@deftypefn {Target Hook} rtx TARGET_EXPAND_BUILTIN_THREAD_POINTER (rtx)
+This hook expands the built-in function for reading the TLS thread pointer, if 
supported on the target.
+@end deftypefn
+
+@deftypefn {Target Hook} void TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER (rtx)
+This hook expands the built-in function for setting the TLS thread pointer, if 
supported on the target.
+@end deftypefn
Index: doc/tm.texi.in
===================================================================
--- doc/tm.texi.in      (revision 189431)
+++ doc/tm.texi.in      (working copy)
@@ -11165,3 +11165,7 @@ memory model bits are allowed.
 @end deftypefn
 
 @hook TARGET_ATOMIC_TEST_AND_SET_TRUEVAL
+
+@hook TARGET_EXPAND_BUILTIN_THREAD_POINTER
+
+@hook TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER

Reply via email to