public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew MacLeod <amacleod@redhat.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Cc: Jeff Law <law@redhat.com>, Richard Biener <richard.guenther@gmail.com>
Subject: [patch] Provide a can_compare_and_swap_p target hook.
Date: Tue, 04 Nov 2014 16:28:00 -0000	[thread overview]
Message-ID: <5458FE9C.2090409@redhat.com> (raw)

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

java/builtins.c needs to call can_compare_and_swap, which happens to be 
provided via optabs.h.
As a result, we see the following in java/builtins.c:

/* FIXME: All these headers are necessary for sync_compare_and_swap.
    Front ends should never have to look at that.  */
#include "rtl.h"
#include "insn-codes.h"
#include "expr.h"
#include "optabs.h"

by providing a target hook and a default which simply calls 
can_compare_and_swap_p(),  we can remove all that include crap from the 
front end.  None of those 4 include files are now directly included by 
any front end files.

Bootstraps on x86_64-unknown-linux-gnu, and no new testsuite failures.  
OK for trunk?

Andrew

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


	* target.def (can_compare_and_swap_p): Define target hook.
	* targhooks.c (default_can_compare_and_swap_p): Provide default hook.
	* targhooks.h (default_can_compare_and_swap_p): Provide prototype.
	* doc/tm.texi (target_can_compare_and_swap_p): Provide description.
	* doc/tm.texi.in (TARGET_CAN_COMPARE_AND_SWAP_P): Provide location.
	* java/builtins.c. Remove backend includes, include target.h.
	(compareAndSwapInt_builtin, compareAndSwapLong_builtin,
	compareAndSwapObject_builtin, VMSupportsCS8_builtin): Use
	compare_and_swap_p target hook.
	
Index: target.def
===================================================================
*** target.def	(revision 217057)
--- target.def	(working copy)
*************** specific target options and the caller d
*** 5185,5190 ****
--- 5185,5199 ----
   bool, (tree caller, tree callee),
   default_target_can_inline_p)
  
+ DEFHOOK
+ (can_compare_and_swap_p,
+  "This macro returns true if the target can perform an atomic\n\
+ compare_and_swap operation on an object of machine mode @var{mode}.\n\
+ @var{allow_libcall} is a boolean which is used to indicate whether the\n\
+ operation is allowed to be performed with a libcall.",
+  bool, (machine_mode mode, bool allow_libcall),
+  default_can_compare_and_swap_p)
+ 
  HOOK_VECTOR_END (target_option)
  
  /* For targets that need to mark extra registers as live on entry to
Index: targhooks.c
===================================================================
*** targhooks.c	(revision 217057)
--- targhooks.c	(working copy)
*************** default_target_can_inline_p (tree caller
*** 1322,1327 ****
--- 1322,1334 ----
    return ret;
  }
  
+ bool 
+ default_can_compare_and_swap_p (machine_mode mode, bool allow_libcall)
+ {
+   return can_compare_and_swap_p (mode, allow_libcall);
+ }
+ 
+ 
  #ifndef HAVE_casesi
  # define HAVE_casesi 0
  #endif
Index: targhooks.h
===================================================================
*** targhooks.h	(revision 217057)
--- targhooks.h	(working copy)
*************** extern tree std_gimplify_va_arg_expr (tr
*** 220,224 ****
--- 220,226 ----
  extern bool can_use_doloop_if_innermost (const widest_int &,
  					 const widest_int &,
  					 unsigned int, bool);
+ extern bool default_can_compare_and_swap_p (machine_mode, bool);
+ 
  
  #endif /* GCC_TARGHOOKS_H */
Index: doc/tm.texi
===================================================================
*** doc/tm.texi	(revision 217057)
--- doc/tm.texi	(working copy)
*************** default, inlining is not allowed if the
*** 9742,9747 ****
--- 9742,9754 ----
  specific target options and the caller does not use the same options.
  @end deftypefn
  
+ @deftypefn {Target Hook} bool TARGET_CAN_COMPARE_AND_SWAP_P (machine_mode @var{mode}, bool @var{allow_libcall})
+ This macro returns true if the target can perform an atomic
+ compare_and_swap operation on an object of machine mode @var{mode}.
+ @var{allow_libcall} is a boolean which is used to indicate whether the
+ operation is allowed to be performed with a libcall.
+ @end deftypefn
+ 
  @node Emulated TLS
  @section Emulating TLS
  @cindex Emulated TLS
Index: doc/tm.texi.in
===================================================================
*** doc/tm.texi.in	(revision 217057)
--- doc/tm.texi.in	(working copy)
*************** on this implementation detail.
*** 7227,7232 ****
--- 7227,7234 ----
  
  @hook TARGET_CAN_INLINE_P
  
