public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 0/6] Thread pointer built-in functions
@ 2012-07-12  6:52 Chung-Lin Tang
  2012-10-11 15:19 ` Chung-Lin Tang
  0 siblings, 1 reply; 6+ messages in thread
From: Chung-Lin Tang @ 2012-07-12  6:52 UTC (permalink / raw)
  To: gcc-patches

Hi, following discussion here:
http://gcc.gnu.org/ml/gcc-patches/2012-07/msg00229.html
(and a few other mails in the thread between Richard Sandiford)

A number of targets implement the same name __builtin_thread_pointer(),
__builtin_set_thread_pointer() TLS builtins. This set of patches changes
them into machine-independent builtins, implemented by target hooks.

Currently, the backend interface does not seem to expose any notion of
TLS registers, hence these functions are not really implementable by the
expanders (the default target hooks are simply sorry()).

I have here the associated backend changes for all ports that have those
builtins implemented, namely alpha, arm, s390, xtensa, plus adding the
mips support which was the original reason I started this. I have CCed
the respective port maintainers in the rest of the patches.

It wasn't convenient for me to build/test the alpha, s390, and xtensa
ports, so please bear with me if you see anything wrong (the patches are
simply straightforward changes associated with the builtin).

Thanks,
Chung-Lin

Full ChangeLog:

2012-07-12  Chung-Lin Tang  <cltang@codesourcery.com>

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

        * config/alpha/alpha.c (alpha_builtin): Remove
        ALPHA_BUILTIN_THREAD_POINTER, ALPHA_BUILTIN_SET_THREAD_POINTER.
        (code_for_builtin): Remove CODE_FOR_load_tp, CODE_FOR_set_tp.
        (alpha_init_builtins): Remove __builtin_thread_pointer,
        __builtin_set_thread_pointer machine-specific builtins.
        (alpha_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (alpha_expand_builtin_set_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.
        (alpha_fold_builtin): Remove ALPHA_BUILTIN_THREAD_POINTER,
        ALPHA_BUILTIN_SET_THREAD_POINTER cases.

        * config/s390/s390.c (s390_builtin,code_for_builtin_64,
        code_for_builtin_31,s390_init_builtins,s390_expand_builtin):
        Remove.
        (s390_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (s390_expand_builtin_set_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.

        * config/xtensa/xtensa.c
        (xtensa_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (xtensa_expand_builtin_set_thread_pointer): Add hook function
        for TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.
        (xtensa_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER and
        XTENSA_BUILTIN_SET_THREAD_POINTER.
        (xtensa_init_builtins): Remove __builtin_thread_pointer,
        __builtin_set_thread_pointer machine-specific builtins.
        (xtensa_fold_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.
        (xtensa_expand_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.

        * config/arm/arm.c (arm_builtins): Remove
        ARM_BUILTIN_THREAD_POINTER.
        (arm_init_tls_builtins): Remove function.
        (arm_init_builtins): Remove call to arm_init_tls_builtins().
        (arm_expand_builtin): Remove ARM_BUILTIN_THREAD_POINTER case.
        (arm_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.

        * config/mips/mips.c (mips_get_tp): Add 'target' parameter for
        generating to specific reg.
        (mips_legitimize_tls_address): Update calls to mips_get_tp().
        (mips_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.

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

* Re: [PATCH 0/6] Thread pointer built-in functions
  2012-07-12  6:52 [PATCH 0/6] Thread pointer built-in functions Chung-Lin Tang
@ 2012-10-11 15:19 ` Chung-Lin Tang
  2012-10-11 23:00   ` [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760 Oleg Endo
  0 siblings, 1 reply; 6+ messages in thread
From: Chung-Lin Tang @ 2012-10-11 15:19 UTC (permalink / raw)
  To: gcc-patches
  Cc: Richard Henderson, Richard Sandiford, Ramana Radhakrishnan,
	Sterling Augustine, Andreas Krebbel


This patch set has been committed, thanks to all maintainers who
reviewed the respective parts.

Thanks,
Chung-Lin

Full ChangeLog:

2012-10-11  Chung-Lin Tang  <cltang@codesourcery.com>

        * 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.
        * optabs.def (get_thread_pointer,set_thread_pointer):
        New standard names.
        * doc/md.texi (Standard Names): Document get_thread_pointer and
        set_thread_pointer patterns.
        * config/alpha/alpha.md (get_thread_pointerdi): Rename from load_tp.
        (set_thread_pointerdi): Rename from set_tp.
        * config/alpha/alpha.c (alpha_legitimize_address_1): Change
        gen_load_tp calls to gen_get_thread_pointerdi.
        (alpha_builtin): Remove ALPHA_BUILTIN_THREAD_POINTER,
        ALPHA_BUILTIN_SET_THREAD_POINTER.
        (code_for_builtin): Remove CODE_FOR_load_tp, CODE_FOR_set_tp.
        (alpha_init_builtins): Remove __builtin_thread_pointer,
        __builtin_set_thread_pointer machine-specific builtins.
        (alpha_expand_builtin_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_THREAD_POINTER.
        (alpha_expand_builtin_set_thread_pointer): Add hook function for
        TARGET_EXPAND_BUILTIN_SET_THREAD_POINTER.
        (alpha_fold_builtin): Remove ALPHA_BUILTIN_THREAD_POINTER,
        ALPHA_BUILTIN_SET_THREAD_POINTER cases.
        * config/arm/arm.md (get_thread_pointersi): New pattern.
        * config/arm/arm-protos.h (arm_load_tp): Add extern declaration.
        * config/arm/arm.c (arm_load_tp): Remove static.
        (arm_builtins): Remove ARM_BUILTIN_THREAD_POINTER.
        (arm_init_tls_builtins): Remove function.
        (arm_init_builtins): Remove call to arm_init_tls_builtins().
        (arm_expand_builtin): Remove ARM_BUILTIN_THREAD_POINTER case.
        * config/mips/mips.md (get_thread_pointer<mode>): New pattern.
        * config/mips/mips-protos.h (mips_expand_thread_pointer):
        Add extern declaration.
        * config/mips/mips.c (mips_expand_thread_pointer):
        Renamed from mips_get_tp.
        (mips_get_tp): New stub calling mips_expand_thread_pointer.
        * config/s390/s390.c (s390_builtin,code_for_builtin_64,
        code_for_builtin_31,s390_init_builtins,s390_expand_builtin): Remove.
        * config/s390/s390.md (get_tp_64,get_tp_31,set_tp_64,set_tp_31):
        Remove.
        (get_thread_pointer<mode>,set_thread_pointer<mode>):
        New, adapted from removed patterns.
        * config/xtensa/xtensa.md (get_thread_pointersi):
        Renamed from load_tp.
        (set_thread_pointersi): Renamed from set_tp.
        * config/xtensa/xtensa.c (xtensa_legitimize_tls_address):
        Change gen_load_tp calls to gen_get_thread_pointersi.
        (xtensa_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER and
        XTENSA_BUILTIN_SET_THREAD_POINTER.
        (xtensa_init_builtins): Remove __builtin_thread_pointer,
        __builtin_set_thread_pointer machine-specific builtins.
        (xtensa_fold_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.
        (xtensa_expand_builtin): Remove XTENSA_BUILTIN_THREAD_POINTER,
        XTENSA_BUILTIN_SET_THREAD_POINTER cases.

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

* Re: [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760
  2012-10-11 15:19 ` Chung-Lin Tang
