On 12/7/14 9:58 AM, Mike Stump wrote: > On Jul 12, 2012, at 11:47 PM, Chung-Lin Tang <clt...@codesourcery.com> wrote: >>> and then for the return value, maybe a const0_rtx for Pmode. >> >> A little unsure what you mean. Are you referring to return const0_rtx >> for default_expand_builtin_thread_pointer() instead of NULL? > > Yes. NULL has the habit of crashing things if they don't expect it. >
I've addressed this. The expand function still handles the NULL case with a ?: for robustness though. Also removed the '()' in the displayed function names. Patch attached. Thanks, Chung-Lin
Index: target.def =================================================================== --- target.def (revision 189512) +++ target.def (working copy) @@ -2717,6 +2717,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 189512) +++ targhooks.c (working copy) @@ -1514,4 +1514,18 @@ default_pch_valid_p (const void *data_p, size_t le return NULL; } +rtx +default_expand_builtin_thread_pointer (rtx target ATTRIBUTE_UNUSED) +{ + error ("%qs is not available for this target", "__builtin_thread_pointer()"); + return NULL; +} + +void +default_expand_builtin_set_thread_pointer (rtx val ATTRIBUTE_UNUSED) +{ + error ("%qs is not available for this target", + "__builtin_set_thread_pointer()"); +} + #include "gt-targhooks.h" Index: targhooks.h =================================================================== --- targhooks.h (revision 189512) +++ targhooks.h (working copy) @@ -184,5 +184,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 189512) +++ builtins.c (working copy) @@ -5767,6 +5767,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 @@ -6832,6 +6853,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 189512) +++ 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 189512) +++ doc/tm.texi (working copy) @@ -11309,3 +11309,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 189512) +++ doc/tm.texi.in (working copy) @@ -11173,3 +11173,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