From patchwork Mon Dec 28 13:46:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 561301 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 6046C140C68 for ; Tue, 29 Dec 2015 00:46:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=AToAiKe1; 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=DvVPlcca3RYwjsoD3AiCTfxWafxDXNnnswi7gzQeGwPrr6BtwM timTeeHZftZgM4ZydHYP63etRhg9F2oDXKrqPKvOBWXPfFEa20WULIkS1kaEyg3t wINdwX1uE4/67Ew1z3hlqM2CeizPzwhZe5D0FoP8PQfbktG4wLSSEiQ+A= 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=3RxhxQS1gqZbJ0UrHiGvssUlvB8=; b=AToAiKe1RSbd+J7whzPM jZKX6syTwWFPDxHMl4HTE/TlmoCdC++oBcbJE8jwIVo05xpzj8FCXGcODTeE2hdb DlfnS8zqSmxa6NsOjiTr2xgFhjCPVpB3U6ewPHXSFNOjNc1gHWb1mM8EgJhlrw2T +RNWVatw8m+Fsk1fE7f/2Jo= Received: (qmail 126873 invoked by alias); 28 Dec 2015 13:46:09 -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 126850 invoked by uid 89); 28 Dec 2015 13:46:08 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=BAYES_05, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:lookup_, Determine, flag_checking, Simplify X-HELO: mail-qg0-f43.google.com Received: from mail-qg0-f43.google.com (HELO mail-qg0-f43.google.com) (209.85.192.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 28 Dec 2015 13:46:06 +0000 Received: by mail-qg0-f43.google.com with SMTP id 6so68724535qgy.1 for ; Mon, 28 Dec 2015 05:46:06 -0800 (PST) X-Received: by 10.140.39.179 with SMTP id v48mr70148312qgv.98.1451310364683; Mon, 28 Dec 2015 05:46:04 -0800 (PST) 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 h14sm11555452qhc.33.2015.12.28.05.46.04 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Dec 2015 05:46:04 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: [gomp4] Simplify function discarding Message-ID: <56813D1B.2030407@acm.org> Date: Mon, 28 Dec 2015 08:46:03 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 I noticed that the code dealing with bind and nohost clauses in execute_oacc_device_lower looked like: #ifdef ACCEL_COMPILER ten lines of 'f(BIND)' #endif #ifndef ACCEL_COMPILER ten lines of 'f(NOHOST)' #endif Simplified to the attached, which reduces the cut and paste, as well as moving this check to after we've determined it's something applicable to offloading. nathan 2015-12-28 Nathan Sidwell * omp-low.c (maybe_discard_oacc_function): New simplification broken out of ... (execte_oacc_device_lower): ... here. Call it. Index: gcc/omp-low.c =================================================================== --- gcc/omp-low.c (revision 231972) +++ gcc/omp-low.c (working copy) @@ -19973,6 +19973,28 @@ default_goacc_reduction (gcall *call) gsi_replace_with_seq (&gsi, seq, true); } +/* Determine whether DECL should be discarded in this offload + compilation. */ + +static bool +maybe_discard_oacc_function (tree decl) +{ + tree attr = lookup_attribute ("omp declare target", DECL_ATTRIBUTES (decl)); + + if (!attr) + return false; + + enum omp_clause_code kind = OMP_CLAUSE_NOHOST; + +#ifdef ACCEL_COMPILER + kind = OMP_CLAUSE_BIND; +#endif + if (find_omp_clause (TREE_VALUE (attr), kind)) + return true; + + return false; +} + /* Main entry point for oacc transformations which run on the device compiler after LTO, so we know what the target device is at this point (including the host fallback). */ @@ -19980,74 +20002,19 @@ default_goacc_reduction (gcall *call) static unsigned int execute_oacc_device_lower () { - /* There are offloaded functions without an "omp declare target" attribute, - so we'll not handle these here, but on the other hand, OpenACC bind and - nohost clauses can only be generated in the front ends, and an "omp - declare target" attribute will then also always have been set there, so - this is not a problem in practice. */ - tree attr = lookup_attribute ("omp declare target", - DECL_ATTRIBUTES (current_function_decl)); - -#if defined(ACCEL_COMPILER) - /* In an offload compiler, discard any offloaded function X that is tagged - with an OpenACC bind(Y) clause: all references to X have been rewritten to - refer to Y; X is unreachable, do not compile it. */ - if (attr) - { - tree clauses = TREE_VALUE (attr); - /* TODO: device_type handling. */ - tree clause_bind = find_omp_clause (clauses, OMP_CLAUSE_BIND); - if (clause_bind) - { - tree clause_bind_name = OMP_CLAUSE_BIND_NAME (clause_bind); - const char *bind_name = TREE_STRING_POINTER(clause_bind_name); - if (dump_file) - fprintf (dump_file, - "Discarding function \"%s\" with \"bind(%s)\" clause.\n", - IDENTIFIER_POINTER (DECL_NAME (current_function_decl)), - bind_name); - TREE_ASM_WRITTEN (current_function_decl) = 1; - return TODO_discard_function; - } - } -#endif /* ACCEL_COMPILER */ -#if !defined(ACCEL_COMPILER) - /* In the host compiler, discard any offloaded function that is tagged with - an OpenACC nohost clause. */ - if (attr) - { - tree clauses = TREE_VALUE (attr); - if (find_omp_clause (clauses, OMP_CLAUSE_NOHOST)) - { - /* There are no construct/clause combinations that could make this - happen, but play it safe, and verify that we never discard a - function that is stored in offload_funcs, used for target/offload - function mapping. */ - if (flag_checking) - { - bool found = false; - for (unsigned i = 0; - !found && i < vec_safe_length (offload_funcs); - i++) - if ((*offload_funcs)[i] == current_function_decl) - found = true; - gcc_assert (!found); - } - - if (dump_file) - fprintf (dump_file, - "Discarding function \"%s\" with \"nohost\" clause.\n", - IDENTIFIER_POINTER (DECL_NAME (current_function_decl))); - TREE_ASM_WRITTEN (current_function_decl) = 1; - return TODO_discard_function; - } - } -#endif /* !ACCEL_COMPILER */ - - attr = get_oacc_fn_attrib (current_function_decl); + tree attr = get_oacc_fn_attrib (current_function_decl); if (!attr) /* Not an offloaded function. */ return 0; + + if (maybe_discard_oacc_function (current_function_decl)) + { + if (dump_file) + fprintf (dump_file, "Discarding function\n"); + TREE_ASM_WRITTEN (current_function_decl) = 1; + return TODO_discard_function; + } + int dims[GOMP_DIM_MAX]; int fn_level = oacc_validate_dims (current_function_decl, attr, dims);