From patchwork Mon Nov 30 23:16:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cesar Philippidis X-Patchwork-Id: 550557 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2D53F14016A for ; Tue, 1 Dec 2015 10:16:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bp74ZPY1; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=cQ+ES8UT3Kk513b9JAgfOcPlusQ2SefcnpxmoHHnskPrkZFPMU ga6vUx7P5dSUKK+uKpH11TVy+CDalNyF4Zog8qgWR1O/Uxar3dlzbsMb8Y6loDqS vnt1f7qp7kvzZ8SfSPXr0P29/+59TP5o2FkJy8fYWgvbfz/Zqe8vu/Fxo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=bdyEXlrGNiCSTzgGqZpOad+d7+c=; b=bp74ZPY1INZzqu1Gw5zl 8uRy/AGVKFbxT857IK+dSd5MiF7H7EsGCruk799wAOlmCilzzELJHoDt4g5bcQLv wAqUd8BrAVinNwfXm6SKH9a5jpGIRvgv2Ay8tCmnxeOvuwrjXLNqJ2tQekjcX7gD LH+oFcYwFLl7zltX/BVw1+U= Received: (qmail 18214 invoked by alias); 30 Nov 2015 23:16:35 -0000 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 Received: (qmail 18198 invoked by uid 89); 30 Nov 2015 23:16:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Nov 2015 23:16:33 +0000 Received: from svr-orw-fem-06.mgc.mentorg.com ([147.34.97.120]) by relay1.mentorg.com with esmtp id 1a3XgL-0000p7-Pi from Cesar_Philippidis@mentor.com for gcc-patches@gcc.gnu.org; Mon, 30 Nov 2015 15:16:29 -0800 Received: from [127.0.0.1] (147.34.91.1) by SVR-ORW-FEM-06.mgc.mentorg.com (147.34.97.120) with Microsoft SMTP Server id 14.3.224.2; Mon, 30 Nov 2015 15:16:29 -0800 To: "gcc-patches@gcc.gnu.org" From: Cesar Philippidis Subject: [gomp4] fortran routine backports Message-ID: <565CD8CD.1000402@codesourcery.com> Date: Mon, 30 Nov 2015 15:16:29 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 This patch backports the recent fortran routine support changes I've made in trunk to gomp-4_0-branch. Nothing changed in the fortran front end, but I corrected a couple of problems with the way that gang, worker and vector were handled in tree-nested.c. And there's a new test case to exercise those changes. This patch has been applied to gomp-4_0-branch. Cesar 2015-11-30 Cesar Philippidis gcc/ * tree-nested.c (convert_nonlocal_omp_clauses): Handle optional arguments for OMP_CLAUSE_{GANG,WORKER,VECTOR}. (convert_local_omp_clauses): Likewise gcc/testsuite/ * gfortran.dg/goacc/subroutines.f90: New test. diff --git a/gcc/testsuite/gfortran.dg/goacc/subroutines.f90 b/gcc/testsuite/gfortran.dg/goacc/subroutines.f90 new file mode 100644 index 0000000..6cab798 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/subroutines.f90 @@ -0,0 +1,73 @@ +! Exercise how tree-nested.c handles gang, worker vector and seq. + +! { dg-do compile } + +program main + integer, parameter :: N = 100 + integer :: nonlocal_arg + integer :: nonlocal_a(N) + integer :: nonlocal_i + integer :: nonlocal_j + + nonlocal_a (:) = 5 + nonlocal_arg = 5 + + call local () + call nonlocal () + +contains + + subroutine local () + integer :: local_i + integer :: local_arg + integer :: local_a(N) + integer :: local_j + + local_a (:) = 5 + local_arg = 5 + + !$acc kernels loop gang(num:local_arg) worker(local_arg) vector(local_arg) + do local_i = 1, N + local_a(local_i) = 100 + !$acc loop seq + do local_j = 1, N + enddo + enddo + !$acc end kernels loop + + !$acc kernels loop gang(static:local_arg) worker(local_arg) & + !$acc vector(local_arg) + do local_i = 1, N + local_a(local_i) = 100 + !$acc loop seq + do local_j = 1, N + enddo + enddo + !$acc end kernels loop + end subroutine local + + subroutine nonlocal () + nonlocal_a (:) = 5 + nonlocal_arg = 5 + + !$acc kernels loop gang(num:nonlocal_arg) worker(nonlocal_arg) & + !$acc vector(nonlocal_arg) + do nonlocal_i = 1, N + nonlocal_a(nonlocal_i) = 100 + !$acc loop seq + do nonlocal_j = 1, N + enddo + enddo + !$acc end kernels loop + + !$acc kernels loop gang(static:nonlocal_arg) worker(nonlocal_arg) & + !$acc vector(nonlocal_arg) + do nonlocal_i = 1, N + nonlocal_a(nonlocal_i) = 100 + !$acc loop seq + do nonlocal_j = 1, N + enddo + enddo + !$acc end kernels loop + end subroutine nonlocal +end program main diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index e321072..1c9849b 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -1109,10 +1109,28 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_NUM_GANGS: case OMP_CLAUSE_NUM_WORKERS: case OMP_CLAUSE_VECTOR_LENGTH: - wi->val_only = true; - wi->is_lhs = false; - convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0), - &dummy, wi); + case OMP_CLAUSE_GANG: + case OMP_CLAUSE_WORKER: + case OMP_CLAUSE_VECTOR: + /* Several OpenACC clauses have optional arguments. Check if they + are present. */ + if (OMP_CLAUSE_OPERAND (clause, 0)) + { + wi->val_only = true; + wi->is_lhs = false; + convert_nonlocal_reference_op (&OMP_CLAUSE_OPERAND (clause, 0), + &dummy, wi); + } + + /* The gang clause accepts two arguments. */ + if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG + && OMP_CLAUSE_GANG_STATIC_EXPR (clause)) + { + wi->val_only = true; + wi->is_lhs = false; + convert_nonlocal_reference_op + (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi); + } break; case OMP_CLAUSE_DIST_SCHEDULE: @@ -1176,9 +1194,6 @@ convert_nonlocal_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_THREADS: case OMP_CLAUSE_SIMD: case OMP_CLAUSE_DEFAULTMAP: - case OMP_CLAUSE_GANG: - case OMP_CLAUSE_WORKER: - case OMP_CLAUSE_VECTOR: case OMP_CLAUSE_SEQ: break; @@ -1768,10 +1783,28 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_NUM_GANGS: case OMP_CLAUSE_NUM_WORKERS: case OMP_CLAUSE_VECTOR_LENGTH: - wi->val_only = true; - wi->is_lhs = false; - convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0), &dummy, - wi); + case OMP_CLAUSE_GANG: + case OMP_CLAUSE_WORKER: + case OMP_CLAUSE_VECTOR: + /* Several OpenACC clauses have optional arguments. Check if they + are present. */ + if (OMP_CLAUSE_OPERAND (clause, 0)) + { + wi->val_only = true; + wi->is_lhs = false; + convert_local_reference_op (&OMP_CLAUSE_OPERAND (clause, 0), + &dummy, wi); + } + + /* The gang clause accepts two arguments. */ + if (OMP_CLAUSE_CODE (clause) == OMP_CLAUSE_GANG + && OMP_CLAUSE_GANG_STATIC_EXPR (clause)) + { + wi->val_only = true; + wi->is_lhs = false; + convert_nonlocal_reference_op + (&OMP_CLAUSE_GANG_STATIC_EXPR (clause), &dummy, wi); + } break; case OMP_CLAUSE_DIST_SCHEDULE: @@ -1840,9 +1873,6 @@ convert_local_omp_clauses (tree *pclauses, struct walk_stmt_info *wi) case OMP_CLAUSE_THREADS: case OMP_CLAUSE_SIMD: case OMP_CLAUSE_DEFAULTMAP: - case OMP_CLAUSE_GANG: - case OMP_CLAUSE_WORKER: - case OMP_CLAUSE_VECTOR: case OMP_CLAUSE_SEQ: break;