public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [AArch64][TLSGD Trad][1/2] Generalize TLS Global Dynamic support for all memory mode
@ 2015-06-19 14:59 Jiong Wang
  2015-08-27  9:55 ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Jiong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jiong Wang @ 2015-06-19 14:59 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1447 bytes --]


Currently, there is only small model support for TLS GD on
AArch64. While TLS Global Dynamic (Traditional) is actually the same for
all memory mode. 

For TLSGD, the code logic is always the following:

RegA = GOT descriptor address of tls variable.
call __tls_get_addr/
nop

Instruction sequences for different memory model differs only for how to
addressing the GOT descriptor of that TLS variable, and they should
always be packed together for later linker relaxation.

Tiny
==    
adr  a0, :tlsgd:x

Small
==
adrp a0, :tlsgd:x
add  a0, a0, #:tlsgd_lo12:x

Large
==
movz a0, #:tlsgd_g1:x
movk a0, #:tlsgd_g0_nc:x
add  a0, gp, a0

This patch generalize TLS GD code for all memory model and remove the
duplicated define_expand. Another seperate patch will add GD support for
Tiny model.

OK for trunk?

2015-06-19  Jiong Wang  <jiong.wang@arm.com>

gcc/
  * config/aarch64/aarch64-protos.h (aarch64_symbol_context): Rename
  SYMBOL_SMALL_TLSGD to SYMBOL_TLSGD.
  (aarch64_symbol_context): Ditto.
  * config/aarch64/aarch64.md (tlsgd_small): Deleted.
  (*tlsgd_small): Renamed into "tlsgd".
  (UNSPEC_TLSGD): New.
  * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Rename
  SYMBOL_SMALL_TLSGD to SYMBOL_TLSGD. Update parameter for gen_tlsgd.
  (aarch64_expand_mov_immediate): Ditto.
  (aarch64_print_operand): Ditto.
  (aarch64_classify_tls_symbol): Ditto.
-- 
Regards,
Jiong


[-- Attachment #2: tlsgdtrad1.patch --]
[-- Type: text/x-diff, Size: 4161 bytes --]

commit c1ed4442a4d81db8a421b74c6a9d65c69e095779
Author: Jiong Wang <jiong.wang@arm.com>
Date:   Mon May 18 16:48:33 2015 +0100

    Generalize GD

diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 7b5c86e1..7fad48b 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -61,10 +61,10 @@ enum aarch64_symbol_context
 
    This corresponds to the small PIC model of the compiler.
 
-   SYMBOL_SMALL_TLSGD
    SYMBOL_SMALL_TLSDESC
    SYMBOL_SMALL_GOTTPREL
    SYMBOL_TINY_TLSIE
+   SYMBOL_TLSGD
    SYMBOL_TLSLE
    Each of of these represents a thread-local symbol, and corresponds to the
    thread local storage relocation operator for the symbol being referred to.
@@ -96,12 +96,12 @@ enum aarch64_symbol_type
 {
   SYMBOL_SMALL_ABSOLUTE,
   SYMBOL_SMALL_GOT,
-  SYMBOL_SMALL_TLSGD,
   SYMBOL_SMALL_TLSDESC,
   SYMBOL_SMALL_GOTTPREL,
   SYMBOL_TINY_ABSOLUTE,
   SYMBOL_TINY_GOT,
   SYMBOL_TINY_TLSIE,
+  SYMBOL_TLSGD,
   SYMBOL_TLSLE,
   SYMBOL_FORCE_TO_MEM
 };
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index be1e83d..e724bd4 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -905,13 +905,14 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 	return;
       }
 
-    case SYMBOL_SMALL_TLSGD:
+    case SYMBOL_TLSGD:
       {
 	rtx_insn *insns;
 	rtx result = gen_rtx_REG (Pmode, R0_REGNUM);
+	rtx func = aarch64_tls_get_addr ();
 
 	start_sequence ();
-	aarch64_emit_call_insn (gen_tlsgd_small (result, imm));
+	aarch64_emit_call_insn (gen_tlsgd (result, imm, func));
 	insns = get_insns ();
 	end_sequence ();
 
@@ -1547,7 +1548,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm)
 	  emit_insn (gen_rtx_SET (dest, mem));
 	  return;
 
-        case SYMBOL_SMALL_TLSGD:
+        case SYMBOL_TLSGD:
         case SYMBOL_SMALL_TLSDESC:
         case SYMBOL_SMALL_GOTTPREL:
 	case SYMBOL_SMALL_GOT:
@@ -4430,7 +4431,7 @@ aarch64_print_operand (FILE *f, rtx x, char code)
 	    asm_fprintf (asm_out_file, ":got:");
 	  break;
 
-	case SYMBOL_SMALL_TLSGD:
+	case SYMBOL_TLSGD:
 	  asm_fprintf (asm_out_file, ":tlsgd:");
 	  break;
 
@@ -4463,7 +4464,7 @@ aarch64_print_operand (FILE *f, rtx x, char code)
 	  asm_fprintf (asm_out_file, ":lo12:");
 	  break;
 
-	case SYMBOL_SMALL_TLSGD:
+	case SYMBOL_TLSGD:
 	  asm_fprintf (asm_out_file, ":tlsgd_lo12:");
 	  break;
 
