From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13623 invoked by alias); 28 Oct 2011 04:08:24 -0000 Received: (qmail 13479 invoked by uid 22791); 28 Oct 2011 04:08:21 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Oct 2011 04:07:51 +0000 Received: by ywf9 with SMTP id 9so3781664ywf.20 for ; Thu, 27 Oct 2011 21:07:51 -0700 (PDT) Received: by 10.236.133.241 with SMTP id q77mr788753yhi.117.1319774871142; Thu, 27 Oct 2011 21:07:51 -0700 (PDT) Received: from localhost.localdomain (c-98-203-235-125.hsd1.wa.comcast.net. [98.203.235.125]) by mx.google.com with ESMTPS id j25sm10849016yhm.12.2011.10.27.21.07.50 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Oct 2011 21:07:50 -0700 (PDT) From: Richard Henderson To: gcc-patches@gcc.gnu.org Cc: amacleod@redhat.com Subject: [PATCH 3/9] Introduce and use can_compare_and_swap_p. Date: Fri, 28 Oct 2011 04:08:00 -0000 Message-Id: <1319774858-9181-4-git-send-email-rth@redhat.com> In-Reply-To: <1319774858-9181-1-git-send-email-rth@redhat.com> References: <1319774858-9181-1-git-send-email-rth@redhat.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-10/txt/msg02605.txt.bz2 --- gcc/builtins.c | 7 +++---- gcc/omp-low.c | 3 +-- gcc/optabs.c | 27 +++++++++++++++++++++++---- gcc/optabs.h | 3 +++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 3367b50..cb9da83 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5452,12 +5452,11 @@ fold_builtin_atomic_always_lock_free (tree arg) of the pattern indicates support is present. */ size = INTVAL (expand_normal (arg)) * BITS_PER_UNIT; mode = mode_for_size (size, MODE_INT, 0); - icode = direct_optab_handler (sync_compare_and_swap_optab, mode); - if (icode == CODE_FOR_nothing) + if (can_compare_and_swap_p (mode)) + return integer_one_node; + else return integer_zero_node; - - return integer_one_node; } /* Return true if the first argument to call EXP represents a size of diff --git a/gcc/omp-low.c b/gcc/omp-low.c index 05a3493..5faa084 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -5190,8 +5190,7 @@ expand_omp_atomic_pipeline (basic_block load_bb, basic_block store_bb, type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (addr))); itype = TREE_TYPE (TREE_TYPE (cmpxchg)); - if (direct_optab_handler (sync_compare_and_swap_optab, TYPE_MODE (itype)) - == CODE_FOR_nothing) + if (!can_compare_and_swap_p (TYPE_MODE (itype))) return false; /* Load the initial value, replacing the GIMPLE_OMP_ATOMIC_LOAD. */ diff --git a/gcc/optabs.c b/gcc/optabs.c index 307101b..9b4d6cf 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -6778,6 +6778,27 @@ expand_vec_cond_expr (tree vec_cond_type, tree op0, tree op1, tree op2, } +/* Return true if there is a compare_and_swap pattern. */ + +bool +can_compare_and_swap_p (enum machine_mode mode) +{ + enum insn_code icode; + + /* Check for __sync_compare_and_swap. */ + icode = direct_optab_handler (sync_compare_and_swap_optab, mode); + if (icode != CODE_FOR_nothing) + return true; + + /* Check for __atomic_compare_and_swap. */ + icode = direct_optab_handler (atomic_compare_and_swap_optab, mode); + if (icode != CODE_FOR_nothing) + return true; + + /* No inline compare and swap. */ + return false; +} + /* This is an internal subroutine of the other compare_and_swap expanders. MEM, OLD_VAL and NEW_VAL are as you'd expect for a compare-and-swap operation. TARGET is an optional place to store the value result of @@ -7014,8 +7035,7 @@ expand_atomic_exchange (rtx target, rtx mem, rtx val, enum memmodel model) delete_insns_since (last_insn); /* Otherwise, use a compare-and-swap loop for the exchange. */ - if (direct_optab_handler (sync_compare_and_swap_optab, mode) - != CODE_FOR_nothing) + if (can_compare_and_swap_p (mode)) { if (!target || !register_operand (target, mode)) target = gen_reg_rtx (mode); @@ -7451,8 +7471,7 @@ expand_atomic_fetch_op (rtx target, rtx mem, rtx val, enum rtx_code code, } /* If nothing else has succeeded, default to a compare and swap loop. */ - if (direct_optab_handler (sync_compare_and_swap_optab, mode) - != CODE_FOR_nothing) + if (can_compare_and_swap_p (mode)) { rtx insn; rtx t0 = gen_reg_rtx (mode), t1; diff --git a/gcc/optabs.h b/gcc/optabs.h index 84e18e6..eabc994 100644 --- a/gcc/optabs.h +++ b/gcc/optabs.h @@ -952,6 +952,9 @@ extern void expand_float (rtx, rtx, int); /* Return the insn_code for a FLOAT_EXPR. */ enum insn_code can_float_p (enum machine_mode, enum machine_mode, int); +/* Return true if there is an inline compare and swap pattern. */ +extern bool can_compare_and_swap_p (enum machine_mode); + /* Generate code for a FIX_EXPR. */ extern void expand_fix (rtx, rtx, int); -- 1.7.6.4