]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Implement __builtin_thread_pointer for TLS.
authorchenxiaolong <chenxiaolong@loongson.cn>
Tue, 24 Oct 2023 06:40:14 +0000 (14:40 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Thu, 26 Oct 2023 06:05:16 +0000 (14:05 +0800)
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.

(cherry picked from commit 1b30ef7cea773e0af527dbf821e0be42b6a264f8)

gcc/config/loongarch/loongarch.md
gcc/doc/extend.texi
gcc/testsuite/gcc.target/loongarch/builtin_thread_pointer.c [new file with mode: 0644]

index 43c3578b6db44417fd30a36198b81ce6bf0d9c79..830eaaea90e4a0f5328c8b56a92433014614e03d 100644 (file)
 
 (define_constants
   [(RETURN_ADDR_REGNUM         1)
+   (TP_REGNUM                  2)
    (T0_REGNUM                  12)
    (T1_REGNUM                  13)
    (S0_REGNUM                  23)
   [(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")]
index 7a3b5454724a023db2db57857c8cbd7d548e7ade..12c5ca507ed5bc05b3449ad62b7509ca9e8e0d38 100644 (file)
@@ -16332,6 +16332,11 @@ function you need to include @code{larchintrin.h}.
     void __break (imm0_32767)
 @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 (file)
index 0000000..541e3b1
--- /dev/null
@@ -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 ();
+}