From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 115363 invoked by alias); 26 Jun 2015 12:05:26 -0000 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 Received: (qmail 115215 invoked by uid 89); 26 Jun 2015 12:05:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.4 required=5.0 tests=AWL,BAYES_50,SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Jun 2015 12:05:18 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-21-q_sfPkwJSdqGpZcJxYG4HA-1 Received: from e106327-lin.cambridge.arm.com ([10.1.2.79]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 26 Jun 2015 13:05:15 +0100 Message-ID: <558D3FFB.8080207@arm.com> Date: Fri, 26 Jun 2015 12:06:00 -0000 From: Matthew Wahab User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: gcc-patches Subject: [PATCH 1/4][PR target/65697][5.1] Backport stronger barriers for GCC,__sync builtins on Aarch64 X-MC-Unique: q_sfPkwJSdqGpZcJxYG4HA-1 Content-Type: multipart/mixed; boundary="------------070701080009000309060208" X-IsSubscribed: yes X-SW-Source: 2015-06/txt/msg01938.txt.bz2 This is a multi-part message in MIME format. --------------070701080009000309060208 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-length: 4311 Hello, The __sync builtins are implemented using barriers that are too weak for AR= Mv8 targets, this has been fixed on trunk for Aarch64. Since GCC-5.1 is also generating the incorrect code, it should also be fixed. The fix on trunk involved changes to the way that memory orders represent barriers for __sync builtins and changes to the code generated by the Aarch64 back-end. This patch backports the changes made to the handling of = memory orders. The trunk patch submission is at https://gcc.gnu.org/ml/gcc-patches/2015-05/msg00557.html. The commit is at https://gcc.gnu.org/viewcvs?rev=3D223096&root=3Dgcc&view= =3Drev Testing: - Checked aarch64-none-linux-gnu with check-gcc - Bootstrapped x86_64-unknown-linux-gnu - Built all targets (for c and c++) in config-list.mk with no new compiliat= ion errors. (I needed to remove the --enable-werror-always flag to get round= a printf format warning that I believe is unrelated to the change.) Ok for the branch? Matthew 2015-06-26 Matthew Wahab Backport from trunk 2015-05-12 Andrew MacLeod PR target/65697 * coretypes.h (MEMMODEL_SYNC, MEMMODEL_BASE_MASK): New macros. (enum memmodel): Add SYNC_{ACQUIRE,RELEASE,SEQ_CST}. * tree.h (memmodel_from_int, memmodel_base, is_mm_relaxed, is_mm_consume,is_mm_acquire, is_mm_release, is_mm_acq_rel, is_mm_seq_cst, is_mm_sync): New accessor functions. * builtins.c (expand_builtin_sync_operation, expand_builtin_compare_and_swap): Use MEMMODEL_SYNC_SEQ_CST. (expand_builtin_sync_lock_release): Use MEMMODEL_SYNC_RELEASE. (get_memmodel, expand_builtin_atomic_compare_exchange, expand_builtin_atomic_load, expand_builtin_atomic_store, expand_builtin_atomic_clear): Use new accessor routines. (expand_builtin_sync_synchronize): Use MEMMODEL_SYNC_SEQ_CST. * optabs.c (expand_compare_and_swap_loop): Use MEMMODEL_SYNC_SEQ_CST. (maybe_emit_sync_lock_test_and_set): Use new accessors and MEMMODEL_SYNC_ACQUIRE. (expand_sync_lock_test_and_set): Use MEMMODEL_SYNC_ACQUIRE. (expand_mem_thread_fence, expand_mem_signal_fence, expand_atomic_load, expand_atomic_store): Use new accessors. * emit-rtl.c (need_atomic_barrier_p): Add additional enum cases. * tsan.c (instrument_builtin_call): Update check for memory model bey= ond final enum to use MEMMODEL_LAST. * c-family/c-common.c: Use new accessor for memmodel_base. * config/aarch64/aarch64.c (aarch64_expand_compare_and_swap): Use new accessors. * config/aarch64/atomics.md (atomic_load,atomic_store, arch64_load_exclusive, aarch64_store_exclusive, mem_thread_fence, *dmb): Likewise. * config/alpha/alpha.c (alpha_split_compare_and_swap, alpha_split_compare_and_swap_12): Likewise. * config/arm/arm.c (arm_expand_compare_and_swap, arm_split_compare_and_swap, arm_split_atomic_op): Likewise. * config/arm/sync.md (atomic_load, atomic_store, atomic_loaddi): Likewise. * config/i386/i386.c (ix86_destroy_cost_data, ix86_memmodel_check): Likewise. * config/i386/sync.md (mem_thread_fence, atomic_store): Likewis= e. * config/ia64/ia64.c (ia64_expand_atomic_op): Add new memmodel cases = and use new accessors. * config/ia64/sync.md (mem_thread_fence, atomic_load, atomic_store, atomic_compare_and_swap, atomic_exchange): Use new accessors. * config/mips/mips.c (mips_process_sync_loop): Likewise. * config/pa/pa.md (atomic_loaddi, atomic_storedi): Likewise. * config/rs6000/rs6000.c (rs6000_pre_atomic_barrier, rs6000_post_atomic_barrier): Add new cases. (rs6000_expand_atomic_compare_and_swap): Use new accessors. * config/rs6000/sync.md (mem_thread_fence): Add new cases. (atomic_load): Add new cases and use new accessors. (store_quadpti): Add new cases. * config/s390/s390.md (mem_thread_fence, atomic_store): Use new accessors. * config/sparc/sparc.c (sparc_emit_membar_for_model): Use new accesso= rs. * doc/extend.texi: Update docs to indicate 16 bits are used for memory model, not 8. --------------070701080009000309060208 Content-Type: text/x-patch; name=0001-Backport-2015-05-12-Andrew-MacLeod-amacleod-redhat.c.patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-Backport-2015-05-12-Andrew-MacLeod-amacleod-redhat.c.pa"; filename*1="tch" Content-length: 45007 =46rom 4797f71dc0946cbb5a7541abd90932cef25fbfa1 Mon Sep 17 00:00:00 2001 From: amacleod Date: Tue, 12 May 2015 20:01:47 +0000 Subject: [PATCH 1/4] Backport 2015-05-12 Andrew MacLeod=20 PR target/65697 * coretypes.h (MEMMODEL_SYNC, MEMMODEL_BASE_MASK): New macros. (enum memmodel): Add SYNC_{ACQUIRE,RELEASE,SEQ_CST}. * tree.h (memmodel_from_int, memmodel_base, is_mm_relaxed, is_mm_consume,is_mm_acquire, is_mm_release, is_mm_acq_rel, is_mm_seq_cst, is_mm_sync): New accessor functions. * builtins.c (expand_builtin_sync_operation, expand_builtin_compare_and_swap): Use MEMMODEL_SYNC_SEQ_CST. (expand_builtin_sync_lock_release): Use MEMMODEL_SYNC_RELEASE. (get_memmodel, expand_builtin_atomic_compare_exchange, expand_builtin_atomic_load, expand_builtin_atomic_store, expand_builtin_atomic_clear): Use new accessor routines. (expand_builtin_sync_synchronize): Use MEMMODEL_SYNC_SEQ_CST. * optabs.c (expand_compare_and_swap_loop): Use MEMMODEL_SYNC_SEQ_CST. (maybe_emit_sync_lock_test_and_set): Use new accessors and MEMMODEL_SYNC_ACQUIRE. (expand_sync_lock_test_and_set): Use MEMMODEL_SYNC_ACQUIRE. (expand_mem_thread_fence, expand_mem_signal_fence, expand_atomic_load, expand_atomic_store): Use new accessors. * emit-rtl.c (need_atomic_barrier_p): Add additional enum cases. * tsan.c (instrument_builtin_call): Update check for memory model beyond final enum to use MEMMODEL_LAST. * c-family/c-common.c: Use new accessor for memmodel_base. * config/aarch64/aarch64.c (aarch64_expand_compare_and_swap): Use new accessors. * config/aarch64/atomics.md (atomic_load,atomic_store, arch64_load_exclusive, aarch64_store_exclusive, mem_thread_fence, *dmb): Likewise. * config/alpha/alpha.c (alpha_split_compare_and_swap, alpha_split_compare_and_swap_12): Likewise. * config/arm/arm.c (arm_expand_compare_and_swap, arm_split_compare_and_swap, arm_split_atomic_op): Likewise. * config/arm/sync.md (atomic_load, atomic_store, atomic_loaddi): Likewise. * config/i386/i386.c (ix86_destroy_cost_data, ix86_memmodel_check): Likewise. * config/i386/sync.md (mem_thread_fence, atomic_store): Likewise. * config/ia64/ia64.c (ia64_expand_atomic_op): Add new memmodel cases and use new accessors. * config/ia64/sync.md (mem_thread_fence, atomic_load, atomic_store, atomic_compare_and_swap, atomic_exchange): Use new accessors. * config/mips/mips.c (mips_process_sync_loop): Likewise. * config/pa/pa.md (atomic_loaddi, atomic_storedi): Likewise. * config/rs6000/rs6000.c (rs6000_pre_atomic_barrier, rs6000_post_atomic_barrier): Add new cases. (rs6000_expand_atomic_compare_and_swap): Use new accessors. * config/rs6000/sync.md (mem_thread_fence): Add new cases. (atomic_load): Add new cases and use new accessors. (store_quadpti): Add new cases. * config/s390/s390.md (mem_thread_fence, atomic_store): Use new accessors. * config/sparc/sparc.c (sparc_emit_membar_for_model): Use new accessors. * doc/extend.texi: Update docs to indicate 16 bits are used for memory model, not 8. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223096 138bc75d-0d04-0410-9= 61f-82ee72b054a4 Conflicts: gcc/ChangeLog Change-Id: I7a995fbd128c6db920a89d5417d216f51769a875 --- gcc/builtins.c | 28 +++++++++---------- gcc/c-family/c-common.c | 2 +- gcc/config/aarch64/aarch64.c | 4 +-- gcc/config/aarch64/atomics.md | 38 ++++++++++---------------- gcc/config/alpha/alpha.c | 16 +++++------ gcc/config/arm/arm.c | 36 +++++++++++-------------- gcc/config/arm/sync.md | 16 +++++------ gcc/config/i386/i386.c | 8 +++--- gcc/config/i386/sync.md | 10 +++---- gcc/config/ia64/ia64.c | 9 +++++-- gcc/config/ia64/sync.md | 18 +++++++------ gcc/config/mips/mips.c | 2 +- gcc/config/pa/pa.md | 8 +++--- gcc/config/rs6000/rs6000.c | 14 +++++++--- gcc/config/rs6000/sync.md | 15 ++++++++--- gcc/config/s390/s390.md | 6 ++--- gcc/config/sparc/sparc.c | 10 +++---- gcc/coretypes.h | 20 +++++++++++--- gcc/doc/extend.texi | 4 +-- gcc/emit-rtl.c | 3 +++ gcc/optabs.c | 23 ++++++++-------- gcc/tree.h | 63 +++++++++++++++++++++++++++++++++++++++= ++++ gcc/tsan.c | 6 ++--- 23 files changed, 216 insertions(+), 143 deletions(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 9263777..b1e2b84 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -5271,7 +5271,7 @@ expand_builtin_sync_operation (machine_mode mode, tre= e exp, mem =3D get_builtin_sync_mem (CALL_EXPR_ARG (exp, 0), mode); val =3D expand_expr_force_mode (CALL_EXPR_ARG (exp, 1), mode); =20 - return expand_atomic_fetch_op (target, mem, val, code, MEMMODEL_SEQ_CST, + return expand_atomic_fetch_op (target, mem, val, code, MEMMODEL_SYNC_SEQ= _CST, after); } =20 @@ -5301,8 +5301,8 @@ expand_builtin_compare_and_swap (machine_mode mode, t= ree exp, poval =3D ⌖ } if (!expand_atomic_compare_and_swap (pbool, poval, mem, old_val, new_val, - false, MEMMODEL_SEQ_CST, - MEMMODEL_SEQ_CST)) + false, MEMMODEL_SYNC_SEQ_CST, + MEMMODEL_SYNC_SEQ_CST)) return NULL_RTX; =20 return target; @@ -5337,7 +5337,7 @@ expand_builtin_sync_lock_release (machine_mode mode, = tree exp) /* Expand the operands. */ mem =3D get_builtin_sync_mem (CALL_EXPR_ARG (exp, 0), mode); =20 - expand_atomic_store (mem, const0_rtx, MEMMODEL_RELEASE, true); + expand_atomic_store (mem, const0_rtx, MEMMODEL_SYNC_RELEASE, true); } =20 /* Given an integer representing an ``enum memmodel'', verify its @@ -5366,7 +5366,8 @@ get_memmodel (tree exp) return MEMMODEL_SEQ_CST; } =20 - if ((INTVAL (op) & MEMMODEL_MASK) >=3D MEMMODEL_LAST) + /* Should never see a user explicit SYNC memodel model, so >=3D LAST wor= ks. */ + if (memmodel_base (val) >=3D MEMMODEL_LAST) { warning (OPT_Winvalid_memory_model, "invalid memory model argument to builtin"); @@ -5433,8 +5434,7 @@ expand_builtin_atomic_compare_exchange (machine_mode = mode, tree exp, success =3D MEMMODEL_SEQ_CST; } =20=20 - if ((failure & MEMMODEL_MASK) =3D=3D MEMMODEL_RELEASE - || (failure & MEMMODEL_MASK) =3D=3D MEMMODEL_ACQ_REL) + if (is_mm_release (failure) || is_mm_acq_rel (failure)) { warning (OPT_Winvalid_memory_model, "invalid failure memory model for " @@ -5496,8 +5496,7 @@ expand_builtin_atomic_load (machine_mode mode, tree e= xp, rtx target) enum memmodel model; =20 model =3D get_memmodel (CALL_EXPR_ARG (exp, 1)); - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_RELEASE - || (model & MEMMODEL_MASK) =3D=3D MEMMODEL_ACQ_REL) + if (is_mm_release (model) || is_mm_acq_rel (model)) { warning (OPT_Winvalid_memory_model, "invalid memory model for %<__atomic_load%>"); @@ -5526,9 +5525,8 @@ expand_builtin_atomic_store (machine_mode mode, tree = exp) enum memmodel model; =20 model =3D get_memmodel (CALL_EXPR_ARG (exp, 2)); - if ((model & MEMMODEL_MASK) !=3D MEMMODEL_RELAXED - && (model & MEMMODEL_MASK) !=3D MEMMODEL_SEQ_CST - && (model & MEMMODEL_MASK) !=3D MEMMODEL_RELEASE) + if (!(is_mm_relaxed (model) || is_mm_seq_cst (model) + || is_mm_release (model))) { warning (OPT_Winvalid_memory_model, "invalid memory model for %<__atomic_store%>"); @@ -5635,9 +5633,7 @@ expand_builtin_atomic_clear (tree exp) mem =3D get_builtin_sync_mem (CALL_EXPR_ARG (exp, 0), mode); model =3D get_memmodel (CALL_EXPR_ARG (exp, 1)); =20 - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_CONSUME - || (model & MEMMODEL_MASK) =3D=3D MEMMODEL_ACQUIRE - || (model & MEMMODEL_MASK) =3D=3D MEMMODEL_ACQ_REL) + if (is_mm_consume (model) || is_mm_acquire (model) || is_mm_acq_rel (mod= el)) { warning (OPT_Winvalid_memory_model, "invalid memory model for %<__atomic_store%>"); @@ -5833,7 +5829,7 @@ expand_builtin_atomic_signal_fence (tree exp) static void expand_builtin_sync_synchronize (void) { - expand_mem_thread_fence (MEMMODEL_SEQ_CST); + expand_mem_thread_fence (MEMMODEL_SYNC_SEQ_CST); } =20 static rtx diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 7fe7fa6..117f89c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -10741,7 +10741,7 @@ get_atomic_generic_size (location_t loc, tree funct= ion, if (TREE_CODE (p) =3D=3D INTEGER_CST) { int i =3D tree_to_uhwi (p); - if (i < 0 || (i & MEMMODEL_MASK) >=3D MEMMODEL_LAST) + if (i < 0 || (memmodel_base (i) >=3D MEMMODEL_LAST)) { warning_at (loc, OPT_Winvalid_memory_model, "invalid memory model argument %d of %qE", x + 1, diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 6f86ede..b8b37b8 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -9020,8 +9020,8 @@ aarch64_expand_compare_and_swap (rtx operands[]) unlikely event of fail being ACQUIRE and succ being RELEASE we need to promote succ to ACQ_REL so that we don't lose the acquire semantics. = */ =20 - if (INTVAL (mod_f) =3D=3D MEMMODEL_ACQUIRE - && INTVAL (mod_s) =3D=3D MEMMODEL_RELEASE) + if (is_mm_acquire (memmodel_from_int (INTVAL (mod_f))) + && is_mm_release (memmodel_from_int (INTVAL (mod_s)))) mod_s =3D GEN_INT (MEMMODEL_ACQ_REL); =20 switch (mode) diff --git a/gcc/config/aarch64/atomics.md b/gcc/config/aarch64/atomics.md index 939a11e..1a38ac0 100644 --- a/gcc/config/aarch64/atomics.md +++ b/gcc/config/aarch64/atomics.md @@ -260,10 +260,8 @@ UNSPECV_LDA))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_RELEASE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_release (m= odel)) return "ldr\t%0, %1"; else return "ldar\t%0, %1"; @@ -278,10 +276,8 @@ UNSPECV_STL))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_ACQUIRE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_acquire (m= odel)) return "str\t%1, %0"; else return "stlr\t%1, %0"; @@ -297,10 +293,8 @@ UNSPECV_LX)))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_RELEASE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_release (m= odel)) return "ldxr\t%w0, %1"; else return "ldaxr\t%w0, %1"; @@ -315,10 +309,8 @@ UNSPECV_LX))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_RELEASE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_release (m= odel)) return "ldxr\t%0, %1"; else return "ldaxr\t%0, %1"; @@ -335,10 +327,8 @@ UNSPECV_SX))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[3]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_ACQUIRE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[3])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_acquire (m= odel)) return "stxr\t%w0, %2, %1"; else return "stlxr\t%w0, %2, %1"; @@ -349,8 +339,8 @@ [(match_operand:SI 0 "const_int_operand" "")] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[0]); - if (model !=3D MEMMODEL_RELAXED && model !=3D MEMMODEL_CONSUME) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[0])); + if (!(is_mm_relaxed (model) || is_mm_consume (model))) emit_insn (gen_dmb (operands[0])); DONE; } @@ -373,8 +363,8 @@ UNSPEC_MB))] "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[1]); - if (model =3D=3D MEMMODEL_ACQUIRE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[1])); + if (is_mm_acquire (model)) return "dmb\\tishld"; else return "dmb\\tish"; diff --git a/gcc/config/alpha/alpha.c b/gcc/config/alpha/alpha.c index 864a8fc..731a966 100644 --- a/gcc/config/alpha/alpha.c +++ b/gcc/config/alpha/alpha.c @@ -4548,8 +4548,8 @@ alpha_split_compare_and_swap (rtx operands[]) oldval =3D operands[3]; newval =3D operands[4]; is_weak =3D (operands[5] !=3D const0_rtx); - mod_s =3D (enum memmodel) INTVAL (operands[6]); - mod_f =3D (enum memmodel) INTVAL (operands[7]); + mod_s =3D memmodel_from_int (INTVAL (operands[6])); + mod_f =3D memmodel_from_int (INTVAL (operands[7])); mode =3D GET_MODE (mem); =20 alpha_pre_atomic_barrier (mod_s); @@ -4587,12 +4587,12 @@ alpha_split_compare_and_swap (rtx operands[]) emit_unlikely_jump (x, label1); } =20 - if (mod_f !=3D MEMMODEL_RELAXED) + if (!is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); =20 alpha_post_atomic_barrier (mod_s); =20 - if (mod_f =3D=3D MEMMODEL_RELAXED) + if (is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); } =20 @@ -4653,8 +4653,8 @@ alpha_split_compare_and_swap_12 (rtx operands[]) newval =3D operands[4]; align =3D operands[5]; is_weak =3D (operands[6] !=3D const0_rtx); - mod_s =3D (enum memmodel) INTVAL (operands[7]); - mod_f =3D (enum memmodel) INTVAL (operands[8]); + mod_s =3D memmodel_from_int (INTVAL (operands[7])); + mod_f =3D memmodel_from_int (INTVAL (operands[8])); scratch =3D operands[9]; mode =3D GET_MODE (orig_mem); addr =3D XEXP (orig_mem, 0); @@ -4706,12 +4706,12 @@ alpha_split_compare_and_swap_12 (rtx operands[]) emit_unlikely_jump (x, label1); } =20 - if (mod_f !=3D MEMMODEL_RELAXED) + if (!is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); =20 alpha_post_atomic_barrier (mod_s); =20 - if (mod_f =3D=3D MEMMODEL_RELAXED) + if (is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); } =20 diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 292fed9..7b279c7 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -27663,8 +27663,8 @@ arm_expand_compare_and_swap (rtx operands[]) promote succ to ACQ_REL so that we don't lose the acquire semantics. = */ =20 if (TARGET_HAVE_LDACQ - && INTVAL (mod_f) =3D=3D MEMMODEL_ACQUIRE - && INTVAL (mod_s) =3D=3D MEMMODEL_RELEASE) + && is_mm_acquire (memmodel_from_int (INTVAL (mod_f))) + && is_mm_release (memmodel_from_int (INTVAL (mod_s)))) mod_s =3D GEN_INT (MEMMODEL_ACQ_REL); =20 switch (mode) @@ -27737,20 +27737,18 @@ arm_split_compare_and_swap (rtx operands[]) oldval =3D operands[2]; newval =3D operands[3]; is_weak =3D (operands[4] !=3D const0_rtx); - mod_s =3D (enum memmodel) INTVAL (operands[5]); - mod_f =3D (enum memmodel) INTVAL (operands[6]); + mod_s =3D memmodel_from_int (INTVAL (operands[5])); + mod_f =3D memmodel_from_int (INTVAL (operands[6])); scratch =3D operands[7]; mode =3D GET_MODE (mem); =20 bool use_acquire =3D TARGET_HAVE_LDACQ - && !(mod_s =3D=3D MEMMODEL_RELAXED - || mod_s =3D=3D MEMMODEL_CONSUME - || mod_s =3D=3D MEMMODEL_RELEASE); - + && !(is_mm_relaxed (mod_s) || is_mm_consume (mod_s) + || is_mm_release (mod_s)); +=09=09 bool use_release =3D TARGET_HAVE_LDACQ - && !(mod_s =3D=3D MEMMODEL_RELAXED - || mod_s =3D=3D MEMMODEL_CONSUME - || mod_s =3D=3D MEMMODEL_ACQUIRE); + && !(is_mm_relaxed (mod_s) || is_mm_consume (mod_s) + || is_mm_acquire (mod_s)); =20 /* Checks whether a barrier is needed and emits one accordingly. */ if (!(use_acquire || use_release)) @@ -27788,14 +27786,14 @@ arm_split_compare_and_swap (rtx operands[]) emit_unlikely_jump (gen_rtx_SET (VOIDmode, pc_rtx, x)); } =20 - if (mod_f !=3D MEMMODEL_RELAXED) + if (!is_mm_relaxed (mod_f)) emit_label (label2); =20 /* Checks whether a barrier is needed and emits one accordingly. */ if (!(use_acquire || use_release)) arm_post_atomic_barrier (mod_s); =20 - if (mod_f =3D=3D MEMMODEL_RELAXED) + if (is_mm_relaxed (mod_f)) emit_label (label2); } =20 @@ -27803,21 +27801,19 @@ void arm_split_atomic_op (enum rtx_code code, rtx old_out, rtx new_out, rtx mem, rtx value, rtx model_rtx, rtx cond) { - enum memmodel model =3D (enum memmodel) INTVAL (model_rtx); + enum memmodel model =3D memmodel_from_int (INTVAL (model_rtx)); machine_mode mode =3D GET_MODE (mem); machine_mode wmode =3D (mode =3D=3D DImode ? DImode : SImode); rtx_code_label *label; rtx x; =20 bool use_acquire =3D TARGET_HAVE_LDACQ - && !(model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_RELEASE); + && !(is_mm_relaxed (model) || is_mm_consume (model) + || is_mm_release (model)); =20 bool use_release =3D TARGET_HAVE_LDACQ - && !(model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_ACQUIRE); + && !(is_mm_relaxed (model) || is_mm_consume (model) + || is_mm_acquire (model)); =20 /* Checks whether a barrier is needed and emits one accordingly. */ if (!(use_acquire || use_release)) diff --git a/gcc/config/arm/sync.md b/gcc/config/arm/sync.md index 78bdafc..44cda61 100644 --- a/gcc/config/arm/sync.md +++ b/gcc/config/arm/sync.md @@ -73,10 +73,8 @@ VUNSPEC_LDA))] "TARGET_HAVE_LDACQ" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_RELEASE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_release (m= odel)) return \"ldr\\t%0, %1\"; else return \"lda\\t%0, %1\"; @@ -91,10 +89,8 @@ VUNSPEC_STL))] "TARGET_HAVE_LDACQ" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); - if (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_CONSUME - || model =3D=3D MEMMODEL_ACQUIRE) + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); + if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_acquire (m= odel)) return \"str\t%1, %0\"; else return \"stl\t%1, %0\"; @@ -110,10 +106,10 @@ (match_operand:SI 2 "const_int_operand")] ;; model "TARGET_HAVE_LDREXD && ARM_DOUBLEWORD_ALIGN" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); expand_mem_thread_fence (model); emit_insn (gen_atomic_loaddi_1 (operands[0], operands[1])); - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); DONE; }) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 7c28a55..6851890 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -51516,7 +51516,7 @@ ix86_destroy_cost_data (void *data) static unsigned HOST_WIDE_INT ix86_memmodel_check (unsigned HOST_WIDE_INT val) { - unsigned HOST_WIDE_INT model =3D val & MEMMODEL_MASK; + enum memmodel model =3D memmodel_from_int (val); bool strong; =20 if (val & ~(unsigned HOST_WIDE_INT)(IX86_HLE_ACQUIRE|IX86_HLE_RELEASE @@ -51527,14 +51527,14 @@ ix86_memmodel_check (unsigned HOST_WIDE_INT val) "Unknown architecture specific memory model"); return MEMMODEL_SEQ_CST; } - strong =3D (model =3D=3D MEMMODEL_ACQ_REL || model =3D=3D MEMMODEL_SEQ_C= ST); - if (val & IX86_HLE_ACQUIRE && !(model =3D=3D MEMMODEL_ACQUIRE || strong)) + strong =3D (is_mm_acq_rel (model) || is_mm_seq_cst (model)); + if (val & IX86_HLE_ACQUIRE && !(is_mm_acquire (model) || strong)) { warning (OPT_Winvalid_memory_model, "HLE_ACQUIRE not used with ACQUIRE or stronger memory model"= ); return MEMMODEL_SEQ_CST | IX86_HLE_ACQUIRE; } - if (val & IX86_HLE_RELEASE && !(model =3D=3D MEMMODEL_RELEASE || strong= )) + if (val & IX86_HLE_RELEASE && !(is_mm_release (model) || strong)) { warning (OPT_Winvalid_memory_model, "HLE_RELEASE not used with RELEASE or stronger memory model"= ); diff --git a/gcc/config/i386/sync.md b/gcc/config/i386/sync.md index 61a2a81..59573d4 100644 --- a/gcc/config/i386/sync.md +++ b/gcc/config/i386/sync.md @@ -105,11 +105,11 @@ [(match_operand:SI 0 "const_int_operand")] ;; model "" { - enum memmodel model =3D (enum memmodel) (INTVAL (operands[0]) & MEMMODEL= _MASK); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[0])); =20 /* Unless this is a SEQ_CST fence, the i386 memory model is strong enough not to require barriers of any kind. */ - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) { rtx (*mfence_insn)(rtx); rtx mem; @@ -217,7 +217,7 @@ UNSPEC_STA))] "" { - enum memmodel model =3D (enum memmodel) (INTVAL (operands[2]) & MEMMODEL= _MASK); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); =20 if (mode =3D=3D DImode && !TARGET_64BIT) { @@ -233,7 +233,7 @@ operands[1] =3D force_reg (mode, operands[1]); =20 /* For seq-cst stores, when we lack MFENCE, use XCHG. */ - if (model =3D=3D MEMMODEL_SEQ_CST && !(TARGET_64BIT || TARGET_SSE2)) + if (is_mm_seq_cst (model) && !(TARGET_64BIT || TARGET_SSE2)) { emit_insn (gen_atomic_exchange (gen_reg_rtx (mode), operands[0], operands[1], @@ -246,7 +246,7 @@ operands[2])); } /* ... followed by an MFENCE, if required. */ - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) emit_insn (gen_mem_thread_fence (operands[2])); DONE; }) diff --git a/gcc/config/ia64/ia64.c b/gcc/config/ia64/ia64.c index 5132d2f..21da9e2 100644 --- a/gcc/config/ia64/ia64.c +++ b/gcc/config/ia64/ia64.c @@ -2389,10 +2389,12 @@ ia64_expand_atomic_op (enum rtx_code code, rtx mem,= rtx val, { case MEMMODEL_ACQ_REL: case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_memory_barrier ()); /* FALLTHRU */ case MEMMODEL_RELAXED: case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: case MEMMODEL_CONSUME: if (mode =3D=3D SImode) icode =3D CODE_FOR_fetchadd_acq_si; @@ -2400,6 +2402,7 @@ ia64_expand_atomic_op (enum rtx_code code, rtx mem, r= tx val, icode =3D CODE_FOR_fetchadd_acq_di; break; case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: if (mode =3D=3D SImode) icode =3D CODE_FOR_fetchadd_rel_si; else @@ -2426,8 +2429,7 @@ ia64_expand_atomic_op (enum rtx_code code, rtx mem, r= tx val, front half of the full barrier. The end half is the cmpxchg.rel. For relaxed and release memory models, we don't need this. But we also don't bother trying to prevent it either. */ - gcc_assert (model =3D=3D MEMMODEL_RELAXED - || model =3D=3D MEMMODEL_RELEASE + gcc_assert (is_mm_relaxed (model) || is_mm_release (model) || MEM_VOLATILE_P (mem)); =20 old_reg =3D gen_reg_rtx (DImode); @@ -2471,6 +2473,7 @@ ia64_expand_atomic_op (enum rtx_code code, rtx mem, r= tx val, { case MEMMODEL_RELAXED: case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: case MEMMODEL_CONSUME: switch (mode) { @@ -2484,8 +2487,10 @@ ia64_expand_atomic_op (enum rtx_code code, rtx mem, = rtx val, break; =20 case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: case MEMMODEL_ACQ_REL: case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: switch (mode) { case QImode: icode =3D CODE_FOR_cmpxchg_rel_qi; break; diff --git a/gcc/config/ia64/sync.md b/gcc/config/ia64/sync.md index 75d746d..9c178b8 100644 --- a/gcc/config/ia64/sync.md +++ b/gcc/config/ia64/sync.md @@ -33,7 +33,7 @@ [(match_operand:SI 0 "const_int_operand" "")] ;; model "" { - if (INTVAL (operands[0]) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (memmodel_from_int (INTVAL (operands[0])))) emit_insn (gen_memory_barrier ()); DONE; }) @@ -60,11 +60,11 @@ (match_operand:SI 2 "const_int_operand" "")] ;; model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); =20 /* Unless the memory model is relaxed, we want to emit ld.acq, which will happen automatically for volatile memories. */ - gcc_assert (model =3D=3D MEMMODEL_RELAXED || MEM_VOLATILE_P (operands[1]= )); + gcc_assert (is_mm_relaxed (model) || MEM_VOLATILE_P (operands[1])); emit_move_insn (operands[0], operands[1]); DONE; }) @@ -75,17 +75,17 @@ (match_operand:SI 2 "const_int_operand" "")] ;; model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); =20 /* Unless the memory model is relaxed, we want to emit st.rel, which will happen automatically for volatile memories. */ - gcc_assert (model =3D=3D MEMMODEL_RELAXED || MEM_VOLATILE_P (operands[0]= )); + gcc_assert (is_mm_relaxed (model) || MEM_VOLATILE_P (operands[0])); emit_move_insn (operands[0], operands[1]); =20 /* Sequentially consistent stores need a subsequent MF. See http://www.decadent.org.uk/pipermail/cpp-threads/2008-December/001952= .html for a discussion of why a MF is needed here, but not for atomic_load.= */ - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) emit_insn (gen_memory_barrier ()); DONE; }) @@ -101,7 +101,8 @@ (match_operand:SI 7 "const_int_operand" "")] ;; fail model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[6]); + /* No need to distinquish __sync from __atomic, so get base value. */ + enum memmodel model =3D memmodel_base (INTVAL (operands[6])); rtx ccv =3D gen_rtx_REG (DImode, AR_CCV_REGNUM); rtx dval, eval; =20 @@ -200,7 +201,8 @@ (match_operand:SI 3 "const_int_operand" "")] ;; succ model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[3]); + /* No need to distinquish __sync from __atomic, so get base value. */ + enum memmodel model =3D memmodel_base (INTVAL (operands[3])); =20 switch (model) { diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c index 1733457..67ec6b9 100644 --- a/gcc/config/mips/mips.c +++ b/gcc/config/mips/mips.c @@ -13111,7 +13111,7 @@ mips_process_sync_loop (rtx_insn *insn, rtx *operan= ds) model =3D MEMMODEL_ACQUIRE; break; default: - model =3D (enum memmodel) INTVAL (operands[memmodel_attr]); + model =3D memmodel_from_int (INTVAL (operands[memmodel_attr])); } =20 mips_multi_start (); diff --git a/gcc/config/pa/pa.md b/gcc/config/pa/pa.md index 2fd2059..9e506ac 100644 --- a/gcc/config/pa/pa.md +++ b/gcc/config/pa/pa.md @@ -707,12 +707,12 @@ (match_operand:SI 2 "const_int_operand")] ;; model "!TARGET_64BIT && !TARGET_SOFT_FLOAT" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); operands[1] =3D force_reg (SImode, XEXP (operands[1], 0)); operands[2] =3D gen_reg_rtx (DImode); expand_mem_thread_fence (model); emit_insn (gen_atomic_loaddi_1 (operands[0], operands[1], operands[2])); - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); DONE; }) @@ -734,12 +734,12 @@ (match_operand:SI 2 "const_int_operand")] ;; model "!TARGET_64BIT && !TARGET_SOFT_FLOAT" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); operands[0] =3D force_reg (SImode, XEXP (operands[0], 0)); operands[2] =3D gen_reg_rtx (DImode); expand_mem_thread_fence (model); emit_insn (gen_atomic_storedi_1 (operands[0], operands[1], operands[2])); - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); DONE; }) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 97c5842..725c6fd 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -20537,12 +20537,15 @@ rs6000_pre_atomic_barrier (rtx mem, enum memmodel= model) case MEMMODEL_RELAXED: case MEMMODEL_CONSUME: case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: break; case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: case MEMMODEL_ACQ_REL: emit_insn (gen_lwsync ()); break; case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_hwsync ()); break; default: @@ -20559,10 +20562,13 @@ rs6000_post_atomic_barrier (enum memmodel model) case MEMMODEL_RELAXED: case MEMMODEL_CONSUME: case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: break; case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: case MEMMODEL_ACQ_REL: case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_isync ()); break; default: @@ -20662,8 +20668,8 @@ rs6000_expand_atomic_compare_and_swap (rtx operands= []) oldval =3D operands[3]; newval =3D operands[4]; is_weak =3D (INTVAL (operands[5]) !=3D 0); - mod_s =3D (enum memmodel) INTVAL (operands[6]); - mod_f =3D (enum memmodel) INTVAL (operands[7]); + mod_s =3D memmodel_from_int (INTVAL (operands[6])); + mod_f =3D memmodel_from_int (INTVAL (operands[7])); orig_mode =3D mode =3D GET_MODE (mem); =20 mask =3D shift =3D NULL_RTX; @@ -20751,12 +20757,12 @@ rs6000_expand_atomic_compare_and_swap (rtx operan= ds[]) emit_unlikely_jump (x, label1); } =20 - if (mod_f !=3D MEMMODEL_RELAXED) + if (!is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); =20 rs6000_post_atomic_barrier (mod_s); =20 - if (mod_f =3D=3D MEMMODEL_RELAXED) + if (is_mm_relaxed (mod_f)) emit_label (XEXP (label2, 0)); =20 if (shift) diff --git a/gcc/config/rs6000/sync.md b/gcc/config/rs6000/sync.md index 4364c85..8ba30b9 100644 --- a/gcc/config/rs6000/sync.md +++ b/gcc/config/rs6000/sync.md @@ -41,18 +41,21 @@ [(match_operand:SI 0 "const_int_operand" "")] ;; model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[0]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[0])); switch (model) { case MEMMODEL_RELAXED: break; case MEMMODEL_CONSUME: case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: case MEMMODEL_ACQ_REL: emit_insn (gen_lwsync ()); break; case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_hwsync ()); break; default: @@ -144,9 +147,9 @@ if (mode =3D=3D TImode && !TARGET_SYNC_TI) FAIL; =20 - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); =20 - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) emit_insn (gen_hwsync ()); =20 if (mode !=3D TImode) @@ -182,7 +185,9 @@ break; case MEMMODEL_CONSUME: case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_loadsync_ (operands[0])); break; default: @@ -209,15 +214,17 @@ if (mode =3D=3D TImode && !TARGET_SYNC_TI) FAIL; =20 - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); switch (model) { case MEMMODEL_RELAXED: break; case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: emit_insn (gen_lwsync ()); break; case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: emit_insn (gen_hwsync ()); break; default: diff --git a/gcc/config/s390/s390.md b/gcc/config/s390/s390.md index 76dca0a..8544f7d 100644 --- a/gcc/config/s390/s390.md +++ b/gcc/config/s390/s390.md @@ -9226,7 +9226,7 @@ { /* Unless this is a SEQ_CST fence, the s390 memory model is strong enough not to require barriers of any kind. */ - if (INTVAL (operands[0]) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (memmodel_from_int (INTVAL (operands[0])))) { rtx mem =3D gen_rtx_MEM (BLKmode, gen_rtx_SCRATCH (Pmode)); MEM_VOLATILE_P (mem) =3D 1; @@ -9307,7 +9307,7 @@ (match_operand:SI 2 "const_int_operand")] ;; model "" { - enum memmodel model =3D (enum memmodel) INTVAL (operands[2]); + enum memmodel model =3D memmodel_from_int (INTVAL (operands[2])); =20 if (MEM_ALIGN (operands[0]) < GET_MODE_BITSIZE (GET_MODE (operands[0]))) FAIL; @@ -9318,7 +9318,7 @@ emit_insn (gen_atomic_storedi_1 (operands[0], operands[1])); else emit_move_insn (operands[0], operands[1]); - if (model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) emit_insn (gen_mem_thread_fence (operands[2])); DONE; }) diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c index 1fd3c1e..f938236 100644 --- a/gcc/config/sparc/sparc.c +++ b/gcc/config/sparc/sparc.c @@ -11678,9 +11678,8 @@ sparc_emit_membar_for_model (enum memmodel model, =20 if (before_after & 1) { - if (model =3D=3D MEMMODEL_RELEASE - || model =3D=3D MEMMODEL_ACQ_REL - || model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_release (model) || is_mm_acq_rel (model) + || is_mm_seq_cst (model)) { if (load_store & 1) mm |=3D LoadLoad | StoreLoad; @@ -11690,9 +11689,8 @@ sparc_emit_membar_for_model (enum memmodel model, } if (before_after & 2) { - if (model =3D=3D MEMMODEL_ACQUIRE - || model =3D=3D MEMMODEL_ACQ_REL - || model =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_acquire (model) || is_mm_acq_rel (model) + || is_mm_seq_cst (model)) { if (load_store & 1) mm |=3D LoadLoad | LoadStore; diff --git a/gcc/coretypes.h b/gcc/coretypes.h index 90fa13f..0ee8633 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -263,6 +263,18 @@ enum function_class { function_c11_misc }; =20 +/* Suppose that higher bits are target dependent. */ +#define MEMMODEL_MASK ((1<<16)-1) + +/* Legacy sync operations set this upper flag in the memory model. This a= llows + targets that need to do something stronger for sync operations to + differentiate with their target patterns and issue a more appropriate i= nsn + sequence. See bugzilla 65697 for background. */ +#define MEMMODEL_SYNC (1<<15) + +/* Memory model without SYNC bit for targets/operations that do not care. = */ +#define MEMMODEL_BASE_MASK (MEMMODEL_SYNC-1) + /* Memory model types for the __atomic* builtins.=20 This must match the order in libstdc++-v3/include/bits/atomic_base.h. = */ enum memmodel @@ -273,12 +285,12 @@ enum memmodel MEMMODEL_RELEASE =3D 3, MEMMODEL_ACQ_REL =3D 4, MEMMODEL_SEQ_CST =3D 5, - MEMMODEL_LAST =3D 6 + MEMMODEL_LAST =3D 6, + MEMMODEL_SYNC_ACQUIRE =3D MEMMODEL_ACQUIRE | MEMMODEL_SYNC, + MEMMODEL_SYNC_RELEASE =3D MEMMODEL_RELEASE | MEMMODEL_SYNC, + MEMMODEL_SYNC_SEQ_CST =3D MEMMODEL_SEQ_CST | MEMMODEL_SYNC }; =20 -/* Suppose that higher bits are target dependent. */ -#define MEMMODEL_MASK ((1<<16)-1) - /* Support for user-provided GGC and PCH markers. The first parameter is a pointer to a pointer, the second a cookie. */ typedef void (*gt_pointer_operator) (void *, void *); diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 79559c8..4f9176e 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -8423,9 +8423,9 @@ functions map any run-time value to @code{__ATOMIC_SE= Q_CST} rather than invoke a runtime library call or inline a switch statement. This is standard compliant, safe, and the simplest approach for now. =20 -The memory model parameter is a signed int, but only the lower 8 bits are +The memory model parameter is a signed int, but only the lower 16 bits are reserved for the memory model. The remainder of the signed int is reserved -for future use and should be 0. Use of the predefined atomic values +for target use and should be 0. Use of the predefined atomic values ensures proper usage. =20 @deftypefn {Built-in Function} @var{type} __atomic_load_n (@var{type} *ptr= , int memmodel) diff --git a/gcc/emit-rtl.c b/gcc/emit-rtl.c index 483eacb..00ba64e 100644 --- a/gcc/emit-rtl.c +++ b/gcc/emit-rtl.c @@ -6323,11 +6323,14 @@ need_atomic_barrier_p (enum memmodel model, bool pr= e) case MEMMODEL_CONSUME: return false; case MEMMODEL_RELEASE: + case MEMMODEL_SYNC_RELEASE: return pre; case MEMMODEL_ACQUIRE: + case MEMMODEL_SYNC_ACQUIRE: return !pre; case MEMMODEL_ACQ_REL: case MEMMODEL_SEQ_CST: + case MEMMODEL_SYNC_SEQ_CST: return true; default: gcc_unreachable (); diff --git a/gcc/optabs.c b/gcc/optabs.c index e9dc798..2d17521 100644 --- a/gcc/optabs.c +++ b/gcc/optabs.c @@ -7178,7 +7178,7 @@ expand_compare_and_swap_loop (rtx mem, rtx old_reg, r= tx new_reg, rtx seq) success =3D NULL_RTX; oldval =3D cmp_reg; if (!expand_atomic_compare_and_swap (&success, &oldval, mem, old_reg, - new_reg, false, MEMMODEL_SEQ_CST, + new_reg, false, MEMMODEL_SYNC_SEQ_CST, MEMMODEL_RELAXED)) return false; =20 @@ -7239,9 +7239,7 @@ maybe_emit_sync_lock_test_and_set (rtx target, rtx me= m, rtx val, exists, and the memory model is stronger than acquire, add a release= =20 barrier before the instruction. */ =20 - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST - || (model & MEMMODEL_MASK) =3D=3D MEMMODEL_RELEASE - || (model & MEMMODEL_MASK) =3D=3D MEMMODEL_ACQ_REL) + if (is_mm_seq_cst (model) || is_mm_release (model) || is_mm_acq_rel (mod= el)) expand_mem_thread_fence (model); =20 if (icode !=3D CODE_FOR_nothing) @@ -7348,11 +7346,12 @@ expand_sync_lock_test_and_set (rtx target, rtx mem,= rtx val) rtx ret; =20 /* Try an atomic_exchange first. */ - ret =3D maybe_emit_atomic_exchange (target, mem, val, MEMMODEL_ACQUIRE); + ret =3D maybe_emit_atomic_exchange (target, mem, val, MEMMODEL_SYNC_ACQU= IRE); if (ret) return ret; =20 - ret =3D maybe_emit_sync_lock_test_and_set (target, mem, val, MEMMODEL_AC= QUIRE); + ret =3D maybe_emit_sync_lock_test_and_set (target, mem, val, + MEMMODEL_SYNC_ACQUIRE); if (ret) return ret; =20 @@ -7363,7 +7362,7 @@ expand_sync_lock_test_and_set (rtx target, rtx mem, r= tx val) /* If there are no other options, try atomic_test_and_set if the value being stored is 1. */ if (val =3D=3D const1_rtx) - ret =3D maybe_emit_atomic_test_and_set (target, mem, MEMMODEL_ACQUIRE); + ret =3D maybe_emit_atomic_test_and_set (target, mem, MEMMODEL_SYNC_ACQ= UIRE); =20 return ret; } @@ -7620,7 +7619,7 @@ expand_mem_thread_fence (enum memmodel model) { if (HAVE_mem_thread_fence) emit_insn (gen_mem_thread_fence (GEN_INT (model))); - else if ((model & MEMMODEL_MASK) !=3D MEMMODEL_RELAXED) + else if (!is_mm_relaxed (model)) { if (HAVE_memory_barrier) emit_insn (gen_memory_barrier ()); @@ -7644,7 +7643,7 @@ expand_mem_signal_fence (enum memmodel model) { if (HAVE_mem_signal_fence) emit_insn (gen_mem_signal_fence (GEN_INT (model))); - else if ((model & MEMMODEL_MASK) !=3D MEMMODEL_RELAXED) + else if (!is_mm_relaxed (model)) { /* By default targets are coherent between a thread and the signal handler running on the same thread. Thus this really becomes a @@ -7699,7 +7698,7 @@ expand_atomic_load (rtx target, rtx mem, enum memmode= l model) target =3D gen_reg_rtx (mode); =20 /* For SEQ_CST, emit a barrier before the load. */ - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); =20 emit_move_insn (target, mem); @@ -7745,7 +7744,7 @@ expand_atomic_store (rtx mem, rtx val, enum memmodel = model, bool use_release) if (maybe_expand_insn (icode, 2, ops)) { /* lock_release is only a release barrier. */ - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); return const0_rtx; } @@ -7772,7 +7771,7 @@ expand_atomic_store (rtx mem, rtx val, enum memmodel = model, bool use_release) emit_move_insn (mem, val); =20 /* For SEQ_CST, also emit a barrier after the store. */ - if ((model & MEMMODEL_MASK) =3D=3D MEMMODEL_SEQ_CST) + if (is_mm_seq_cst (model)) expand_mem_thread_fence (model); =20 return const0_rtx; diff --git a/gcc/tree.h b/gcc/tree.h index 7e5f4b3..9fe3ce6 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4381,6 +4381,69 @@ extern void assign_assembler_name_if_neeeded (tree); extern void warn_deprecated_use (tree, tree); extern void cache_integer_cst (tree); =20 +/* Return the memory model from a host integer. */ +static inline enum memmodel +memmodel_from_int (unsigned HOST_WIDE_INT val) +{ + return (enum memmodel) (val & MEMMODEL_MASK); +} + +/* Return the base memory model from a host integer. */ +static inline enum memmodel +memmodel_base (unsigned HOST_WIDE_INT val) +{ + return (enum memmodel) (val & MEMMODEL_BASE_MASK); +} + +/* Return TRUE if the memory model is RELAXED. */ +static inline bool +is_mm_relaxed (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_RELAXED; +} + +/* Return TRUE if the memory model is CONSUME. */ +static inline bool +is_mm_consume (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_CONSUME; +} + +/* Return TRUE if the memory model is ACQUIRE. */ +static inline bool +is_mm_acquire (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_ACQUIRE; +} + +/* Return TRUE if the memory model is RELEASE. */ +static inline bool +is_mm_release (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_RELEASE; +} + +/* Return TRUE if the memory model is ACQ_REL. */ +static inline bool +is_mm_acq_rel (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_ACQ_REL; +} + +/* Return TRUE if the memory model is SEQ_CST. */ +static inline bool +is_mm_seq_cst (enum memmodel model) +{ + return (model & MEMMODEL_BASE_MASK) =3D=3D MEMMODEL_SEQ_CST; +} + +/* Return TRUE if the memory model is a SYNC variant. */ +static inline bool +is_mm_sync (enum memmodel model) +{ + return (model & MEMMODEL_SYNC); +} + /* Compare and hash for any structure which begins with a canonical pointer. Assumes all pointers are interchangeable, which is sort of already assumed by gcc elsewhere IIRC. */ diff --git a/gcc/tsan.c b/gcc/tsan.c index ebafbb0..2752182 100644 --- a/gcc/tsan.c +++ b/gcc/tsan.c @@ -535,7 +535,7 @@ instrument_builtin_call (gimple_stmt_iterator *gsi) case fetch_op: last_arg =3D gimple_call_arg (stmt, num - 1); if (!tree_fits_uhwi_p (last_arg) - || tree_to_uhwi (last_arg) > MEMMODEL_SEQ_CST) + || memmodel_base (tree_to_uhwi (last_arg)) >=3D MEMMODEL_LAST) return; gimple_call_set_fndecl (stmt, decl); update_stmt (stmt); @@ -600,10 +600,10 @@ instrument_builtin_call (gimple_stmt_iterator *gsi) for (j =3D 0; j < 6; j++) args[j] =3D gimple_call_arg (stmt, j); if (!tree_fits_uhwi_p (args[4]) - || tree_to_uhwi (args[4]) > MEMMODEL_SEQ_CST) + || memmodel_base (tree_to_uhwi (args[4])) >=3D MEMMODEL_LAST) return; if (!tree_fits_uhwi_p (args[5]) - || tree_to_uhwi (args[5]) > MEMMODEL_SEQ_CST) + || memmodel_base (tree_to_uhwi (args[5])) >=3D MEMMODEL_LAST) return; update_gimple_call (gsi, decl, 5, args[0], args[1], args[2], args[4], args[5]); --=20 1.9.1 --------------070701080009000309060208--