From patchwork Fri Aug 10 20:23:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Iyer, Balaji V" X-Patchwork-Id: 176624 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 D2A262C00A7 for ; Sat, 11 Aug 2012 06:23:42 +1000 (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=1345235023; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:From:To:Subject:Date:Message-ID:Content-Type: MIME-Version:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=PI3+egx bUyjoIRXjsXkQ8VaEHYs=; b=owpXX+/iGVfRbQ5hmN+fG2aqNBYk2wmh0WtYT88 vbuQ3STpZcp5sYcgzeTs+Ed901m6fcs1wOPQesiXO80UNJ0mvsLegi/s7rzfJBFS imxMsfRPUCiPx1l1qS7K9ii5b5aOvjOfWkVejL72cfvOrKWrzTCRJdAYBHWkR1Nf xW28= 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:X-ExtLoop1:Received:Received:Received:From:To:Subject:Date:Message-ID:Content-Type:MIME-Version:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=E8aO7Kz6M5vJ1ky5gs3i/P9MoMdqdBiueIlATAVN4duSh5SiNyW+mNx49rkqwL uKPIerT9TgtBCJJz8Dy3dhYOj+ExSS1OetJuQ3WyMtCQ5MyX99h53T/m7pTIQnkM RwcRhnWzXtxLHEXgW+NvZarPpKZTBiqWEt9Y52wxy+47U=; Received: (qmail 15701 invoked by alias); 10 Aug 2012 20:23:37 -0000 Received: (qmail 15684 invoked by uid 22791); 10 Aug 2012 20:23:34 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Aug 2012 20:23:21 +0000 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 10 Aug 2012 13:23:21 -0700 X-ExtLoop1: 1 Received: from fmsmsx107.amr.corp.intel.com ([10.19.9.54]) by fmsmga001.fm.intel.com with ESMTP; 10 Aug 2012 13:23:02 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.19.9.52) by FMSMSX107.amr.corp.intel.com (10.19.9.54) with Microsoft SMTP Server (TLS) id 14.1.355.2; Fri, 10 Aug 2012 13:23:01 -0700 Received: from fmsmsx102.amr.corp.intel.com ([169.254.2.100]) by FMSMSX101.amr.corp.intel.com ([169.254.1.136]) with mapi id 14.01.0355.002; Fri, 10 Aug 2012 13:23:02 -0700 From: "Iyer, Balaji V" To: "gcc-patches@gcc.gnu.org" Subject: [PATCH][Cilkplus] Patch to add implicit sync before try block Date: Fri, 10 Aug 2012 20:23:00 +0000 Message-ID: MIME-Version: 1.0 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 Hello Everyone, This patch is for the Cilk Plus branch affecting mainly the C++ compiler. This patch will add an implicit sync before a try block in a function that spawns. Thanks, Balaji V. Iyer. Index: gcc/testsuite/g++.dg/cilk-plus/test-try.cc =================================================================== --- gcc/testsuite/g++.dg/cilk-plus/test-try.cc (revision 0) +++ gcc/testsuite/g++.dg/cilk-plus/test-try.cc (revision 0) @@ -0,0 +1,32 @@ +/* Please run this in the following way: + + time ./a.out + + The output should be something like this: + + real 0m10.002s <== This is the main thing that should match. + user 0m10.793s + sys 0m53.855s + +*/ + + +#include +void mysleep(int a) +{ + sleep(5); +} + +int main(int argc, char ** argv) +{ + _Cilk_spawn mysleep(5); + try + { + _Cilk_spawn mysleep(5); + mysleep(5); + } + + catch(int err) + { + } +} Index: gcc/testsuite/g++.dg/cilk-plus/test-try-cond.cc =================================================================== --- gcc/testsuite/g++.dg/cilk-plus/test-try-cond.cc (revision 0) +++ gcc/testsuite/g++.dg/cilk-plus/test-try-cond.cc (revision 0) @@ -0,0 +1,41 @@ +/* Please run this in the following way: + + time ./a.out + + The output should be something like this: + + real 0m5.002s <=== This is the main thing that should match. + user 0m6.200s + sys 0m28.670s + + When you run it with any number of arguments > 1 then you should get + something like this: + + time ./a.out 1 2 3 + real 0m10.003s <=== This is the main thing that should match. + user 0m11.401s + sys 0m53.387s + +*/ + + +#include +void mysleep(int a) { + sleep(5); +} + +int main(int argc, char ** argv) { + _Cilk_spawn mysleep(5); + if (argc > 1) { + try { + _Cilk_spawn mysleep(5); + mysleep(5); + } + + catch(int err) { + } + } + else { + mysleep(5); + } +} Index: gcc/testsuite/ChangeLog.cilkplus =================================================================== --- gcc/testsuite/ChangeLog.cilkplus (revision 190299) +++ gcc/testsuite/ChangeLog.cilkplus (working copy) @@ -1,3 +1,8 @@ +2012-08-10 Balaji V. Iyer + + * g++.dg/cilk-plus/test-try.cc: New test file. + * g++.dg/cilk-plus/test-try-cond.cc: Likewise. + 2012-07-16 Balaji V. Iyer * gcc.dg/cilk-plus/cilk_plus.exp: Added flag_enable_cilk flag. Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 190195) +++ gcc/cp/decl.c (working copy) @@ -13371,7 +13371,7 @@ /* Here we insert Cilk specific functions when _Cilk_spawn is used. */ if (flag_enable_cilk && cfun->calls_spawn) { - cfun->cilk_frame_decl = cp_make_cilk_frame (); + cfun->cilk_frame_decl = cp_make_cilk_frame (compstmt); DECL_HAS_SPAWN_P (cfun->decl) = 1; } Index: gcc/cp/cilk.c =================================================================== --- gcc/cp/cilk.c (revision 190179) +++ gcc/cp/cilk.c (working copy) @@ -805,11 +805,34 @@ return 0; } +/* This function will insert a _Cilk_sync right before a try block. */ +static tree +insert_sync_stmt (tree *tp, int *walk_subtrees, void *data ATTRIBUTE_UNUSED) +{ + tree new_sync_stmt = NULL_TREE, synced_stmt_list = NULL_TREE; + if (TREE_CODE (*tp) == TRY_BLOCK) + { + new_sync_stmt = build_stmt (UNKNOWN_LOCATION, CILK_SYNC_STMT); + gcc_assert (new_sync_stmt && (new_sync_stmt != error_mark_node)); + append_to_statement_list_force (new_sync_stmt, &synced_stmt_list); + append_to_statement_list_force (*tp, &synced_stmt_list); + *tp = synced_stmt_list; + + /* We don't need to go any deeper. */ + *walk_subtrees = 0; + + /* We are finished here. We only need to find the first try block. */ + return *tp; + } + + return NULL; +} + /* This function will make the frame for C++ function that uses Cilk_spawn. */ tree -cp_make_cilk_frame (void) +cp_make_cilk_frame (tree compstmt) { tree decl = cfun->cilk_frame_decl; @@ -861,6 +884,10 @@ &body); *saved_tree = body; + + /* Here we talk through all the subtrees of compstmt and as soon as + we find a try block, we insert a _Cilk_sync right before it. */ + cp_walk_tree (&compstmt, insert_sync_stmt, NULL, NULL); } return decl; Index: gcc/cp/ChangeLog.cilkplus =================================================================== --- gcc/cp/ChangeLog.cilkplus (revision 190299) +++ gcc/cp/ChangeLog.cilkplus (working copy) @@ -1,3 +1,10 @@ +2012-08-10 Balaji V. Iyer + + * decl.c (finish_function_body): Added compstmt as a new parameter. + (cp_make_cilk_frame): Added compstmt as a parameter and called + insert_sync_stmt inside cp_walk_tree. + (insert_sync_stmt): New function. + 2012-08-07 Balaji V. Iyer * parser.c (cp_parser_cilk_for): Stored the initial value in cilk_for tree. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 190195) +++ gcc/cp/cp-tree.h (working copy) @@ -6051,7 +6051,7 @@ struct cp_binding_level *in_cilk_block (void); bool cp_spawnable_constructor (tree); bool cp_recognize_spawn (tree); -tree cp_make_cilk_frame (void); +tree cp_make_cilk_frame (tree); extern tree cilk_for_var_decl (tree, bool); extern void finish_cilk_for_stmt (tree);