From patchwork Fri Nov 15 21:41:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1195860 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-513684-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="nvmcZXRi"; dkim-atps=neutral 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 47FBdb46Dgz9s4Y for ; Sat, 16 Nov 2019 08:42:10 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; q=dns; s= default; b=xQqK/oMRe1gAA6uG2fQt4Sm3i/26qVduWRmMtN+wF0WOqaYDIvVCb cC88vnGY3tQPwP8NrwmPJoeo77pC1K1zaYHW++QePMFZgpNh8l7ffR5/SK7LW+8T 6BZI/Pk6yHvD3sdcxtNVRBJT5rMOSruJ/Nc+Rr7mpgnEKfBNhogJ5I= 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:from :to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=default; bh=6T664o0UOFyPfaq6OC2N7HkXo18=; b=nvmcZXRitjnzoK+t8yMayvHqv/lz QtHEz0dXgWjnhO+jpkJ6vHuEJzQIZi8QXYsAM+BC5sVG0u7CbiYyrAl3lvM4A/lK T1API4HUWQtB0zvfc6WBPn9fAb8F6TdIOfKZY/l427Lf3qqNb1oUu1lTfgd8IZtr bV8aY7gfoPDnxlA= Received: (qmail 39577 invoked by alias); 15 Nov 2019 21:41:58 -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 39510 invoked by uid 89); 15 Nov 2019 21:41:57 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-23.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=H*MI:sk:cover.1, update_stmt X-HELO: esa2.mentor.iphmx.com Received: from esa2.mentor.iphmx.com (HELO esa2.mentor.iphmx.com) (68.232.141.98) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Nov 2019 21:41:55 +0000 IronPort-SDR: gnRepjJWYMAVfF6KmhukINro1GFIDsY3K4hIMJB/tHWYzUpVl2FOkenXVoUPBkEXQWRjWxV+yW 5fJ8eyS6rXFNOZsZhYz8A2FpxSLKeIUQ9jQX8sG+3ZYzkCjO2FfkwchkS9ud9TrcpmyyefTjMd AyqKPXMF/eVf277uBDZU0uBGar8SPXqgt1g9dJsssjrO7oTNdInKcLgN1g3t0ZrVfujSLGrGj2 fVMPjmLICceX0lm4Pz0OGmdh2KgS5EDDVlf1rjDfuL8V6fPA8ZIZa8QnuhuSRfsQTZNDi0lTZa zUM= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 15 Nov 2019 13:41:54 -0800 IronPort-SDR: XMk+tyOrNMH/TLdzsg1rmAAzV8HvOGMYIirsIEM9YeQVQSK6Ln9gleoFqMHP3OPaCa+vEjIfpT n0UbCis2+BXLa6bXPnlYrYUNbP2IQO4s2C2LcSs7WEgDJvxuUmy8PHCbjLWcwPFeAgk1aOzVXF gdW6w7z9ivZ9bZK8g3RzWSE2by0b+1wnn4VGlHq0Ju74wnHNH4HHN60Go81gYNVez1mBYZF4pD II82u9ZTNAcPLU8pm5UL84YnKVzShZJ1YIIVExIStpZlAwe4NetyyU9z3BxM+Nk6SpIkKftIRe Jpo= From: Julian Brown To: CC: , , , Andrew Stubbs Subject: [PATCH 02/13] Target-dependent gang-private variable decl rewriting Date: Fri, 15 Nov 2019 13:41:12 -0800 Message-ID: <7418bfe5c95eecc8e87601d0181a9c9d1775a8c5.1573849743.git.julian@codesourcery.com> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes This patch provides support for the adjust_private_decl hook introduced by the previous patch changing the type of its decl argument, e.g. if the offload target forces it into another address space. Any ADDR_EXPR nodes that have the decl as an argument will have the wrong type: this patch implements a scheme to rewrite those nodes at oaccdevlow time. Arguments to sync builtins are handled specially, since those often have variants that operate on alternative address spaces, so the rewritten decl can be passed to them directly. ChangeLog gcc/ * omp-offload.c (struct addr_expr_rewrite_info): Add struct. (rewrite_addr_expr): New function. (is_sync_builtin_call): New function. (execute_oacc_device_lower): Fix up addr_expr nodes whose argument type has changed after calling the OpenACC adjust_private_decl hook. --- gcc/omp-offload.c | 130 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 129 insertions(+), 1 deletion(-) diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index d8291125370..2e56a04a714 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -1502,6 +1502,78 @@ default_goacc_reduction (gcall *call) gsi_replace_with_seq (&gsi, seq, true); } +struct addr_expr_rewrite_info +{ + gimple *stmt; + hash_set *adjusted_vars; + bool avoid_pointer_conversion; + bool modified; +}; + +static tree +rewrite_addr_expr (tree *tp, int *walk_subtrees, void *data) +{ + walk_stmt_info *wi = (walk_stmt_info *) data; + addr_expr_rewrite_info *info = (addr_expr_rewrite_info *) wi->info; + + if (TREE_CODE (*tp) == ADDR_EXPR) + { + tree arg = TREE_OPERAND (*tp, 0); + + if (info->adjusted_vars->contains (arg)) + { + if (info->avoid_pointer_conversion) + { + *tp = build_fold_addr_expr (arg); + info->modified = true; + *walk_subtrees = 0; + } + else + { + gimple_stmt_iterator gsi = gsi_for_stmt (info->stmt); + tree repl = build_fold_addr_expr (arg); + gimple *stmt1 + = gimple_build_assign (make_ssa_name (TREE_TYPE (repl)), repl); + tree conv = convert_to_pointer (TREE_TYPE (*tp), + gimple_assign_lhs (stmt1)); + gimple *stmt2 + = gimple_build_assign (make_ssa_name (TREE_TYPE (*tp)), conv); + gsi_insert_before (&gsi, stmt1, GSI_SAME_STMT); + gsi_insert_before (&gsi, stmt2, GSI_SAME_STMT); + *tp = gimple_assign_lhs (stmt2); + info->modified = true; + *walk_subtrees = 0; + } + } + } + + return NULL_TREE; +} + +/* Return TRUE if CALL is a call to a builtin atomic/sync operation. */ + +static bool +is_sync_builtin_call (gcall *call) +{ + tree callee = gimple_call_fndecl (call); + + if (callee != NULL_TREE + && gimple_call_builtin_p (call, BUILT_IN_NORMAL)) + switch (DECL_FUNCTION_CODE (callee)) + { +#undef DEF_SYNC_BUILTIN +#define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM: +#include "sync-builtins.def" +#undef DEF_SYNC_BUILTIN + return true; + + default: + ; + } + + 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). */ @@ -1611,6 +1683,8 @@ execute_oacc_device_lower () dominance information to update SSA. */ calculate_dominance_info (CDI_DOMINATORS); + hash_set adjusted_vars; + /* Now lower internal loop functions to target-specific code sequences. */ basic_block bb; @@ -1714,7 +1788,12 @@ execute_oacc_device_lower () fputc ('\n', dump_file); } if (targetm.goacc.adjust_private_decl) - targetm.goacc.adjust_private_decl (decl, level); + { + tree oldtype = TREE_TYPE (decl); + targetm.goacc.adjust_private_decl (decl, level); + if (TREE_TYPE (decl) != oldtype) + adjusted_vars.add (decl); + } } remove = true; } @@ -1750,6 +1829,55 @@ execute_oacc_device_lower () gsi_next (&gsi); } + /* Make adjustments to gang-private local variables if required by the + target, e.g. forcing them into a particular address space. Afterwards, + ADDR_EXPR nodes which have adjusted variables as their argument need to + be modified in one of two ways: + + 1. They can be recreated, making a pointer to the variable in the new + address space, or + + 2. The address of the variable in the new address space can be taken, + converted to the default (original) address space, and the result of + that conversion subsituted in place of the original ADDR_EXPR node. + + Which of these is done depends on the gimple statement being processed. + At present atomic operations and inline asms use (1), and everything else + uses (2). At least on AMD GCN, there are atomic operations that work + directly in the LDS address space. */ + + if (targetm.goacc.adjust_private_decl) + { + tree var; + unsigned i; + + FOR_ALL_BB_FN (bb, cfun) + for (gimple_stmt_iterator gsi = gsi_start_bb (bb); + !gsi_end_p (gsi); + gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + walk_stmt_info wi; + addr_expr_rewrite_info info; + + info.avoid_pointer_conversion + = (is_gimple_call (stmt) + && is_sync_builtin_call (as_a (stmt))) + || gimple_code (stmt) == GIMPLE_ASM; + info.stmt = stmt; + info.modified = false; + info.adjusted_vars = &adjusted_vars; + + memset (&wi, 0, sizeof (wi)); + wi.info = &info; + + walk_gimple_op (stmt, rewrite_addr_expr, &wi); + + if (info.modified) + update_stmt (stmt); + } + } + free_oacc_loop (loops); return 0;