From patchwork Thu Oct 1 12:33:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 524964 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 467F41400B7 for ; Thu, 1 Oct 2015 22:33:22 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=DeHZQVEd; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=GRj/eOsQbd2R89mTC qh0wmRvZSY3qIAOy61/VvgvgoXHBBrSjBoJ3mELwgOmjBqacJMfQ9XeLBgD6tjdo AFrgI5sDB5lve7qsAnMcZ6nOcK+j/KsTenU+O9BSSXnXB//uePzQHV7qCq6y3fbq Im9DvBl34Af0xroxM77u/phwmE= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=rVDn9skqyx/Hv4Y8OR4/e66 wcPo=; b=DeHZQVEdnm2TcIlzeRWpbFkZ7JnMgS1xh2zJRKEL7tVOXCBnvDW9fmb RhLfJkTtvPbeJczkmQdsIr83PY8D3r/HyBhKOZDr6NsULkhktpfd6vBN1TtxoJsv Y1uoZSgOsC2ECw+1O8dtF98UtarAV+VsGxKUVPpp4uGjj2xTLSfw= Received: (qmail 73140 invoked by alias); 1 Oct 2015 12:33:14 -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 73127 invoked by uid 89); 1 Oct 2015 12:33:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=BAYES_20, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=no version=3.3.2 X-HELO: mail-qg0-f45.google.com Received: from mail-qg0-f45.google.com (HELO mail-qg0-f45.google.com) (209.85.192.45) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 12:33:11 +0000 Received: by qgx61 with SMTP id 61so62921228qgx.3 for ; Thu, 01 Oct 2015 05:33:09 -0700 (PDT) X-Received: by 10.55.215.152 with SMTP id t24mr11570602qkt.18.1443702789451; Thu, 01 Oct 2015 05:33:09 -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 g20sm2318968qge.9.2015.10.01.05.33.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 05:33:08 -0700 (PDT) Subject: Re: Fold acc_on_device To: Richard Biener , Jakub Jelinek References: <560AD6A6.4050109@acm.org> <560BD31C.9020503@acm.org> <560C3182.6060204@acm.org> <20150930192230.GT1847@tucnak.redhat.com> Cc: Bernd Schmidt , GCC Patches From: Nathan Sidwell Message-ID: <560D2803.5080304@acm.org> Date: Thu, 1 Oct 2015 08:33:07 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: On 10/01/15 06:03, Richard Biener wrote: > On Wed, Sep 30, 2015 at 9:22 PM, Jakub Jelinek wrote: >> Wouldn't it be better to just emit GIMPLE here instead? >> So >> tree res = make_ssa_name (boolean_type_node); >> gimple g = gimple_build_assign (res, EQ_EXPR, arg0, >> build_int_cst (integer_type_node, val_host)); >> gsi_insert_before (gsi, g); >> ... Like this? nathan 2015-10-01 Nathan Sidwell * builtins.c: Don't include gomp-constants.h. (fold_builtin_1): Don't fold acc_on_device here. * gimple-fold.c: Include gomp-constants.h. (gimple_fold_builtin_acc_on_device): New. (gimple_fold_builtin): Call it. Index: gcc/gimple-fold.c =================================================================== --- gcc/gimple-fold.c (revision 228288) +++ gcc/gimple-fold.c (working copy) @@ -62,6 +62,7 @@ along with GCC; see the file COPYING3. #include "output.h" #include "tree-eh.h" #include "gimple-match.h" +#include "gomp-constants.h" /* Return true when DECL can be referenced from current unit. FROM_DECL (if non-null) specify constructor of variable DECL was taken from. @@ -2708,6 +2709,47 @@ gimple_fold_builtin_strlen (gimple_stmt_ return true; } +/* Fold a call to __builtin_acc_on_device. */ + +static bool +gimple_fold_builtin_acc_on_device (gimple_stmt_iterator *gsi, tree arg0) +{ + /* Defer folding until we know which compiler we're in. */ + if (symtab->state != EXPANSION) + return false; + + unsigned val_host = GOMP_DEVICE_HOST; + unsigned val_dev = GOMP_DEVICE_NONE; + +#ifdef ACCEL_COMPILER + val_host = GOMP_DEVICE_NOT_HOST; + val_dev = ACCEL_COMPILER_acc_device; +#endif + + location_t loc = gimple_location (gsi_stmt (*gsi)); + + tree host_eq = make_ssa_name (boolean_type_node); + gimple *host_ass = gimple_build_assign + (host_eq, EQ_EXPR, arg0, build_int_cst (integer_type_node, val_host)); + gimple_set_location (host_ass, loc); + gsi_insert_before (gsi, host_ass, GSI_SAME_STMT); + + tree dev_eq = make_ssa_name (boolean_type_node); + gimple *dev_ass = gimple_build_assign + (dev_eq, EQ_EXPR, arg0, build_int_cst (integer_type_node, val_dev)); + gimple_set_location (host_ass, loc); + gsi_insert_before (gsi, dev_ass, GSI_SAME_STMT); + + tree result = make_ssa_name (boolean_type_node); + gimple *result_ass = gimple_build_assign + (result, BIT_IOR_EXPR, host_eq, dev_eq); + gimple_set_location (host_ass, loc); + gsi_insert_before (gsi, result_ass, GSI_SAME_STMT); + + replace_call_with_value (gsi, result); + + return true; +} /* Fold the non-target builtin at *GSI and return whether any simplification was made. */ @@ -2848,6 +2890,9 @@ gimple_fold_builtin (gimple_stmt_iterato n == 3 ? gimple_call_arg (stmt, 2) : NULL_TREE, fcode); + case BUILT_IN_ACC_ON_DEVICE: + return gimple_fold_builtin_acc_on_device (gsi, + gimple_call_arg (stmt, 0)); default:; } Index: gcc/builtins.c =================================================================== --- gcc/builtins.c (revision 228288) +++ gcc/builtins.c (working copy) @@ -64,7 +64,6 @@ along with GCC; see the file COPYING3. #include "cgraph.h" #include "tree-chkp.h" #include "rtl-chkp.h" -#include "gomp-constants.h" static tree do_mpc_arg1 (tree, tree, int (*)(mpc_ptr, mpc_srcptr, mpc_rnd_t)); @@ -10230,27 +10229,6 @@ fold_builtin_1 (location_t loc, tree fnd return build_empty_stmt (loc); break; - case BUILT_IN_ACC_ON_DEVICE: - /* Don't fold on_device until we know which compiler is active. */ - if (symtab->state == EXPANSION) - { - unsigned val_host = GOMP_DEVICE_HOST; - unsigned val_dev = GOMP_DEVICE_NONE; - -#ifdef ACCEL_COMPILER - val_host = GOMP_DEVICE_NOT_HOST; - val_dev = ACCEL_COMPILER_acc_device; -#endif - tree host = build2 (EQ_EXPR, boolean_type_node, arg0, - build_int_cst (integer_type_node, val_host)); - tree dev = build2 (EQ_EXPR, boolean_type_node, arg0, - build_int_cst (integer_type_node, val_dev)); - - tree result = build2 (TRUTH_OR_EXPR, boolean_type_node, host, dev); - return fold_convert (integer_type_node, result); - } - break; - default: break; }