@ 2012-10-11 23:00   ` Oleg Endo
  2012-10-12  1:09     ` Kaz Kojima
  2012-10-13 12:05     ` Chung-Lin Tang
  0 siblings, 2 replies; 6+ messages in thread
From: Oleg Endo @ 2012-10-11 23:00 UTC (permalink / raw)
  To: Chung-Lin Tang
  Cc: gcc-patches, Richard Henderson, Richard Sandiford,
	Ramana Radhakrishnan, Sterling Augustine, Andreas Krebbel

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

On Thu, 2012-10-11 at 23:11 +0800, Chung-Lin Tang wrote:
> This patch set has been committed, thanks to all maintainers who
> reviewed the respective parts.
> 
> Thanks,
> Chung-Lin
> 

This broke the recently added thread pointer built-ins on SH, but I was
prepared for that, so no problem here.  The attached patch is a straight
forward fix.

However, with the patch applied I get an ICE on one of the SH thread
pointer tests:  gcc/testsuite/gcc.target/sh/pr54760-3.c, function
test04:

internal compiler error: in expand_insn, at optabs.c:8208
    __builtin_set_thread_pointer (xx[i]);
                                 ^
0x8478872 expand_insn
	../../gcc-trunk2/gcc/optabs.c:8208
0x8478872 expand_insn
	../../gcc-trunk2/gcc/optabs.c:8204
0x81ded5a expand_builtin_set_thread_pointer
	../../gcc-trunk2/gcc/builtins.c:5780
0x81e6b18 expand_builtin(tree_node*, rtx_def*, rtx_def*, machine_mode,
int)
	../../gcc-trunk2/gcc/builtins.c:6855
0x82eeaf9 expand_expr_real_1(tree_node*, rtx_def*, machine_mode,
expand_modifier, rtx_def**)
	../../gcc-trunk2/gcc/expr.c:10143
0x8216a7b expand_call_stmt
	../../gcc-trunk2/gcc/cfgexpand.c:2012
0x8216a7b expand_gimple_stmt_1
	../../gcc-trunk2/gcc/cfgexpand.c:2050
0x8216a7b expand_gimple_stmt
	../../gcc-trunk2/gcc/cfgexpand.c:2202
0x8218406 expand_gimple_basic_block
	../../gcc-trunk2/gcc/cfgexpand.c:3956
0x821a417 gimple_expand_cfg
	../../gcc-trunk2/gcc/cfgexpand.c:4475
Please submit a full bug report,


All the other test cases seem to produce code as expected though.
Could you please try out the failing test case mentioned above?
As mentioned in the file gcc/testsuite/gcc.target/sh/pr54760-3.c it
should be moved to C torture tests.

Anyway, regardless of this failure, the attached patch for SH should be
applicable. OK?

Cheers,
Oleg

gcc/ChangeLog:

	PR target/54760
	* config/sh/sh.c (bdesc): Remove thread pointer built-ins.
	* config/sh/sh.md (get_thread_pointer, set_thread_pointer): 
	Append mode name 'si'.


[-- Attachment #2: sh_pr54760_4.patch --]
[-- Type: text/x-patch, Size: 1351 bytes --]

Index: gcc/config/sh/sh.c
===================================================================
--- gcc/config/sh/sh.c	(revision 192378)
+++ gcc/config/sh/sh.c	(working copy)
@@ -11778,12 +11778,6 @@
     CODE_FOR_byterev,	"__builtin_sh_media_BYTEREV", SH_BLTIN_2, 0 },
   { shmedia_builtin_p,
     CODE_FOR_prefetch,	"__builtin_sh_media_PREFO", SH_BLTIN_PSSV, 0 },
-
-  { sh1_builtin_p,
-    CODE_FOR_get_thread_pointer, "__builtin_thread_pointer", SH_BLTIN_VP, 0 },
-  { sh1_builtin_p,
-    CODE_FOR_set_thread_pointer, "__builtin_set_thread_pointer",
-    SH_BLTIN_PV, 0 },
 };
 
 static void
Index: gcc/config/sh/sh.md
===================================================================
--- gcc/config/sh/sh.md	(revision 192378)
+++ gcc/config/sh/sh.md	(working copy)
@@ -10085,7 +10085,7 @@
 ;;
 ;; On SH the thread pointer is kept in the GBR.
 ;; These patterns are usually expanded from the respective built-in functions.
-(define_expand "get_thread_pointer"
+(define_expand "get_thread_pointersi"
   [(set (match_operand:SI 0 "register_operand") (reg:SI GBR_REG))]
   "TARGET_SH1")
 
@@ -10096,7 +10096,7 @@
   "stc	gbr,%0"
   [(set_attr "type" "tls_load")])
 
-(define_expand "set_thread_pointer"
+(define_expand "set_thread_pointersi"
   [(set (reg:SI GBR_REG)
 	(unspec_volatile:SI [(match_operand:SI 0 "register_operand")]
 	 UNSPECV_GBR))]

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

* Re: [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760
  2012-10-11 23:00   ` [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760 Oleg Endo
@ 2012-10-12  1:09     ` Kaz Kojima
  2012-10-13 12:05     ` Chung-Lin Tang
  1 sibling, 0 replies; 6+ messages in thread
From: Kaz Kojima @ 2012-10-12  1:09 UTC (permalink / raw)
  To: oleg.endo; +Cc: gcc-patches

Oleg Endo <oleg.endo@t-online.de> wrote:
> Anyway, regardless of this failure, the attached patch for SH should be
> applicable. OK?

OK.

Regards,
	kaz

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

* Re: [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760
  2012-10-11 23:00   ` [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760 Oleg Endo
  2012-10-12  1:09     ` Kaz Kojima
@ 2012-10-13 12:05     ` Chung-Lin Tang
  2012-10-13 13:26       ` Oleg Endo
  1 sibling, 1 reply; 6+ messages in thread
From: Chung-Lin Tang @ 2012-10-13 12:05 UTC (permalink / raw)
  To: Oleg Endo
  Cc: gcc-patches, Richard Henderson, Richard Sandiford,
	Ramana Radhakrishnan, Sterling Augustine, Andreas Krebbel

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

On 2012/10/12 06:55 AM, Oleg Endo wrote:
> This broke the recently added thread pointer built-ins on SH, but I was
> prepared for that, so no problem here.  The attached patch is a straight
> forward fix.
> 
> However, with the patch applied I get an ICE on one of the SH thread
> pointer tests:  gcc/testsuite/gcc.target/sh/pr54760-3.c, function
> test04:
> 
> internal compiler error: in expand_insn, at optabs.c:8208
>     __builtin_set_thread_pointer (xx[i]);

Looks like I was supposed to use create_input_operand() there instead.
I've committed the attached patch as obvious. This should be fixed now.

Thanks,
Chung-Lin

        * builtins.c (expand_builtin_set_thread_pointer): Use
        create_input_operand() instead of create_fixed_operand().


[-- Attachment #2: tmp.diff --]
[-- Type: text/plain, Size: 454 bytes --]

Index: builtins.c
===================================================================
--- builtins.c	(revision 192421)
+++ builtins.c	(revision 192422)
@@ -5776,7 +5776,7 @@
       struct expand_operand op;
       rtx val = expand_expr (CALL_EXPR_ARG (exp, 0), NULL_RTX,
 			     Pmode, EXPAND_NORMAL);      
-      create_fixed_operand (&op, val);
+      create_input_operand (&op, val, Pmode);
       expand_insn (icode, 1, &op);
       return;
     }

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

* Re: [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760
  2012-10-13 12:05     ` Chung-Lin Tang
@ 2012-10-13 13:26       ` Oleg Endo
  0 siblings, 0 replies; 6+ messages in thread
From: Oleg Endo @ 2012-10-13 13:26 UTC (permalink / raw)
  To: Chung-Lin Tang
  Cc: gcc-patches, Richard Henderson, Richard Sandiford,
	Ramana Radhakrishnan, Sterling Augustine, Andreas Krebbel

On Sat, 2012-10-13 at 17:33 +0800, Chung-Lin Tang wrote:
> On 2012/10/12 06:55 AM, Oleg Endo wrote:
> > This broke the recently added thread pointer built-ins on SH, but I was
> > prepared for that, so no problem here.  The attached patch is a straight
> > forward fix.
> > 
> > However, with the patch applied I get an ICE on one of the SH thread
> > pointer tests:  gcc/testsuite/gcc.target/sh/pr54760-3.c, function
> > test04:
> > 
> > internal compiler error: in expand_insn, at optabs.c:8208
> >     __builtin_set_thread_pointer (xx[i]);
> 
> Looks like I was supposed to use create_input_operand() there instead.
> I've committed the attached patch as obvious. This should be fixed now.

Yep, confirmed.  Thanks!

Cheers,
Oleg

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

end of thread, other threads:[~2012-10-13 11:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-12  6:52 [PATCH 0/6] Thread pointer built-in functions Chung-Lin Tang
2012-10-11 15:19 ` Chung-Lin Tang
2012-10-11 23:00   ` [PATCH 0/6] Thread pointer built-in functions / [SH] PR 54760 Oleg Endo
2012-10-12  1:09     ` Kaz Kojima
2012-10-13 12:05     ` Chung-Lin Tang
2012-10-13 13:26       ` Oleg Endo

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