From patchwork Mon Mar 14 13:20:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 86735 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 3DB25B6F88 for ; Tue, 15 Mar 2011 00:20:30 +1100 (EST) Received: (qmail 24051 invoked by alias); 14 Mar 2011 13:20:28 -0000 Received: (qmail 24036 invoked by uid 22791); 14 Mar 2011 13:20:27 -0000 X-SWARE-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Mar 2011 13:20:19 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2EDKIBT026868 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Mar 2011 09:20:18 -0400 Received: from houston.quesejoda.com (vpn-227-84.phx2.redhat.com [10.3.227.84]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p2EDKInj016840 for ; Mon, 14 Mar 2011 09:20:18 -0400 Message-ID: <4D7E1611.801@redhat.com> Date: Mon, 14 Mar 2011 08:20:17 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: gcc-patches Subject: [cxx-mem-model] options for controlling data races Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The following patch adds the --param(eters) needed to tweak the optimizers into allowing or disallowing data races in cross-thread visible data. There will be additional flags added later to make these parameters available to the common user. It has been suggested to use -fmemory-model=xxx, but I will implement this later. The next step will be to find out where we introduce the data races in the testsuite, and fix the optimizers accordingly. Committed to branch. * params.h (ALLOW_LOAD_DATA_RACES): New. (ALLOW_STORE_DATA_RACES): New. (ALLOW_PACKED_LOAD_DATA_RACES): New. (ALLOW_PACKED_STORE_DATA_RACES): New. * params.def (PARAM_ALLOW_LOAD_DATA_RACES): New. (PARAM_ALLOW_STORE_DATA_RACES): New. (PARAM_ALLOW_PACKED_LOAD_DATA_RACES): New. (PARAM_ALLOW_PACKED_STORE_DATA_RACES): New. * doc/invoke.texi (Optimize Options): Document above parameters. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 170745) +++ doc/invoke.texi (working copy) @@ -8897,6 +8897,26 @@ partitions. The maximum number of namespaces to consult for suggestions when C++ name lookup fails for an identifier. The default is 1000. +@item allow-load-data-races +Allow optimizers to introduce new data races on loads. +Set to 1 to allow, otherwise to 0. This option is enabled by default +unless implicitly set by the @option{-fmemory-model=} option. + +@item allow-store-data-races +Allow optimizers to introduce new data races on stores. +Set to 1 to allow, otherwise to 0. This option is enabled by default +unless implicitly set by the @option{-fmemory-model=} option. + +@item allow-packed-load-data-races +Allow optimizers to introduce new data races on packed data loads. +Set to 1 to allow, otherwise to 0. This option is enabled by default +unless implicitly set by the @option{-fmemory-model=} option. + +@item allow-packed-store-data-races +Allow optimizers to introduce new data races on packed data stores. +Set to 1 to allow, otherwise to 0. This option is enabled by default +unless implicitly set by the @option{-fmemory-model=} option. + @end table @end table Index: params.h =================================================================== --- params.h (revision 170745) +++ params.h (working copy) @@ -206,4 +206,13 @@ extern void init_param_values (int *para PARAM_VALUE (PARAM_PREFETCH_MIN_INSN_TO_MEM_RATIO) #define MIN_NONDEBUG_INSN_UID \ PARAM_VALUE (PARAM_MIN_NONDEBUG_INSN_UID) +#define ALLOW_LOAD_DATA_RACES \ + PARAM_VALUE (PARAM_ALLOW_LOAD_DATA_RACES) +#define ALLOW_STORE_DATA_RACES \ + PARAM_VALUE (PARAM_ALLOW_STORE_DATA_RACES) +#define ALLOW_PACKED_LOAD_DATA_RACES \ + PARAM_VALUE (PARAM_ALLOW_PACKED_LOAD_DATA_RACES) +#define ALLOW_PACKED_STORE_DATA_RACES \ + PARAM_VALUE (PARAM_ALLOW_PACKED_STORE_DATA_RACES) + #endif /* ! GCC_PARAMS_H */ Index: testsuite/gcc.dg/memmodel/speculative-store.c =================================================================== --- testsuite/gcc.dg/memmodel/speculative-store.c (revision 170852) +++ testsuite/gcc.dg/memmodel/speculative-store.c (working copy) @@ -1,14 +1,12 @@ /* { dg-do link } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 --param allow-store-data-races=0" } */ /* { dg-final { memmodel-gdb-test } } */ -/* FIXME: I can't get this to fail. */ - #include #include "memmodel.h" /* This file tests that speculative store movement out of a loop doesn't - happen. This is disallowed when -fno-allow-store-data-races is on. */ + happen. This is disallowed when --param allow-store-data-races is 0. */ int global = 100; Index: testsuite/gcc.dg/memmodel/subfields.c =================================================================== --- testsuite/gcc.dg/memmodel/subfields.c (revision 170852) +++ testsuite/gcc.dg/memmodel/subfields.c (working copy) @@ -1,9 +1,7 @@ /* { dg-do link } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 --param allow-packed-store-data-races=0" } */ /* { dg-final { memmodel-gdb-test } } */ -/* FIXME: I can't get this to fail. */ - #include #include "memmodel.h" Index: testsuite/gcc.dg/memmodel/global-hoist.c =================================================================== --- testsuite/gcc.dg/memmodel/global-hoist.c (revision 170852) +++ testsuite/gcc.dg/memmodel/global-hoist.c (working copy) @@ -1,10 +1,10 @@ /* { dg-do link } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 --param allow-load-data-races=0" } */ /* { dg-final { memmodel-gdb-test } } */ /* Verify that a load of a global is not hoisted out of a loop. This can introduce a data race, and is dissallowed if - -fno-allow-load-data-races is enabled. */ + --param allow-load-data-races is 0. */ #include #include Index: testsuite/gcc.dg/memmodel/d2.c =================================================================== --- testsuite/gcc.dg/memmodel/d2.c (revision 170852) +++ testsuite/gcc.dg/memmodel/d2.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do link } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 --param allow-load-data-races=0" } */ /* { dg-final { memmodel-gdb-test } } */ #include @@ -8,7 +8,7 @@ /* This is a variation on global-hoist.c where instead of a loop, we store global into different elements of an array in straightline code with an if condition. This will catch cases where commoning - should be disabled when -fno-allow-load-data-races is on. */ + should be disabled when --param allow-load-data-races is 0. */ /* Test the FALSE path in test. */ Index: testsuite/gcc.dg/memmodel/d3.c =================================================================== --- testsuite/gcc.dg/memmodel/d3.c (revision 170852) +++ testsuite/gcc.dg/memmodel/d3.c (working copy) @@ -1,5 +1,5 @@ /* { dg-do link } */ -/* { dg-options "-O2" } */ +/* { dg-options "-O2 --param allow-load-data-races=0" } */ /* { dg-final { memmodel-gdb-test } } */ #include @@ -8,7 +8,7 @@ /* A variation on global-hoist.c where instead of a loop, we store global into different elements of an array in straightline code with an if condition. This will catch cases where commoning should - be disabled when -fno-allow-load-data-races is on. */ + be disabled when --param allow-load-data-races is 0. */ /* Test the TRUE path in test. */ Index: params.def =================================================================== --- params.def (revision 170745) +++ params.def (working copy) @@ -877,6 +877,28 @@ DEFPARAM (CXX_MAX_NAMESPACES_FOR_DIAGNOS "name lookup fails", 1000, 0, 0) + /* Data race flags for C++0x memory model compliance. */ + + DEFPARAM (PARAM_ALLOW_LOAD_DATA_RACES, + "allow-load-data-races", + "Allow new data races on loads to be introduced", + 1, 0, 1) + + DEFPARAM (PARAM_ALLOW_STORE_DATA_RACES, + "allow-store-data-races", + "Allow new data races on stores to be introduced", + 1, 0, 1) + + DEFPARAM (PARAM_ALLOW_PACKED_LOAD_DATA_RACES, + "allow-packed-load-data-races", + "Allow new data races on packed data loads to be introduced", + 1, 0, 1) + + DEFPARAM (PARAM_ALLOW_PACKED_STORE_DATA_RACES, + "allow-packed-store-data-races", + "Allow new data races on packed data stores to be introduced", + 1, 0, 1) + /* Local variables: mode:c