From patchwork Thu Jul 12 06:52:14 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: 170578 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 45F582C020C for ; Thu, 12 Jul 2012 16:52:31 +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=1342680751; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=+ujrwSU fK7Eoi2RJ6BjDHiweLhs=; b=GjZiMeIzkAoRvA6OuoCEI1UHFV+DzkVCMMqWWtF 1vVd3P7NmVP8QB71NywmDJItr6La3q1xoFvoh2psjtjbRsz9c6ohXwGzhQNrykk8 RiywRJ4IvNUhjSIa2QhTqbB/r7qOUSoi1tzkbRg1fyS1866fiy5bhUMfLfvL1yPU lbMk= 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:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=v5tQ5OsjL1cqHZnlg0WG63IMMRDoB1/73KAkp9ALcDH7xpZfKv9OB6Sww3uO5J jyHj7slGuo3/HI0++iHerMsLwyirOs0grd7ragislDKFbNJLnlvpjMFIUSX6VYQ/ YViE7dO7m9nhF9q5AneDbj8AS0J/rxSkbFltruT+enmdY=; Received: (qmail 30758 invoked by alias); 12 Jul 2012 06:52:27 -0000 Received: (qmail 30748 invoked by uid 22791); 12 Jul 2012 06:52:25 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, FROM_12LTRDOM, KHOP_RCVD_UNTRUST, 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; Thu, 12 Jul 2012 06:52:12 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1SpDFz-00014Z-UM from ChungLin_Tang@mentor.com for gcc-patches@gcc.gnu.org; Wed, 11 Jul 2012 23:52:11 -0700 Received: from SVR-ORW-FEM-05.mgc.mentorg.com ([147.34.97.43]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Wed, 11 Jul 2012 23:51:17 -0700 Received: from [0.0.0.0] (147.34.91.1) by svr-orw-fem-05.mgc.mentorg.com (147.34.97.43) with Microsoft SMTP Server id 14.1.289.1; Wed, 11 Jul 2012 23:52:10 -0700 Message-ID: <4FFE741E.7080506@codesourcery.com> Date: Thu, 12 Jul 2012 14:52:14 +0800 From: Chung-Lin Tang User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH 1/6] Thread pointer built-in functions, core parts 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 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