public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v1] LoongArch: Implement __builtin_thread_pointer for TLS.
@ 2023-10-24  6:40 chenxiaolong
  2023-10-25 13:12 ` [pushed][PATCH " chenglulu
  0 siblings, 1 reply; 2+ messages in thread
From: chenxiaolong @ 2023-10-24  6:40 UTC (permalink / raw)
  To: gcc-patches; +Cc: xry111, i, xuchenghua, chenglulu, chenxiaolong

gcc/ChangeLog:

	* config/loongarch/loongarch.md (get_thread_pointer<mode>):Adds the
        instruction template corresponding to the __builtin_thread_pointer
        function.
	* doc/extend.texi:Add the __builtin_thread_pointer function support
        description to the documentation.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/builtin_thread_pointer.c: New test.
---
 gcc/config/loongarch/loongarch.md                      |  7 +++++++
 gcc/doc/extend.texi                                    |  5 +++++
 .../gcc.target/loongarch/builtin_thread_pointer.c      | 10 ++++++++++
 3 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c

diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
index 13473472171..4dd716e1941 100644
--- a/gcc/config/loongarch/loongarch.md
+++ b/gcc/config/loongarch/loongarch.md
@@ -113,6 +113,7 @@ (define_c_enum "unspecv" [
 
 (define_constants
   [(RETURN_ADDR_REGNUM		1)
+   (TP_REGNUM			2)
    (T0_REGNUM			12)
    (T1_REGNUM			13)
    (S0_REGNUM			23)
@@ -3647,6 +3648,12 @@ (define_insn "@stack_tie<mode>"
   [(set_attr "length" "0")
    (set_attr "type" "ghost")])
 
+;; Named pattern for expanding thread pointer reference.
+(define_expand "get_thread_pointer<mode>"
+  [(set (match_operand:P 0 "register_operand" "=r")
+	(reg:P TP_REGNUM))]
+  "HAVE_AS_TLS"
+  {})
 \f
 (define_split
   [(match_operand 0 "small_data_pattern")]
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index bf941e6b93a..9923a18bde9 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -16749,6 +16749,11 @@ __float128 __builtin_nanq (void);
 __float128 __builtin_nansq (void);
 @end smallexample
 
+Returns the value that is currently set in the @samp{tp} register.
+@smallexample
+    void * __builtin_thread_pointer (void)
+@end smallexample
+
 @node MIPS DSP Built-in Functions
 @subsection MIPS DSP Built-in Functions
 
diff --git a/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c
new file mode 100644
index 00000000000..541e3b143bd
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-options "-O2" } */
+/* { dg-final { scan-assembler "or\t\\\$r4,\\\$r2,\\\$r0" } } */
+
+void *
+get_tp ()
+{
+  return __builtin_thread_pointer ();
+}
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pushed][PATCH v1] LoongArch: Implement __builtin_thread_pointer for TLS.
  2023-10-24  6:40 [PATCH v1] LoongArch: Implement __builtin_thread_pointer for TLS chenxiaolong
@ 2023-10-25 13:12 ` chenglulu
  0 siblings, 0 replies; 2+ messages in thread
From: chenglulu @ 2023-10-25 13:12 UTC (permalink / raw)
  To: chenxiaolong, gcc-patches; +Cc: xry111, i, xuchenghua

Pushed to r14-4925.

在 2023/10/24 下午2:40, chenxiaolong 写道:
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.md (get_thread_pointer<mode>):Adds the
>          instruction template corresponding to the __builtin_thread_pointer
>          function.
> 	* doc/extend.texi:Add the __builtin_thread_pointer function support
>          description to the documentation.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/loongarch/builtin_thread_pointer.c: New test.
> ---
>   gcc/config/loongarch/loongarch.md                      |  7 +++++++
>   gcc/doc/extend.texi                                    |  5 +++++
>   .../gcc.target/loongarch/builtin_thread_pointer.c      | 10 ++++++++++
>   3 files changed, 22 insertions(+)
>   create mode 100644 gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c
>
> diff --git a/gcc/config/loongarch/loongarch.md b/gcc/config/loongarch/loongarch.md
> index 13473472171..4dd716e1941 100644
> --- a/gcc/config/loongarch/loongarch.md
> +++ b/gcc/config/loongarch/loongarch.md
> @@ -113,6 +113,7 @@ (define_c_enum "unspecv" [
>   
>   (define_constants
>     [(RETURN_ADDR_REGNUM		1)
> +   (TP_REGNUM			2)
>      (T0_REGNUM			12)
>      (T1_REGNUM			13)
>      (S0_REGNUM			23)
> @@ -3647,6 +3648,12 @@ (define_insn "@stack_tie<mode>"
>     [(set_attr "length" "0")
>      (set_attr "type" "ghost")])
>   
> +;; Named pattern for expanding thread pointer reference.
> +(define_expand "get_thread_pointer<mode>"
> +  [(set (match_operand:P 0 "register_operand" "=r")
> +	(reg:P TP_REGNUM))]
> +  "HAVE_AS_TLS"
> +  {})
>   \f
>   (define_split
>     [(match_operand 0 "small_data_pattern")]
> diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
> index bf941e6b93a..9923a18bde9 100644
> --- a/gcc/doc/extend.texi
> +++ b/gcc/doc/extend.texi
> @@ -16749,6 +16749,11 @@ __float128 __builtin_nanq (void);
>   __float128 __builtin_nansq (void);
>   @end smallexample
>   
> +Returns the value that is currently set in the @samp{tp} register.
> +@smallexample
> +    void * __builtin_thread_pointer (void)
> +@end smallexample
> +
>   @node MIPS DSP Built-in Functions
>   @subsection MIPS DSP Built-in Functions
>   
> diff --git a/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c
> new file mode 100644
> index 00000000000..541e3b143bd
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c
> @@ -0,0 +1,10 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target tls_native } */
> +/* { dg-options "-O2" } */
> +/* { dg-final { scan-assembler "or\t\\\$r4,\\\$r2,\\\$r0" } } */
> +
> +void *
> +get_tp ()
> +{
> +  return __builtin_thread_pointer ();
> +}


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-25 13:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-24  6:40 [PATCH v1] LoongArch: Implement __builtin_thread_pointer for TLS chenxiaolong
2023-10-25 13:12 ` [pushed][PATCH " chenglulu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).