From patchwork Fri Jul 24 15:10:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 499779 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 9B62E140776 for ; Sat, 25 Jul 2015 01:11:14 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=etRgqJnG; 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=twuGmjW5R0EPQo1Lf/dRdGzbKcP8gA+R8MQC0jICv6DGZ9h4rR LDk1s+3gtNum/HtGUFGi7Kt+Sa2w7YLxA5YKmJOBBeJm1e5Z8insHoaTwGd5dlVe rj0MemxbfP8cwE5sOOkt++BmXJETii2WMCce65N8yANufXmjTRLgxbjPs= 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=BT+fuQJ8NfaXJ3ui6ybH8OI9ISs=; b=etRgqJnGqwWtYfoSh+Xh Sgro3P+6hpJZ2GYblzXWOGBzWUUH8R3+vAASWsp+9pz2BcRpV/Ra6TirbpNQvcBp V/q5Z0FUwm63AR0uIh0ba2yU5S4a2QW4EQj5p9lb2nMV940QXoCgeNxvsCc8D/ss WtVC4FnqHWyxdAgwId9GJNg= Received: (qmail 113805 invoked by alias); 24 Jul 2015 15:11:06 -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 112965 invoked by uid 89); 24 Jul 2015 15:11:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f178.google.com Received: from mail-qk0-f178.google.com (HELO mail-qk0-f178.google.com) (209.85.220.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 24 Jul 2015 15:11:04 +0000 Received: by qkdl129 with SMTP id l129so16119463qkd.0 for ; Fri, 24 Jul 2015 08:11:02 -0700 (PDT) X-Received: by 10.55.20.24 with SMTP id e24mr21040205qkh.35.1437750662177; Fri, 24 Jul 2015 08:11:02 -0700 (PDT) Received: from ?IPv6:2601:181:c000:c497:a2a8:cdff:fe3e:b48? ([2601:181:c000:c497:a2a8:cdff:fe3e:b48]) by smtp.googlemail.com with ESMTPSA id 34sm4180455qkz.38.2015.07.24.08.11.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Jul 2015 08:11:01 -0700 (PDT) To: Jakub Jelinek , GCC Patches From: Nathan Sidwell Subject: default omp clause Message-ID: <55B25583.4060407@acm.org> Date: Fri, 24 Jul 2015 11:10:59 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 Jakub, in working on openacc default clause handling, I found the logic in omp_notice_variable a little hard to follow, due to the size of function and depth of nesting. I broke out the existing default handling to a separate function, and made the control flow a bit clearer (IMHO). ok for trunk? nathan 2015-07-24 Nathan Sidwell * gimplify.c (omp_default_clause): New function. Reorganize flow for clarity. Broken out of ... (omp_notice_variable): ... here. Index: gcc/gimplify.c =================================================================== --- gcc/gimplify.c (revision 226154) +++ gcc/gimplify.c (working copy) @@ -5764,6 +5764,96 @@ omp_notice_threadprivate_variable (struc return false; } +/* Determine outer default flags for DECL mentioned in an OMP region + but not declared in an enclosing clause. + + ??? Some compiler-generated variables (like SAVE_EXPRs) could be + remapped firstprivate instead of shared. To some extent this is + addressed in omp_firstprivatize_type_sizes, but not + effectively. */ + +static unsigned +omp_default_clause (struct gimplify_omp_ctx *ctx, tree decl, + bool in_code, unsigned flags) +{ + enum omp_clause_default_kind default_kind = ctx->default_kind; + enum omp_clause_default_kind kind; + + kind = lang_hooks.decls.omp_predetermined_sharing (decl); + if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED) + default_kind = kind; + + switch (default_kind) + { + case OMP_CLAUSE_DEFAULT_NONE: + { + const char *accn; + + if (ctx->region_type & ORT_PARALLEL) + accn = "parallel"; + else if (ctx->region_type & ORT_TASK) + accn = "task"; + else if (ctx->region_type & ORT_TEAMS) + accn = "teams"; + else + gcc_unreachable (); + + error ("%qE not specified in enclosing %s", + DECL_NAME (lang_hooks.decls.omp_report_decl (decl)), accn); + error_at (ctx->location, "enclosing %s", accn); + } + /* FALLTHRU */ + case OMP_CLAUSE_DEFAULT_SHARED: + flags |= GOVD_SHARED; + break; + case OMP_CLAUSE_DEFAULT_PRIVATE: + flags |= GOVD_PRIVATE; + break; + case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE: + flags |= GOVD_FIRSTPRIVATE; + break; + case OMP_CLAUSE_DEFAULT_UNSPECIFIED: + /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */ + gcc_assert ((ctx->region_type & ORT_TASK) != 0); + if (struct gimplify_omp_ctx *octx = ctx->outer_context) + { + omp_notice_variable (octx, decl, in_code); + for (; octx; octx = octx->outer_context) + { + splay_tree_node n2; + + if ((octx->region_type & (ORT_TARGET_DATA | ORT_TARGET)) != 0) + continue; + n2 = splay_tree_lookup (octx->variables, (splay_tree_key) decl); + if (n2 && (n2->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED) + { + flags |= GOVD_FIRSTPRIVATE; + goto found_outer; + } + if ((octx->region_type & (ORT_PARALLEL | ORT_TEAMS)) != 0) + { + flags |= GOVD_SHARED; + goto found_outer; + } + } + } + + if (TREE_CODE (decl) == PARM_DECL + || (!is_global_var (decl) + && DECL_CONTEXT (decl) == current_function_decl)) + flags |= GOVD_FIRSTPRIVATE; + else + flags |= GOVD_SHARED; + found_outer: + break; + + default: + gcc_unreachable (); + } + + return flags; +} + /* Record the fact that DECL was used within the OMP context CTX. IN_CODE is true when real code uses DECL, and false when we should merely emit default(none) errors. Return true if DECL is going to @@ -5822,90 +5912,12 @@ omp_notice_variable (struct gimplify_omp if (n == NULL) { - enum omp_clause_default_kind default_kind, kind; - struct gimplify_omp_ctx *octx; - if (ctx->region_type == ORT_WORKSHARE || ctx->region_type == ORT_SIMD || ctx->region_type == ORT_TARGET_DATA) goto do_outer; - /* ??? Some compiler-generated variables (like SAVE_EXPRs) could be - remapped firstprivate instead of shared. To some extent this is - addressed in omp_firstprivatize_type_sizes, but not effectively. */ - default_kind = ctx->default_kind; - kind = lang_hooks.decls.omp_predetermined_sharing (decl); - if (kind != OMP_CLAUSE_DEFAULT_UNSPECIFIED) - default_kind = kind; - - switch (default_kind) - { - case OMP_CLAUSE_DEFAULT_NONE: - if ((ctx->region_type & ORT_PARALLEL) != 0) - { - error ("%qE not specified in enclosing parallel", - DECL_NAME (lang_hooks.decls.omp_report_decl (decl))); - error_at (ctx->location, "enclosing parallel"); - } - else if ((ctx->region_type & ORT_TASK) != 0) - { - error ("%qE not specified in enclosing task", - DECL_NAME (lang_hooks.decls.omp_report_decl (decl))); - error_at (ctx->location, "enclosing task"); - } - else if (ctx->region_type & ORT_TEAMS) - { - error ("%qE not specified in enclosing teams construct", - DECL_NAME (lang_hooks.decls.omp_report_decl (decl))); - error_at (ctx->location, "enclosing teams construct"); - } - else - gcc_unreachable (); - /* FALLTHRU */ - case OMP_CLAUSE_DEFAULT_SHARED: - flags |= GOVD_SHARED; - break; - case OMP_CLAUSE_DEFAULT_PRIVATE: - flags |= GOVD_PRIVATE; - break; - case OMP_CLAUSE_DEFAULT_FIRSTPRIVATE: - flags |= GOVD_FIRSTPRIVATE; - break; - case OMP_CLAUSE_DEFAULT_UNSPECIFIED: - /* decl will be either GOVD_FIRSTPRIVATE or GOVD_SHARED. */ - gcc_assert ((ctx->region_type & ORT_TASK) != 0); - if (ctx->outer_context) - omp_notice_variable (ctx->outer_context, decl, in_code); - for (octx = ctx->outer_context; octx; octx = octx->outer_context) - { - splay_tree_node n2; - - if ((octx->region_type & (ORT_TARGET_DATA | ORT_TARGET)) != 0) - continue; - n2 = splay_tree_lookup (octx->variables, (splay_tree_key) decl); - if (n2 && (n2->value & GOVD_DATA_SHARE_CLASS) != GOVD_SHARED) - { - flags |= GOVD_FIRSTPRIVATE; - break; - } - if ((octx->region_type & (ORT_PARALLEL | ORT_TEAMS)) != 0) - break; - } - if (flags & GOVD_FIRSTPRIVATE) - break; - if (octx == NULL - && (TREE_CODE (decl) == PARM_DECL - || (!is_global_var (decl) - && DECL_CONTEXT (decl) == current_function_decl))) - { - flags |= GOVD_FIRSTPRIVATE; - break; - } - flags |= GOVD_SHARED; - break; - default: - gcc_unreachable (); - } + flags = omp_default_clause (ctx, decl, in_code, flags); if ((flags & GOVD_PRIVATE) && lang_hooks.decls.omp_private_outer_ref (decl))