+ @hook TARGET_CAN_COMPARE_AND_SWAP_P
+ 
  @node Emulated TLS
  @section Emulating TLS
  @cindex Emulated TLS
Index: java/builtins.c
===================================================================
*** java/builtins.c	(revision 217057)
--- java/builtins.c	(working copy)
*************** The Free Software Foundation is independ
*** 37,49 ****
  #include "flags.h"
  #include "langhooks.h"
  #include "java-tree.h"
! 
! /* FIXME: All these headers are necessary for sync_compare_and_swap.
!    Front ends should never have to look at that.  */
! #include "rtl.h"
! #include "insn-codes.h"
! #include "expr.h"
! #include "optabs.h"
  
  static tree max_builtin (tree, tree);
  static tree min_builtin (tree, tree);
--- 37,43 ----
  #include "flags.h"
  #include "langhooks.h"
  #include "java-tree.h"
! #include "target.h"
  
  static tree max_builtin (tree, tree);
  static tree min_builtin (tree, tree);
*************** compareAndSwapInt_builtin (tree method_r
*** 320,326 ****
  			   tree orig_call)
  {
    machine_mode mode = TYPE_MODE (int_type_node);
!   if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
      {
        tree addr, stmt;
        enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
--- 314,321 ----
  			   tree orig_call)
  {
    machine_mode mode = TYPE_MODE (int_type_node);
!   if (targetm.target_option.can_compare_and_swap_p (mode,
! 						    flag_use_atomic_builtins))
      {
        tree addr, stmt;
        enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_4;
*************** compareAndSwapLong_builtin (tree method_
*** 344,352 ****
    /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
       Some machines such as ARM have atomic libfuncs but not the multi-word
       versions.  */
!   if (can_compare_and_swap_p (mode,
! 			      (flag_use_atomic_builtins
! 			       && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
      {
        tree addr, stmt;
        enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
--- 339,347 ----
    /* We don't trust flag_use_atomic_builtins for multi-word compareAndSwap.
       Some machines such as ARM have atomic libfuncs but not the multi-word
       versions.  */
!   if (targetm.target_option.can_compare_and_swap_p (mode,
! 				  (flag_use_atomic_builtins
! 				   && GET_MODE_SIZE (mode) <= UNITS_PER_WORD)))
      {
        tree addr, stmt;
        enum built_in_function fncode = BUILT_IN_SYNC_BOOL_COMPARE_AND_SWAP_8;
*************** compareAndSwapObject_builtin (tree metho
*** 366,372 ****
  			      tree orig_call)
  {
    machine_mode mode = TYPE_MODE (ptr_type_node);
!   if (can_compare_and_swap_p (mode, flag_use_atomic_builtins))
    {
      tree addr, stmt;
      enum built_in_function builtin;
--- 361,368 ----
  			      tree orig_call)
  {
    machine_mode mode = TYPE_MODE (ptr_type_node);
!   if (targetm.target_option.can_compare_and_swap_p (mode,
! 						    flag_use_atomic_builtins))
    {
      tree addr, stmt;
      enum built_in_function builtin;
*************** VMSupportsCS8_builtin (tree method_retur
*** 446,452 ****
  {
    machine_mode mode = TYPE_MODE (long_type_node);
    gcc_assert (method_return_type == boolean_type_node);
!   if (can_compare_and_swap_p (mode, false))
      return boolean_true_node;
    else
      return boolean_false_node;
--- 442,448 ----
  {
    machine_mode mode = TYPE_MODE (long_type_node);
    gcc_assert (method_return_type == boolean_type_node);
!   if (targetm.target_option.can_compare_and_swap_p (mode, false))
      return boolean_true_node;
    else
      return boolean_false_node;

             reply	other threads:[~2014-11-04 16:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 16:28 Andrew MacLeod [this message]
2014-11-04 17:26 ` Richard Henderson
2014-11-04 17:56   ` Andrew MacLeod
2014-11-04 17:58     ` Richard Henderson
2014-11-04 18:30       ` Andrew MacLeod
2014-11-04 19:53         ` Richard Biener
2014-11-04 20:13           ` Andrew MacLeod
2014-11-06 17:57             ` Andrew MacLeod
2014-11-06 18:23               ` Andrew Haley
2014-11-06 19:05                 ` Andrew MacLeod
2014-11-07  9:31                   ` Andrew Haley
2014-11-07 13:31                     ` Andrew MacLeod

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5458FE9C.2090409@redhat.com \
    --to=amacleod@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=richard.guenther@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).