From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2100) id 50D253877036; Sat, 22 Aug 2020 23:27:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50D253877036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1598138864; bh=4Hg8AIDv2M7Ie9fwrzB4xHj6dQ4RiTzvrrOlQvKuQ9w=; h=From:To:Subject:Date:From; b=vhlkGIBKlWfrzfxxo1oeoPOyurSKqNvF5gXOJNt8P52+Y0e0CgtYdniMDIi+GuZsW b3KKovNoiLTzvjJ1UKQSnzToqnhGXhhxEsniUgUKjAisFe2p2Jss47hT9xS/ZnbdE5 o/SpR+qJWdmehkRYAfT0ZATpXR18/rPik3aumY9A= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Giuliano Belinassi To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/autopar_devel] RISC-V: Implement __builtin_thread_pointer X-Act-Checkin: gcc X-Git-Author: Kito Cheng X-Git-Refname: refs/heads/devel/autopar_devel X-Git-Oldrev: 8c5c300fc850259752265e87eea81b8cd8759f06 X-Git-Newrev: 3e65ce625e7bcb64eed9634fdf73fb87d9337c9f Message-Id: <20200822232744.50D253877036@sourceware.org> Date: Sat, 22 Aug 2020 23:27:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Aug 2020 23:27:44 -0000 https://gcc.gnu.org/g:3e65ce625e7bcb64eed9634fdf73fb87d9337c9f commit 3e65ce625e7bcb64eed9634fdf73fb87d9337c9f Author: Kito Cheng Date: Tue Jul 7 16:20:53 2020 +0800 RISC-V: Implement __builtin_thread_pointer RISC-V has a dedicate register for thread pointer which is specified in psABI doc, so we could support __builtin_thread_pointer in straightforward way. Note: clang/llvm was supported __builtin_thread_pointer for RISC-V port recently. - https://reviews.llvm.org/rGaabc24acf0d5f8677bd22fe9c108581e07c3e180 gcc/ChangeLog: * config/riscv/riscv.md (get_thread_pointer): New. (TP_REGNUM): Ditto. * doc/extend.texi (Target Builtins): Add RISC-V built-in section. Document __builtin_thread_pointer. gcc/testsuite/ChangeLog: * gcc.target/riscv/read-thread-pointer.c: New. Diff: --- gcc/config/riscv/riscv.md | 8 ++++++++ gcc/doc/extend.texi | 11 +++++++++++ gcc/testsuite/gcc.target/riscv/read-thread-pointer.c | 7 +++++++ 3 files changed, 26 insertions(+) diff --git a/gcc/config/riscv/riscv.md b/gcc/config/riscv/riscv.md index 36012ad1f77..95a02ecaa34 100644 --- a/gcc/config/riscv/riscv.md +++ b/gcc/config/riscv/riscv.md @@ -70,6 +70,7 @@ (define_constants [(RETURN_ADDR_REGNUM 1) (GP_REGNUM 3) + (TP_REGNUM 4) (T0_REGNUM 5) (T1_REGNUM 6) (S0_REGNUM 8) @@ -2515,6 +2516,13 @@ DONE; }) +;; Named pattern for expanding thread pointer reference. +(define_expand "get_thread_pointer" + [(set (match_operand:P 0 "register_operand" "=r") + (reg:P TP_REGNUM))] + "" +{}) + (include "sync.md") (include "peephole.md") (include "pic.md") diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 3f92171a3b1..d1510dd3f36 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -13859,6 +13859,7 @@ instructions, but allow the compiler to schedule those calls. * PowerPC Hardware Transactional Memory Built-in Functions:: * PowerPC Atomic Memory Operation Functions:: * PowerPC Matrix-Multiply Assist Built-in Functions:: +* RISC-V Built-in Functions:: * RX Built-in Functions:: * S/390 System z Built-in Functions:: * SH Built-in Functions:: @@ -21471,6 +21472,16 @@ vec_t __builtin_vsx_xvcvspbf16 (vec_t); vec_t __builtin_vsx_xvcvbf16sp (vec_t); @end smallexample +@node RISC-V Built-in Functions +@subsection RISC-V Built-in Functions + +These built-in functions are available for the RISC-V family of +processors. + +@deftypefn {Built-in Function} {void *} __builtin_thread_pointer (void) +Returns the value that is currently set in the @samp{tp} register. +@end deftypefn + @node RX Built-in Functions @subsection RX Built-in Functions GCC supports some of the RX instructions which cannot be expressed in diff --git a/gcc/testsuite/gcc.target/riscv/read-thread-pointer.c b/gcc/testsuite/gcc.target/riscv/read-thread-pointer.c new file mode 100644 index 00000000000..760f8eafb40 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/read-thread-pointer.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ + +void *get_tp() +{ + return __builtin_thread_pointer (); +} +/* { dg-final { scan-assembler "mv\[ \t\]*[at][0-9]+,tp" } } */