From patchwork Mon Jan 23 22:59:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Marlier X-Patchwork-Id: 137492 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 D577CB6F99 for ; Tue, 24 Jan 2012 10:00:21 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1327964425; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=esD3iL4iTAGPpaWWjQLgf7wHDjI=; b=veKhPMUIKDCTpUe 59cBRa60JJw08yj0ThEpCHkX5JQqjAFcv4huFQi8bo8skzaQIlDpJzKbwZEmUBYQ MLdmMPUFg4+4MqtFQBmyy/4JUbGpNEkjqFcu1qXxOJx5nmMCdZiTJBjo3ax8prKU aA8FC20t+UmjdXnZI1CIIsYxd/0o= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=uNuSYbZ/HPE62dWnJKa4f37GyseuvKquzZyQg3A/ziDMQG6npqrV62Owp/IIyc SWwkRO0SgnyECMpL7smB+peRpfyQAE5p8xYN7cAvv6ad+ZU2Ik/u+JJgGBaQyLOx BxKipav37IKYl830sC+iGTaBq7XPQGHIlhfDRGJXrPWZ0=; Received: (qmail 23827 invoked by alias); 23 Jan 2012 23:00:16 -0000 Received: (qmail 23816 invoked by uid 22791); 23 Jan 2012 23:00:14 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 23 Jan 2012 23:00:01 +0000 Received: by qadz30 with SMTP id z30so696582qad.20 for ; Mon, 23 Jan 2012 15:00:00 -0800 (PST) Received: by 10.224.168.84 with SMTP id t20mr12124413qay.2.1327359600528; Mon, 23 Jan 2012 15:00:00 -0800 (PST) Received: from [192.168.2.2] (cpe-69-207-95-157.rochester.res.rr.com. [69.207.95.157]) by mx.google.com with ESMTPS id o8sm29398025qaj.0.2012.01.23.14.59.59 (version=SSLv3 cipher=OTHER); Mon, 23 Jan 2012 14:59:59 -0800 (PST) Message-ID: <4F1DE66E.8070701@gmail.com> Date: Mon, 23 Jan 2012 17:59:58 -0500 From: Patrick Marlier User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111124 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches CC: Richard Henderson , Aldy Hernandez , Torvald Riegel Subject: [trans-mem] Do not instrument thread locals X-IsSubscribed: yes 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 Hi, I found that all thread local variables are instrumented with _ITM_W/R* calls whereas they should not be shared with other threads. This patch takes care of thread locals into requires_barrier and also adds the local save/restore for them. This patch also includes a testcase. I did not fill any PR since I have already a patch for it but tell me if I have to. Tested on x86_64-unknown-linux-gnu, ok for trunk? Thanks. --- Patrick Marlier. ChangeLog 2012-01-23 Patrick Marlier * trans-mem.c (requires_barrier): Do not instrument thread local variables and emit save/restore for them. testsuite/ChangeLog 2012-01-23 Patrick Marlier * gcc.dg/tm/threadlocal-1.c: New test. Index: testsuite/gcc.dg/tm/threadlocal-1.c =================================================================== --- testsuite/gcc.dg/tm/threadlocal-1.c (revision 0) +++ testsuite/gcc.dg/tm/threadlocal-1.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-fgnu-tm -O -fdump-tree-tmedge" } */ +__thread int notshared = 0; +int shared = 0; + +int main() +{ + __transaction_atomic + { + notshared++; + shared++; + } + return notshared + shared; +} +/* { dg-final { scan-tree-dump-times "tm_save.\[0-9_\]+ = notshared" 1 "tmedge" } } */ +/* { dg-final { scan-tree-dump-times "notshared = tm_save" 1 "tmedge" } } */ +/* { dg-final { cleanup-tree-dump "tmedge" } } */ Index: trans-mem.c =================================================================== --- trans-mem.c (revision 183448) +++ trans-mem.c (working copy) @@ -1,5 +1,5 @@ /* Passes for transactional memory support. - Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This file is part of GCC. @@ -1488,7 +1488,18 @@ requires_barrier (basic_block entry_block, tree x, } if (is_global_var (x)) - return !TREE_READONLY (x); + { + if (DECL_THREAD_LOCAL_P (x)) + goto thread_local; + if (DECL_HAS_VALUE_EXPR_P (x)) + { + tree value = get_base_address (DECL_VALUE_EXPR (x)); + + if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value)) + goto thread_local; + } + return !TREE_READONLY (x); + } if (/* FIXME: This condition should actually go below in the tm_log_add() call, however is_call_clobbered() depends on aliasing info which is not available during @@ -1498,17 +1509,14 @@ requires_barrier (basic_block entry_block, tree x, lower_sequence_tm altogether. */ needs_to_live_in_memory (x)) return true; - else - { - /* For local memory that doesn't escape (aka thread private - memory), we can either save the value at the beginning of - the transaction and restore on restart, or call a tm - function to dynamically save and restore on restart - (ITM_L*). */ - if (stmt) - tm_log_add (entry_block, orig, stmt); - return false; - } + thread_local: + /* For local memory that doesn't escape (aka thread private memory), + we can either save the value at the beginning of the transaction and + restore on restart, or call a tm function to dynamically save and + restore on restart (ITM_L*). */ + if (stmt) + tm_log_add (entry_block, orig, stmt); + return false; default: return false;