From patchwork Mon Jul 16 10:02:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chung-Lin Tang X-Patchwork-Id: 171150 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B78AC2C00F7 for ; Mon, 16 Jul 2012 20:03:08 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1343037790; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=ymZYhsQS1icvBLJQ39mY9O64AGs=; b=JyU4z7txjUZV0OKPVyZjKz9n/fcqyq65Y2me218wVp5YWM1aDl/UMdSXYlI+o0 0O/DIpOOReugqBB2hpDUoNmgbEfKHfQHNQwpTdMMqomHUoG5Cw092VFumRH6zBb0 e6oA38L7AI67d+mgQ/NtqAFYsY6HVQWZPcyXtdftouijA= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=SMwlKWldcyz3tpQMEEP7WkIQnvylIgH/LksTKUVMWK3O5YKtWSPXvnFFLCI2io TWlvc5l1kyUj3bMKde7Osyp6B2bYphYcEV7fGXg7UOjoJQQNcfs5AN9X1CQd3kU/ JJRh+LvtBlxDHekQWNLKniKpF/nMqwtEn2Rm8GBUsxpL4=; Received: (qmail 31417 invoked by alias); 16 Jul 2012 10:03:03 -0000 Received: (qmail 31375 invoked by uid 22791); 16 Jul 2012 10:03:01 -0000 X-SWARE-Spam-Status: No, hits=-4.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_HOSTKARMA_W, RCVD_IN_HOSTKARMA_WL X-Spam-Check-By: sourceware.org Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 16 Jul 2012 10:02:46 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1Sqi8Z-0003rI-VM from ChungLin_Tang@mentor.com ; Mon, 16 Jul 2012 03:02:43 -0700 Received: from SVR-ORW-FEM-03.mgc.mentorg.com ([147.34.97.39]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Mon, 16 Jul 2012 03:01:46 -0700 Received: from [0.0.0.0] (147.34.91.1) by svr-orw-fem-03.mgc.mentorg.com (147.34.97.39) with Microsoft SMTP Server id 14.1.289.1; Mon, 16 Jul 2012 03:02:42 -0700 Message-ID: <5003E6C1.7070002@codesourcery.com> Date: Mon, 16 Jul 2012 18:02:41 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Mike Stump CC: gcc-patches , Richard Sandiford Subject: Re: [PATCH 1/6] Thread pointer built-in functions, core parts References: <4FFE741E.7080506@codesourcery.com> <08E650FE-14AA-4348-9C5C-FCD2F91307F0@comcast.net> <4FFFC489.5030704@codesourcery.com> In-Reply-To: X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On 12/7/14 9:58 AM, Mike Stump wrote: > On Jul 12, 2012, at 11:47 PM, Chung-Lin Tang 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