@@ -7272,7 +7273,7 @@ aarch64_classify_tls_symbol (rtx x)
     {
     case TLS_MODEL_GLOBAL_DYNAMIC:
     case TLS_MODEL_LOCAL_DYNAMIC:
-      return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_SMALL_TLSGD;
+      return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_TLSGD;
 
     case TLS_MODEL_INITIAL_EXEC:
       switch (aarch64_cmodel)
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index be9da5b..4fe54c9 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -117,6 +117,7 @@
     UNSPEC_ST4_LANE
     UNSPEC_TLS
     UNSPEC_TLSDESC
+    UNSPEC_TLSGD
     UNSPEC_TLSLE
     UNSPEC_USHL_2S
     UNSPEC_VSTRUCTDUMMY
@@ -4255,20 +4256,10 @@
 ;; The TLS ABI specifically requires that the compiler does not schedule
 ;; instructions in the TLS stubs, in order to enable linker relaxation.
 ;; Therefore we treat the stubs as an atomic sequence.
-(define_expand "tlsgd_small"
- [(parallel [(set (match_operand 0 "register_operand" "")
-                  (call (mem:DI (match_dup 2)) (const_int 1)))
-	     (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "")] UNSPEC_GOTSMALLTLS)
-	     (clobber (reg:DI LR_REGNUM))])]
- ""
-{
-  operands[2] = aarch64_tls_get_addr ();
-})
-
-(define_insn "*tlsgd_small"
+(define_insn "tlsgd"
   [(set (match_operand 0 "register_operand" "")
 	(call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
-   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_GOTSMALLTLS)
+   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_TLSGD)
    (clobber (reg:DI LR_REGNUM))
   ]
   ""

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

* [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional
  2015-06-19 14:59 [AArch64][TLSGD Trad][1/2] Generalize TLS Global Dynamic support for all memory mode Jiong Wang
@ 2015-08-27  9:55 ` Jiong Wang
  2015-08-27 10:04   ` [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model Jiong Wang
  2015-10-06 11:40   ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Marcus Shawcroft
  0 siblings, 2 replies; 8+ messages in thread
From: Jiong Wang @ 2015-08-27  9:55 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 3053 bytes --]


Jiong Wang writes:

> Currently, there is only small model support for TLS GD on
> AArch64. While TLS Global Dynamic (Traditional) is actually the same for
> all memory mode. 
>
> For TLSGD, the code logic is always the following:
>
> RegA = GOT descriptor address of tls variable.
> call __tls_get_addr/
> nop
>
> Instruction sequences for different memory model differs only for how to
> addressing the GOT descriptor of that TLS variable, and they should
> always be packed together for later linker relaxation.
>
> Tiny
> ==    
> adr  a0, :tlsgd:x
>
> Small
> ==
> adrp a0, :tlsgd:x
> add  a0, a0, #:tlsgd_lo12:x
>
> Large
> ==
> movz a0, #:tlsgd_g1:x
> movk a0, #:tlsgd_g0_nc:x
> add  a0, gp, a0
>
> This patch generalize TLS GD code for all memory model and remove the
> duplicated define_expand. Another seperate patch will add GD support for
> Tiny model.
>
> OK for trunk?
>
> 2015-06-19  Jiong Wang  <jiong.wang@arm.com>
>
> gcc/
>   * config/aarch64/aarch64-protos.h (aarch64_symbol_context): Rename
>   SYMBOL_SMALL_TLSGD to SYMBOL_TLSGD.
>   (aarch64_symbol_context): Ditto.
>   * config/aarch64/aarch64.md (tlsgd_small): Deleted.
>   (*tlsgd_small): Renamed into "tlsgd".
>   (UNSPEC_TLSGD): New.
>   * config/aarch64/aarch64.c (aarch64_load_symref_appropriately): Rename
>   SYMBOL_SMALL_TLSGD to SYMBOL_TLSGD. Update parameter for gen_tlsgd.
>   (aarch64_expand_mov_immediate): Ditto.
>   (aarch64_print_operand): Ditto.
>   (aarch64_classify_tls_symbol): Ditto.

Reworked this patch.

The old approach is to generalize the support for global dynamic
traditional on all memory model into one define_insn as them share the
same code logic listed below:

  param_reg = GOT descriptor address for tls variable.
  call __tls_get_addr
  nop

There is one thing bad that we haven't classified GD symbol in the first
place, we was generating different instruction sequences by doing a
final model check in the instruction pattern.

While in the new approach we classify GD symbol into tiny and small
version in the first place, then implement a seperate instruction
pattern for tiny.  The GD code logic is still generalized, because both
tiny and small share the same symbol handling code in aarch64.c.

NOTE: TLS GD for tiny model will utilize the relocation type
BFD_RELOC_AARCH64_TLSGD_ADR_PREL21 which is not available in binutils
2.25 and before, so feature detection is added to make sure GD for tiny
only enabled when there is binutils support, otherwise fall back to GD
for small.

This patch removes the unncessary define_expand "tlsgd_small". It was
there purely because operands[2] need to be generated from another rtx
gen function while it's better to move that to the call site, thus this
redundant expand pattern can be removed.

2015-08-27  Jiong Wang  <jiong.wang@arm.com>

gcc/
  * config/aarch64/aarch64.md (tlsgd_small): Delete this define_expand.
  (*tlsgd_small): Rename this define_insn to "tlsgd_small";

-- 
Regards,
Jiong


[-- Attachment #2: gdt1.patch --]
[-- Type: text/x-diff, Size: 1589 bytes --]

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index c74bf84..988062c 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1028,9 +1028,10 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
       {
 	rtx_insn *insns;
 	rtx result = gen_rtx_REG (Pmode, R0_REGNUM);
+	rtx resolver = aarch64_tls_get_addr ();
 
 	start_sequence ();
-	aarch64_emit_call_insn (gen_tlsgd_small (result, imm));
+	aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
 	insns = get_insns ();
 	end_sequence ();
 
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 80fd6c4..cf787d8 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4474,17 +4474,7 @@
 ;; The TLS ABI specifically requires that the compiler does not schedule
 ;; instructions in the TLS stubs, in order to enable linker relaxation.
 ;; Therefore we treat the stubs as an atomic sequence.
-(define_expand "tlsgd_small"
- [(parallel [(set (match_operand 0 "register_operand" "")
-                  (call (mem:DI (match_dup 2)) (const_int 1)))
-	     (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "")] UNSPEC_GOTSMALLTLS)
-	     (clobber (reg:DI LR_REGNUM))])]
- ""
-{
-  operands[2] = aarch64_tls_get_addr ();
-})
-
-(define_insn "*tlsgd_small"
+(define_insn "tlsgd_small"
   [(set (match_operand 0 "register_operand" "")
 	(call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
    (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_GOTSMALLTLS)

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

* [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
  2015-08-27  9:55 ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Jiong Wang
@ 2015-08-27 10:04   ` Jiong Wang
  2015-10-06 13:32     ` Marcus Shawcroft
  2015-10-06 11:40   ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Marcus Shawcroft
  1 sibling, 1 reply; 8+ messages in thread
From: Jiong Wang @ 2015-08-27 10:04 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]


As described this is the main implementaion patch.

2015-08-26  Jiong Wang  <jiong.wang@arm.com>

gcc/
  * configure.ac: Add check for binutils global dynamic tiny code model
  relocation support.
  * configure: Regenerate.
  * config.in: Regenerate.
  * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
  * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
  enumeration SYMBOL_TINY_TLSGD.
  (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
  * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
  SYMBOL_TINY_TLSGD.
  (aarch64_print_operand): Likewise.
  (aarch64_expand_mov_immediate): Likewise.
  (aarch64_load_symref_appropriately): Likewise.

gcc/testsuite/
  * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
  New effective check.
  * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
  * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.

-- 
Regards,
Jiong


[-- Attachment #2: gdt2.patch --]
[-- Type: text/x-diff, Size: 8517 bytes --]

diff --git a/gcc/config.in b/gcc/config.in
index 22a4e6b..9313e36 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -618,6 +618,13 @@
 #endif
 
 
+/* Define if your assembler supports relocs needed by global dynamic for tiny
+   code model. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_TINY_TLSGD_RELOCS
+#endif
+
+
 /* Define if your assembler and linker support thread-local storage. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_TLS
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index 8fbc204..bdcb9a0 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -74,6 +74,7 @@ enum aarch64_symbol_context
    SYMBOL_SMALL_TLSGD
    SYMBOL_SMALL_TLSDESC
    SYMBOL_SMALL_GOTTPREL
+   SYMBOL_TINY_TLSGD
    SYMBOL_TINY_TLSIE
    SYMBOL_TLSLE12
    SYMBOL_TLSLE24
@@ -115,6 +116,7 @@ enum aarch64_symbol_type
   SYMBOL_SMALL_GOTTPREL,
   SYMBOL_TINY_ABSOLUTE,
   SYMBOL_TINY_GOT,
+  SYMBOL_TINY_TLSGD,
   SYMBOL_TINY_TLSIE,
   SYMBOL_TLSLE12,
   SYMBOL_TLSLE24,
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 988062c..610f3db 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1024,6 +1024,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 	return;
       }
 
+    case SYMBOL_TINY_TLSGD:
     case SYMBOL_SMALL_TLSGD:
       {
 	rtx_insn *insns;
@@ -1031,7 +1032,10 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 	rtx resolver = aarch64_tls_get_addr ();
 
 	start_sequence ();
-	aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
+	if (type == SYMBOL_SMALL_TLSGD)
+	  aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
+	else
+	  aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
 	insns = get_insns ();
 	end_sequence ();
 
@@ -1719,6 +1723,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm)
 	case SYMBOL_SMALL_GOT_28K:
 	case SYMBOL_SMALL_GOT_4G:
 	case SYMBOL_TINY_GOT:
+	case SYMBOL_TINY_TLSGD:
 	case SYMBOL_TINY_TLSIE:
 	  if (offset != const0_rtx)
 	    {
@@ -4594,6 +4599,7 @@ aarch64_print_operand (FILE *f, rtx x, char code)
 	  break;
 
 	case SYMBOL_SMALL_TLSGD:
+	case SYMBOL_TINY_TLSGD:
 	  asm_fprintf (asm_out_file, ":tlsgd:");
 	  break;
 
@@ -8755,6 +8761,22 @@ aarch64_classify_tls_symbol (rtx x)
   switch (tls_kind)
     {
     case TLS_MODEL_GLOBAL_DYNAMIC:
+      if (TARGET_TLS_DESC)
+	return SYMBOL_SMALL_TLSDESC;
+
+      /* Traditional model.  */
+      switch (aarch64_cmodel)
+	{
+	case AARCH64_CMODEL_TINY:
+	case AARCH64_CMODEL_TINY_PIC:
+#ifdef HAVE_AS_TINY_TLSGD_RELOCS
+	  return SYMBOL_TINY_TLSGD;
+#else
+	  return SYMBOL_SMALL_TLSGD;
+#endif
+	default:
+	  return SYMBOL_SMALL_TLSGD;
+	}
     case TLS_MODEL_LOCAL_DYNAMIC:
       return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_SMALL_TLSGD;
 
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index cf787d8..e722590 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4485,6 +4485,17 @@
   [(set_attr "type" "call")
    (set_attr "length" "16")])
 
+(define_insn "tlsgd_tiny"
+  [(set (match_operand 0 "register_operand" "")
+	(call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
+   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_GOTTINYTLS)
+   (clobber (reg:DI LR_REGNUM))
+  ]
+  ""
+  "adr\tx0, %A1;bl\t%2;nop";
+  [(set_attr "type" "multiple")
+   (set_attr "length" "12")])
+
 (define_insn "tlsie_small_<mode>"
   [(set (match_operand:PTR 0 "register_operand" "=r")
         (unspec:PTR [(match_operand 1 "aarch64_tls_ie_symref" "S")]
diff --git a/gcc/configure b/gcc/configure
index cf685f2..82fb331 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24308,6 +24308,41 @@ if test $gcc_cv_as_aarch64_picreloc = yes; then
 $as_echo "#define HAVE_AS_SMALL_PIC_RELOCS 1" >>confdefs.h
 
 fi
+    # Check if we have binutils support for relocations types needed by TLSGD
+    # for tiny code model.
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for global dynamic for tiny relocs" >&5
+$as_echo_n "checking assembler for global dynamic for tiny relocs... " >&6; }
+if test "${gcc_cv_as_aarch64_gdtinyreloc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_aarch64_gdtinyreloc=no
+  if test x$gcc_cv_as != x; then
+    $as_echo '
+	.text
+	adr x0, :tlsgd:globalsym
+    ' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+	gcc_cv_as_aarch64_gdtinyreloc=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_aarch64_gdtinyreloc" >&5
+$as_echo "$gcc_cv_as_aarch64_gdtinyreloc" >&6; }
+if test $gcc_cv_as_aarch64_gdtinyreloc = yes; then
+
+$as_echo "#define HAVE_AS_TINY_TLSGD_RELOCS 1" >>confdefs.h
+
+fi
     # Enable default workaround for AArch64 Cortex-A53 erratum 835769.
     # Check whether --enable-fix-cortex-a53-835769 was given.
 if test "${enable_fix_cortex_a53_835769+set}" = set; then :
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 846651d..675b249 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3601,6 +3601,14 @@ case "$target" in
 	ldr     x0, [[x2, #:gotpage_lo15:globalsym]]
     ],,[AC_DEFINE(HAVE_AS_SMALL_PIC_RELOCS, 1,
 	[Define if your assembler supports relocs needed by -fpic.])])
+    # Check if we have binutils support for relocations types needed by TLSGD
+    # for tiny code model.
+    gcc_GAS_CHECK_FEATURE([global dynamic for tiny relocs], gcc_cv_as_aarch64_gdtinyreloc,,,
+    [
+	.text
+	adr x0, :tlsgd:globalsym
+    ],,[AC_DEFINE(HAVE_AS_TINY_TLSGD_RELOCS, 1,
+	[Define if your assembler supports relocs needed by global dynamic for tiny code model.])])
     # Enable default workaround for AArch64 Cortex-A53 erratum 835769.
     AC_ARG_ENABLE(fix-cortex-a53-835769,
     [
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c
new file mode 100644
index 0000000..a808440
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad --save-temps" } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
+/* { dg-final { cleanup-saved-temps } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c
new file mode 100644
index 0000000..b4170c2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target aarch64_tlsgdtiny } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad -mcmodel=tiny --save-temps" } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adr\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
+/* { dg-final { cleanup-saved-temps } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 728d020..76951a0 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -994,6 +994,19 @@ proc check_effective_target_aarch64_tlsle32 { } {
     }
 }
 
+# On AArch64, instruction sequence for TLS GD on tiny code model will utilize
+# the relocation modifier ":tlsgd:" together with ADR, it's only supported
+# in binutils higher than 2.25.
+
+proc check_effective_target_aarch64_tlsgdtiny { } {
+    if { [istarget aarch64*-*-*] } {
+	return [check_no_compiler_messages aarch64_tlsgdtiny object {
+	    void foo (void) { asm ("adr x1,:tlsgd:t1"); }
+	}]
+    } else {
+	return 0
+    }
+}
 # Return 1 if -shared is supported, as in no warnings or errors
 # emitted, 0 otherwise.
 

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

* Re: [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional
  2015-08-27  9:55 ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Jiong Wang
  2015-08-27 10:04   ` [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model Jiong Wang
@ 2015-10-06 11:40   ` Marcus Shawcroft
  1 sibling, 0 replies; 8+ messages in thread
From: Marcus Shawcroft @ 2015-10-06 11:40 UTC (permalink / raw)
  To: Jiong Wang; +Cc: gcc-patches

On 27 August 2015 at 10:52, Jiong Wang <jiong.wang@arm.com> wrote:

> 2015-08-27  Jiong Wang  <jiong.wang@arm.com>
>
> gcc/
>   * config/aarch64/aarch64.md (tlsgd_small): Delete this define_expand.
>   (*tlsgd_small): Rename this define_insn to "tlsgd_small";

OK /Marcus

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

* Re: [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
  2015-08-27 10:04   ` [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model Jiong Wang
@ 2015-10-06 13:32     ` Marcus Shawcroft
  2015-11-05 14:57       ` Jiong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Marcus Shawcroft @ 2015-10-06 13:32 UTC (permalink / raw)
  To: Jiong Wang; +Cc: gcc-patches

On 27 August 2015 at 10:54, Jiong Wang <jiong.wang@arm.com> wrote:
>
> As described this is the main implementaion patch.
>
> 2015-08-26  Jiong Wang  <jiong.wang@arm.com>
>
> gcc/
>   * configure.ac: Add check for binutils global dynamic tiny code model
>   relocation support.
>   * configure: Regenerate.
>   * config.in: Regenerate.
>   * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
>   * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
>   enumeration SYMBOL_TINY_TLSGD.
>   (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
>   * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
>   SYMBOL_TINY_TLSGD.
>   (aarch64_print_operand): Likewise.
>   (aarch64_expand_mov_immediate): Likewise.
>   (aarch64_load_symref_appropriately): Likewise.
>
> gcc/testsuite/
>   * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
>   New effective check.
>   * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
>   * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.
>

+#ifdef HAVE_AS_TINY_TLSGD_RELOCS
+  return SYMBOL_TINY_TLSGD;
+#else
+  return SYMBOL_SMALL_TLSGD;
+#endif

Rather than introduce blocks of conditional compilation it is better
to gate different behaviours with a test on a constant expression. In
this case add something like this:

#if define(HAVE_AS_TINY_TLSGD_RELOCS)
#define USE_TINY_TLSGD 1
#else
#define USE_TINY_TLSGD 0
#endif

up near the definition of TARGET_HAVE_TLS then write the above
fragment without using the preprocessor:

return USE_TINY_TLSGD ? SYMBOL_TINY_TLSGD : SYMBOL_SMALL_TLSGD;

or similar.


@@ -1024,6 +1024,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
  return;
       }

+    case SYMBOL_TINY_TLSGD:
     case SYMBOL_SMALL_TLSGD:
       {
  rtx_insn *insns;
@@ -1031,7 +1032,10 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
  rtx resolver = aarch64_tls_get_addr ();

  start_sequence ();
- aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
+ if (type == SYMBOL_SMALL_TLSGD)
+  aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
+ else
+  aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
  insns = get_insns ();
  end_sequence ();

Add a separate case statment for SYMBOL_TINY_TLSGD rather than reusing
the case statement for SYMBOL_SMALL_TLSGD and then needing to add
another test against symbol type within the body of the case
statement.

+(define_insn "tlsgd_tiny"
+  [(set (match_operand 0 "register_operand" "")
+ (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
+   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
UNSPEC_GOTTINYTLS)
+   (clobber (reg:DI LR_REGNUM))
+  ]
+  ""
+  "adr\tx0, %A1;bl\t%2;nop";
+  [(set_attr "type" "multiple")
+   (set_attr "length" "12")])

I don't think the explicit clobber LR_REGNUM is required since your
change last September:
https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02654.html

Thanks
/Marcus

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

* Re: Re: [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
  2015-10-06 13:32     ` Marcus Shawcroft
@ 2015-11-05 14:57       ` Jiong Wang
  2015-11-13 15:22         ` Jiong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jiong Wang @ 2015-11-05 14:57 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: James Greenhalgh, GCC Patches

[-- Attachment #1: Type: text/plain, Size: 3666 bytes --]

Marcus Shawcroft writes:

> +#ifdef HAVE_AS_TINY_TLSGD_RELOCS
> +  return SYMBOL_TINY_TLSGD;
> +#else
> +  return SYMBOL_SMALL_TLSGD;
> +#endif
>
> Rather than introduce blocks of conditional compilation it is better
> to gate different behaviours with a test on a constant expression. In
> this case add something like this:
>
> #if define(HAVE_AS_TINY_TLSGD_RELOCS)
> #define USE_TINY_TLSGD 1
> #else
> #define USE_TINY_TLSGD 0
> #endif
>
> up near the definition of TARGET_HAVE_TLS then write the above
> fragment without using the preprocessor:
>
> return USE_TINY_TLSGD ? SYMBOL_TINY_TLSGD : SYMBOL_SMALL_TLSGD;

Done.

> - aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
> + if (type == SYMBOL_SMALL_TLSGD)
> +  aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
> + else
> +  aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
>   insns = get_insns ();
>   end_sequence ();
>
> Add a separate case statment for SYMBOL_TINY_TLSGD rather than reusing
> the case statement for SYMBOL_SMALL_TLSGD and then needing to add
> another test against symbol type within the body of the case
> statement.

Done.

>
> +(define_insn "tlsgd_tiny"
> +  [(set (match_operand 0 "register_operand" "")
> + (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
> +   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
> UNSPEC_GOTTINYTLS)
> +   (clobber (reg:DI LR_REGNUM))
> +  ]
> +  ""
> +  "adr\tx0, %A1;bl\t%2;nop";
> +  [(set_attr "type" "multiple")
> +   (set_attr "length" "12")])
>
> I don't think the explicit clobber LR_REGNUM is required since your
> change last September:
> https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02654.html

We don't need this explict clobber LR_REGNUM only if operand 0 happen
be allocated to LR_REGNUM as after my above patch LR_REGNUM is allocable.

However we still need the explict clobber here.  Because for all other
cases LR_REGNUM not allocated, gcc data flow analysis can't deduct LR_REGNUM
will still be clobbered implicitly by the call instruction.

Without this "clobber" tag, a direct impact is df_regs_ever_live is calculated
incorrectly for x30, then for the following simple testcase:

__thread int t0 = 0x10;
__thread int t1 = 0x10;

int
main (int argc, char **argv)
{
   if (t0 != t1)
     return 1;
   return  0;
}


if you compile with

  "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad t.c -mcmodel=tiny -fomit-frame-pointer",
wrong code will be generated:

  main:
         str     x19, [sp, -16]!  <--- x30 is not saved.
         adr     x0, :tlsgd:t0
         bl __tls_get_addr
         nop

Patch updated. tls regression OK

OK for trunk?

2015-11-05  Jiong Wang  <jiong.wang@arm.com>

gcc/
   * configure.ac: Add check for binutils global dynamic tiny code model
   relocation support.
   * configure: Regenerate.
   * config.in: Regenerate.
   * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
   * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
   enumeration SYMBOL_TINY_TLSGD.
   (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
   * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
   SYMBOL_TINY_TLSGD.
   (aarch64_print_operand): Likewise.
   (aarch64_expand_mov_immediate): Likewise.
   (aarch64_load_symref_appropriately): Likewise.

gcc/testsuite/
   * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
   New effective check.
   * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
   * gcc.target/aarch64/tlsgd_small_ilp32_1.c: Likewise.
   * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.
   * gcc.target/aarch64/tlsgd_tiny_ilp32_1.c: Likewise.
   
-- 
Regards,
Jiong


[-- Attachment #2: new-gd-tiny.patch --]
[-- Type: text/x-patch, Size: 9976 bytes --]

diff --git a/gcc/config.in b/gcc/config.in
index 093478c..617278f 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -618,6 +618,13 @@
 #endif
 
 
+/* Define if your assembler supports relocs needed by global dynamic for tiny
+   code model. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_TINY_TLSGD_RELOCS
+#endif
+
+
 /* Define if your assembler and linker support thread-local storage. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_TLS
diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h
index baaf1bd..9128baa 100644
--- a/gcc/config/aarch64/aarch64-protos.h
+++ b/gcc/config/aarch64/aarch64-protos.h
@@ -62,6 +62,7 @@
    SYMBOL_SMALL_TLSGD
    SYMBOL_SMALL_TLSDESC
    SYMBOL_SMALL_TLSIE
+   SYMBOL_TINY_TLSGD
    SYMBOL_TINY_TLSIE
    SYMBOL_TLSLE12
    SYMBOL_TLSLE24
@@ -103,6 +104,7 @@ enum aarch64_symbol_type
   SYMBOL_SMALL_TLSIE,
   SYMBOL_TINY_ABSOLUTE,
   SYMBOL_TINY_GOT,
+  SYMBOL_TINY_TLSGD,
   SYMBOL_TINY_TLSIE,
   SYMBOL_TLSLE12,
   SYMBOL_TLSLE24,
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 7e61b16..8c24740 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -1042,6 +1042,22 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm,
 	return;
       }
 
+    case SYMBOL_TINY_TLSGD:
+      {
+	rtx_insn *insns;
+	rtx result = gen_rtx_REG (Pmode, R0_REGNUM);
+	rtx resolver = aarch64_tls_get_addr ();
+
+	start_sequence ();
+	aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
+	insns = get_insns ();
+	end_sequence ();
+
+	RTL_CONST_CALL_P (insns) = 1;
+	emit_libcall_block (insns, dest, result, imm);
+	return;
+      }
+
     case SYMBOL_SMALL_TLSGD:
       {
 	rtx_insn *insns;
@@ -1573,6 +1589,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm)
 	case SYMBOL_SMALL_GOT_28K:
 	case SYMBOL_SMALL_GOT_4G:
 	case SYMBOL_TINY_GOT:
+	case SYMBOL_TINY_TLSGD:
 	case SYMBOL_TINY_TLSIE:
 	  if (offset != const0_rtx)
 	    {
@@ -4426,6 +4443,7 @@ aarch64_print_operand (FILE *f, rtx x, char code)
 	  break;
 
 	case SYMBOL_SMALL_TLSGD:
+	case SYMBOL_TINY_TLSGD:
 	  asm_fprintf (asm_out_file, ":tlsgd:");
 	  break;
 
@@ -8695,6 +8713,23 @@ aarch64_classify_tls_symbol (rtx x)
   switch (tls_kind)
     {
     case TLS_MODEL_GLOBAL_DYNAMIC:
+      if (TARGET_TLS_DESC)
+      return SYMBOL_SMALL_TLSDESC;
+
+      /* Traditional model.  */
+      switch (aarch64_cmodel)
+      {
+#ifdef HAVE_AS_TINY_TLSGD_RELOCS
+#define USE_TINY_TLSGD 1
+#else
+#define USE_TINY_TLSGD 0
+#endif
+      case AARCH64_CMODEL_TINY:
+      case AARCH64_CMODEL_TINY_PIC:
+	  return USE_TINY_TLSGD ? SYMBOL_TINY_TLSGD : SYMBOL_SMALL_TLSGD;
+      default:
+	  return SYMBOL_SMALL_TLSGD;
+      }
     case TLS_MODEL_LOCAL_DYNAMIC:
       return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_SMALL_TLSGD;
 
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index a80213d..b87730d 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -4688,6 +4688,17 @@
   [(set_attr "type" "call")
    (set_attr "length" "16")])
 
+(define_insn "tlsgd_tiny"
+  [(set (match_operand 0 "register_operand" "")
+  (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
+   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_GOTTINYTLS)
+   (clobber (reg:DI LR_REGNUM))
+  ]
+  ""
+  "adr\tx0, %A1;bl\t%2;nop";
+  [(set_attr "type" "multiple")
+   (set_attr "length" "12")])
+
 (define_insn "tlsie_small_<mode>"
   [(set (match_operand:PTR 0 "register_operand" "=r")
         (unspec:PTR [(match_operand 1 "aarch64_tls_ie_symref" "S")]
diff --git a/gcc/configure b/gcc/configure
index f6ae9906..6b7772a 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24388,6 +24388,41 @@ if test $gcc_cv_as_aarch64_picreloc = yes; then
 $as_echo "#define HAVE_AS_SMALL_PIC_RELOCS 1" >>confdefs.h
 
 fi
+    # Check if we have binutils support for relocations types needed by TLSGD
+    # for tiny code model.
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for global dynamic for tiny relocs" >&5
+$as_echo_n "checking assembler for global dynamic for tiny relocs... " >&6; }
+if test "${gcc_cv_as_aarch64_gdtinyreloc+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_aarch64_gdtinyreloc=no
+  if test x$gcc_cv_as != x; then
+    $as_echo '
+    .text
+    adr x0, :tlsgd:globalsym
+    ' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+    gcc_cv_as_aarch64_gdtinyreloc=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_aarch64_gdtinyreloc" >&5
+$as_echo "$gcc_cv_as_aarch64_gdtinyreloc" >&6; }
+if test $gcc_cv_as_aarch64_gdtinyreloc = yes; then
+
+$as_echo "#define HAVE_AS_TINY_TLSGD_RELOCS 1" >>confdefs.h
+
+fi
     # Enable default workaround for AArch64 Cortex-A53 erratum 835769.
     # Check whether --enable-fix-cortex-a53-835769 was given.
 if test "${enable_fix_cortex_a53_835769+set}" = set; then :
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 88fb9bf..7ba497c 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3637,6 +3637,14 @@ case "$target" in
 	ldr     x0, [[x2, #:gotpage_lo15:globalsym]]
     ],,[AC_DEFINE(HAVE_AS_SMALL_PIC_RELOCS, 1,
 	[Define if your assembler supports relocs needed by -fpic.])])
+    # Check if we have binutils support for relocations types needed by TLSGD
+    # for tiny code model.
+    gcc_GAS_CHECK_FEATURE([global dynamic for tiny relocs], gcc_cv_as_aarch64_gdtinyreloc,,,
+    [
+    .text
+    adr x0, :tlsgd:globalsym
+    ],,[AC_DEFINE(HAVE_AS_TINY_TLSGD_RELOCS, 1,
+    [Define if your assembler supports relocs needed by global dynamic for tiny code model.])])
     # Enable default workaround for AArch64 Cortex-A53 erratum 835769.
     AC_ARG_ENABLE(fix-cortex-a53-835769,
     [
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c
new file mode 100644
index 0000000..6fba678
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c
@@ -0,0 +1,9 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad --save-temps" } */
+/* { dg-skip-if "TLS GD for small" { aarch64*-*-* }  { "-mcmodel=tiny" "-mcmodel=large" } { "" } } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_small_ilp32_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_ilp32_1.c
new file mode 100644
index 0000000..1b189a4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_ilp32_1.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad -mabi=ilp32 --save-temps" } */
+/* { dg-skip-if "TLS GD for small" { aarch64*-*-* }  { "-mcmodel=tiny" "-mcmodel=large" } { "" } } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c
new file mode 100644
index 0000000..1a1053d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c
@@ -0,0 +1,10 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target aarch64_tlsgdtiny } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad -mcmodel=tiny --save-temps" } */
+/* { dg-skip-if "TLS GD for tiny" { aarch64*-*-* }  { "-mcmodel=small" "-mcmodel=large" } { "" } } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adr\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_ilp32_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_ilp32_1.c
new file mode 100644
index 0000000..df00c60
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_ilp32_1.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-require-effective-target ilp32 } */
+/* { dg-require-effective-target tls_native } */
+/* { dg-require-effective-target aarch64_tlsgdtiny } */
+/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad -mcmodel=tiny -mabi=ilp32 --save-temps" } */
+/* { dg-skip-if "TLS GD for tiny" { aarch64*-*-* }  { "-mcmodel=small" "-mcmodel=large" } { "" } } */
+
+#include "tls_1.x"
+
+/* { dg-final { scan-assembler-times "adr\tx\[0-9\]+, :tlsgd:" 2 } } */
+/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 9057a27..1c6f2f7 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -1023,6 +1023,19 @@ proc check_effective_target_aarch64_tlsle32 { } {
     }
 }
 
+# On AArch64, instruction sequence for TLS GD on tiny code model will utilize
+# the relocation modifier ":tlsgd:" together with ADR, it's only supported
+# in binutils higher than 2.25.
+
+proc check_effective_target_aarch64_tlsgdtiny { } {
+    if { [istarget aarch64*-*-*] } {
+    return [check_no_compiler_messages aarch64_tlsgdtiny object {
+        void foo (void) { asm ("adr x1,:tlsgd:t1"); }
+	 }]
+    } else {
+    return 0
+    }
+}
 # Return 1 if -shared is supported, as in no warnings or errors
 # emitted, 0 otherwise.
 

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

* Re: [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
  2015-11-05 14:57       ` Jiong Wang
@ 2015-11-13 15:22         ` Jiong Wang
  2015-12-03 10:42           ` [Ping^2][AArch64][TLSGD][2/2] " Jiong Wang
  0 siblings, 1 reply; 8+ messages in thread
From: Jiong Wang @ 2015-11-13 15:22 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: James Greenhalgh, GCC Patches


On 05/11/15 14:57, Jiong Wang wrote:
> Marcus Shawcroft writes:
>
>> +#ifdef HAVE_AS_TINY_TLSGD_RELOCS
>> +  return SYMBOL_TINY_TLSGD;
>> +#else
>> +  return SYMBOL_SMALL_TLSGD;
>> +#endif
>>
>> Rather than introduce blocks of conditional compilation it is better
>> to gate different behaviours with a test on a constant expression. In
>> this case add something like this:
>>
>> #if define(HAVE_AS_TINY_TLSGD_RELOCS)
>> #define USE_TINY_TLSGD 1
>> #else
>> #define USE_TINY_TLSGD 0
>> #endif
>>
>> up near the definition of TARGET_HAVE_TLS then write the above
>> fragment without using the preprocessor:
>>
>> return USE_TINY_TLSGD ? SYMBOL_TINY_TLSGD : SYMBOL_SMALL_TLSGD;
>
> Done.
>
>> - aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
>> + if (type == SYMBOL_SMALL_TLSGD)
>> +  aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
>> + else
>> +  aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
>>   insns = get_insns ();
>>   end_sequence ();
>>
>> Add a separate case statment for SYMBOL_TINY_TLSGD rather than reusing
>> the case statement for SYMBOL_SMALL_TLSGD and then needing to add
>> another test against symbol type within the body of the case
>> statement.
>
> Done.
>
>>
>> +(define_insn "tlsgd_tiny"
>> +  [(set (match_operand 0 "register_operand" "")
>> + (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
>> +   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
>> UNSPEC_GOTTINYTLS)
>> +   (clobber (reg:DI LR_REGNUM))
>> +  ]
>> +  ""
>> +  "adr\tx0, %A1;bl\t%2;nop";
>> +  [(set_attr "type" "multiple")
>> +   (set_attr "length" "12")])
>>
>> I don't think the explicit clobber LR_REGNUM is required since your
>> change last September:
>> https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02654.html
>
> We don't need this explict clobber LR_REGNUM only if operand 0 happen
> be allocated to LR_REGNUM as after my above patch LR_REGNUM is allocable.
>
> However we still need the explict clobber here.  Because for all other
> cases LR_REGNUM not allocated, gcc data flow analysis can't deduct 
> LR_REGNUM
> will still be clobbered implicitly by the call instruction.
>
> Without this "clobber" tag, a direct impact is df_regs_ever_live is 
> calculated
> incorrectly for x30, then for the following simple testcase:
>
> __thread int t0 = 0x10;
> __thread int t1 = 0x10;
>
> int
> main (int argc, char **argv)
> {
>   if (t0 != t1)
>     return 1;
>   return  0;
> }
>
>
> if you compile with
>
>  "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad t.c 
> -mcmodel=tiny -fomit-frame-pointer",
> wrong code will be generated:
>
>  main:
>         str     x19, [sp, -16]!  <--- x30 is not saved.
>         adr     x0, :tlsgd:t0
>         bl __tls_get_addr
>         nop
>
> Patch updated. tls regression OK
>
> OK for trunk?
>
> 2015-11-05  Jiong Wang  <jiong.wang@arm.com>
>
> gcc/
>   * configure.ac: Add check for binutils global dynamic tiny code model
>   relocation support.
>   * configure: Regenerate.
>   * config.in: Regenerate.
>   * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
>   * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
>   enumeration SYMBOL_TINY_TLSGD.
>   (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
>   * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
>   SYMBOL_TINY_TLSGD.
>   (aarch64_print_operand): Likewise.
>   (aarch64_expand_mov_immediate): Likewise.
>   (aarch64_load_symref_appropriately): Likewise.
>
> gcc/testsuite/
>   * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
>   New effective check.
>   * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
>   * gcc.target/aarch64/tlsgd_small_ilp32_1.c: Likewise.
>   * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.
>   * gcc.target/aarch64/tlsgd_tiny_ilp32_1.c: Likewise.
Ping ~

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

* [Ping^2][AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
  2015-11-13 15:22         ` Jiong Wang
@ 2015-12-03 10:42           ` Jiong Wang
  0 siblings, 0 replies; 8+ messages in thread
From: Jiong Wang @ 2015-12-03 10:42 UTC (permalink / raw)
  To: Marcus Shawcroft; +Cc: James Greenhalgh, Richard Earnshaw, GCC Patches

On 13/11/15 15:21, Jiong Wang wrote:
>
> On 05/11/15 14:57, Jiong Wang wrote:
>> Marcus Shawcroft writes:
>>
>>> +#ifdef HAVE_AS_TINY_TLSGD_RELOCS
>>> +  return SYMBOL_TINY_TLSGD;
>>> +#else
>>> +  return SYMBOL_SMALL_TLSGD;
>>> +#endif
>>>
>>> Rather than introduce blocks of conditional compilation it is better
>>> to gate different behaviours with a test on a constant expression. In
>>> this case add something like this:
>>>
>>> #if define(HAVE_AS_TINY_TLSGD_RELOCS)
>>> #define USE_TINY_TLSGD 1
>>> #else
>>> #define USE_TINY_TLSGD 0
>>> #endif
>>>
>>> up near the definition of TARGET_HAVE_TLS then write the above
>>> fragment without using the preprocessor:
>>>
>>> return USE_TINY_TLSGD ? SYMBOL_TINY_TLSGD : SYMBOL_SMALL_TLSGD;
>>
>> Done.
>>
>>> - aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
>>> + if (type == SYMBOL_SMALL_TLSGD)
>>> +  aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver));
>>> + else
>>> +  aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver));
>>>   insns = get_insns ();
>>>   end_sequence ();
>>>
>>> Add a separate case statment for SYMBOL_TINY_TLSGD rather than reusing
>>> the case statement for SYMBOL_SMALL_TLSGD and then needing to add
>>> another test against symbol type within the body of the case
>>> statement.
>>
>> Done.
>>
>>>
>>> +(define_insn "tlsgd_tiny"
>>> +  [(set (match_operand 0 "register_operand" "")
>>> + (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1)))
>>> +   (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")]
>>> UNSPEC_GOTTINYTLS)
>>> +   (clobber (reg:DI LR_REGNUM))
>>> +  ]
>>> +  ""
>>> +  "adr\tx0, %A1;bl\t%2;nop";
>>> +  [(set_attr "type" "multiple")
>>> +   (set_attr "length" "12")])
>>>
>>> I don't think the explicit clobber LR_REGNUM is required since your
>>> change last September:
>>> https://gcc.gnu.org/ml/gcc-patches/2014-09/msg02654.html
>>
>> We don't need this explict clobber LR_REGNUM only if operand 0 happen
>> be allocated to LR_REGNUM as after my above patch LR_REGNUM is 
>> allocable.
>>
>> However we still need the explict clobber here.  Because for all other
>> cases LR_REGNUM not allocated, gcc data flow analysis can't deduct 
>> LR_REGNUM
>> will still be clobbered implicitly by the call instruction.
>>
>> Without this "clobber" tag, a direct impact is df_regs_ever_live is 
>> calculated
>> incorrectly for x30, then for the following simple testcase:
>>
>> __thread int t0 = 0x10;
>> __thread int t1 = 0x10;
>>
>> int
>> main (int argc, char **argv)
>> {
>>   if (t0 != t1)
>>     return 1;
>>   return  0;
>> }
>>
>>
>> if you compile with
>>
>>  "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad t.c 
>> -mcmodel=tiny -fomit-frame-pointer",
>> wrong code will be generated:
>>
>>  main:
>>         str     x19, [sp, -16]!  <--- x30 is not saved.
>>         adr     x0, :tlsgd:t0
>>         bl __tls_get_addr
>>         nop
>>
>> Patch updated. tls regression OK
>>
>> OK for trunk?
>>
>> 2015-11-05  Jiong Wang  <jiong.wang@arm.com>
>>
>> gcc/
>>   * configure.ac: Add check for binutils global dynamic tiny code model
>>   relocation support.
>>   * configure: Regenerate.
>>   * config.in: Regenerate.
>>   * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
>>   * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
>>   enumeration SYMBOL_TINY_TLSGD.
>>   (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
>>   * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
>>   SYMBOL_TINY_TLSGD.
>>   (aarch64_print_operand): Likewise.
>>   (aarch64_expand_mov_immediate): Likewise.
>>   (aarch64_load_symref_appropriately): Likewise.
>>
>> gcc/testsuite/
>>   * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
>>   New effective check.
>>   * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
>>   * gcc.target/aarch64/tlsgd_small_ilp32_1.c: Likewise.
>>   * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.
>>   * gcc.target/aarch64/tlsgd_tiny_ilp32_1.c: Likewise.
> Ping ~

Ping^2

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

end of thread, other threads:[~2015-12-03 10:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19 14:59 [AArch64][TLSGD Trad][1/2] Generalize TLS Global Dynamic support for all memory mode Jiong Wang
2015-08-27  9:55 ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Jiong Wang
2015-08-27 10:04   ` [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model Jiong Wang
2015-10-06 13:32     ` Marcus Shawcroft
2015-11-05 14:57       ` Jiong Wang
2015-11-13 15:22         ` Jiong Wang
2015-12-03 10:42           ` [Ping^2][AArch64][TLSGD][2/2] " Jiong Wang
2015-10-06 11:40   ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Marcus Shawcroft

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).