From patchwork Fri May 8 15:09:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1286173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49JYdl6wLKz9sRf for ; Sat, 9 May 2020 01:09:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D67D13971C74; Fri, 8 May 2020 15:09:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 2A8E93851C03 for ; Fri, 8 May 2020 15:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2A8E93851C03 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: c5Pn8ljK+3YXid6ZtVtYbcxjJ4POwbfpTUlUqSBZZKdh0RUCFD4S2jrw+JIJZd+YSdCWdtT/vf vFUjO8O52ORJqy2Jf4p9ndHcyVUmbZVolUupaRUMsk6tXn5xT4C0g2TroD6SZV77IZAp2Jos5/ xytDDc8nbK6DxTtqrGJLUbDPNfyAmFjhPu7Uz62ccDkaooYq/oQPggZ75kbM7I5rKzQu+jVHQP GCbkNPDrmizvbRChPwSfQD4ClMKBQi96XjWJba/eOSPc2nFdsCTcPNDXOhMXRLDaS2s0MPAg+I HXo= X-IronPort-AV: E=Sophos;i="5.73,368,1583222400"; d="diff'?scan'208";a="48667741" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 08 May 2020 07:09:19 -0800 IronPort-SDR: OrKSi8FTnJ2+TCOBk52/isdi0dufyLWd3w5jxBjNKtuF990ug7ZuLkW+qMo924giREZnR7jYHU p0Q+ndc1A9Lg8Y6Hb9n2ptfsYGiqTp5/hK1oXr3jlPRSvU9zI3KbKVkMU4bIaG5VAODtigu5Gs cUVMIorSxEdHkRoLWOW8SkK2tbJSGWOGhFcRXUbSqQTRNHuhwhiJGy660WBEWrZmYO09INrwo5 ytLQzImb/6cKJnFyMl7ncyyyWk+P6hqPP6RECJ9F0cqV6t3tYkxt28GYptdVannLwwV08vK875 61k= To: gcc-patches , Jakub Jelinek From: Tobias Burnus Subject: [Patch][OpenMP] Fix mapping of artificial variables (PR94874) Message-ID: Date: Fri, 8 May 2020 17:09:07 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" While for data sharing (e.g. "parallel") the predetermined sharing (e.g.) for compiler-generated variables did work, this did not happen for target mapping – causing errors with "defaultmap(none)". It is not completely clear to my how to best handle this case. In most cases, the auxiliary variable is scalar and never modified – currently, they become "map(tofrom:)" which looks like a missed optimization. I was thinking of simply marking them as "nflags |= GOVD_FIRSTPRIVATE" but I am not sure whether that would always make sense, either. In any case, a simple usage would bypass the "implicit mapping of assumed size array" diagnostic in gfc_omp_finish_clause. One could also use a value returned by the hook, but currently it is tailored for shared memory use only. A fix would be either a new argument ("bool for_mapping") plus special handling or a new hook. In any case, the current hook has: For C and most cases of C++: OMP_CLAUSE_DEFAULT_SHARED except that C++ return for current_class_ptr: OMP_CLAUSE_DEFAULT_FIRSTPRIVATE But Fortran is very complex. A simple handling is also not possible as some things (like a C++/Fortran class pointer or probably Cray pointer) need pointer mapping. [C++: RTTI/dynamic_cast permitted; Fortran: RTTI + virtual calls permitted.] Hence, I went for the simple solution. OK for the trunk? If is, is it worthwhile to backport to the GCC 10 branch? Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter [OpenMP] Fix mapping of artificial variables (PR94874) gcc/ 2020-05-08 Tobias Burnus PR middle-end/94874 * gimplify.c (omp_notice_variable): For mapping, also call lang_hooks.decls.omp_predetermined_sharing. gcc/testsuite/ 2020-05-08 Thomas Schwinge Tobias Burnus PR middle-end/94874 * c-c++-common/gomp/pr94874.c: New. gcc/gimplify.c | 5 ++++- gcc/testsuite/c-c++-common/gomp/pr94874.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 1d532e6f373..4c5eb0b3d54 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -7441,7 +7441,10 @@ omp_notice_variable (struct gimplify_omp_ctx *ctx, tree decl, bool in_code) gdmk = GDMK_SCALAR; else gdmk = GDMK_AGGREGATE; - if (ctx->defaultmap[gdmk] == 0) + if (lang_hooks.decls.omp_predetermined_sharing (decl) + != OMP_CLAUSE_DEFAULT_UNSPECIFIED) + ; /* Handled by lang_hooks.decls.omp_finish_clause. */ + else if (ctx->defaultmap[gdmk] == 0) { tree d = lang_hooks.decls.omp_report_decl (decl); error ("%qE not specified in enclosing %", diff --git a/gcc/testsuite/c-c++-common/gomp/pr94874.c b/gcc/testsuite/c-c++-common/gomp/pr94874.c new file mode 100644 index 00000000000..36da2471a80 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/pr94874.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-gimple" } */ + +#include + +size_t +vla (int array_li) +{ + float array[array_li]; + size_t size1, size2; + +#pragma omp parallel default(none) shared(size1, array) + size1 = sizeof array; + +#pragma omp target defaultmap(none) map(from:size2) map(alloc:array) + size2 = sizeof array; + + return size1 + size2; +} + +/* C */ +/* { dg-final { scan-tree-dump "omp parallel .*shared\\(array_li\.\[0-9\]\\)" "gimple" { target { ! c++ } } } } */ +/* { dg-final { scan-tree-dump "omp target .*map\\(tofrom:array_li\.\[0-9\] " "gimple" { target { ! c++ } } } } */ + +/* C++ */ +/* { dg-final { scan-tree-dump "omp parallel .*shared\\(D\.\[0-9\]*\\)" "gimple" { target { c++ } } } } */ +/* { dg-final { scan-tree-dump "omp target .*map\\(tofrom:D\.\[0-9\]* " "gimple" { target { c++ } } } } */