From patchwork Tue Nov 16 11:49:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Stubbs X-Patchwork-Id: 47761 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 510CA3857809 for ; Tue, 16 Nov 2021 11:49:42 +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 C75083858430 for ; Tue, 16 Nov 2021 11:49:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C75083858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: ATaGW3FJShBUz2GXYciPDKXjvtXSzA8xCYkKKMNoPOjLjQbTTkBIux8+1901gwHrO/ibzueM75 bamXk5CzojjeJA5UXvk+josPHY2TLhFu+u7INav/bz8mvuF9nY72BTIgtmgpXxYAjDl2XYc/0k BCVRHvXMDeVcMyhaFrUUsuyamUvQTrRA83caQfVXGPriKOZR3mCIUIjevm5CPof2L1nlObVR2I 55GRFUlGSTsuABSorbq9dItp6JD0iWkqWiRxqXBTvUXUHCeKPVT5VqgZC//wpHAky56rYkv+77 YSAvpUU4frPnx2RZc76BUqTo X-IronPort-AV: E=Sophos;i="5.87,239,1631606400"; d="scan'208";a="68385052" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 16 Nov 2021 03:49:23 -0800 IronPort-SDR: FmwKwMOBLnwO6hmOTaUBr625CnVbxlcxuBJpNOM/nqCsJFREG2JOp9NU7YYmgRJQsNJQE4MfHc H//Whgb3x6yA2TOpXiBwqM3pvPA4A4RhsGnHhoBRaY9lNGATWAkIIL7bB9/0hloaLbyuKKwYpC 4gfiqfWae7M6863wiH8UJuWqxmTZuvkIpbrVT1rFKrTaKziSuKC3vSOo3EuDPDAdjlf0molz4a uWYM05VDXHDWMZHgRB76OCGFcgm8yIymIAfwd6Dx6GsHrvlomqabdFbzGXHPTtX1wK0YngJgJG BVw= Message-ID: <6843a549-0d4d-0ca7-ae34-929a15e0fa98@codesourcery.com> Date: Tue, 16 Nov 2021 11:49:18 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Content-Language: en-GB From: Andrew Stubbs Subject: [PATCH] OpenMP: Ensure that offloaded variables are public To: "gcc-patches@gcc.gnu.org" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-13.mgc.mentorg.com (139.181.222.13) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch is needed for AMD GCN offloading when we use the assembler from LLVM 13+. The GCN runtime (libgomp+ROCm) requires that the location of all variables in the offloaded variables table are discoverable at runtime (using the "hsa_executable_symbol_get_info" API), and this only works when the symbols are exported from the binary. Previously we solved this by having mkoffload insert ".global" directives into the assembler text, but newer LLVM assemblers emit an error if we do this when then variable was previously declared ".local" (which happens when a variable is zero-initialized and placed in the BSS). Since we can no longer easily fix them up after the fact, this patch fixes them up during OMP lowering. OK? Andrew OpenMP: Ensure that offloaded variables are public The AMD GCN runtime loader requires that variables in the offload table are exported (public) so that it can locate the load address and do the mapping. gcc/ChangeLog: * config/gcn/mkoffload.c (process_asm): Don't add .global directives. * omp-offload.c (pass_omp_target_link::execute): Make offload_vars public. diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c index b2e71ea5aa00..5b130cc6de71 100644 --- a/gcc/config/gcn/mkoffload.c +++ b/gcc/config/gcn/mkoffload.c @@ -573,10 +573,6 @@ process_asm (FILE *in, FILE *out, FILE *cfile) abort (); obstack_int_grow (&varsizes_os, varsize); var_count++; - - /* The HSA Runtime cannot locate the symbol if it is not - exported from the kernel. */ - fprintf (out, "\t.global %s\n", varname); } break; } diff --git a/gcc/omp-offload.c b/gcc/omp-offload.c index 833f7ddea58f..c6fb87a5dee2 100644 --- a/gcc/omp-offload.c +++ b/gcc/omp-offload.c @@ -2799,6 +2799,18 @@ pass_omp_target_link::execute (function *fun) } } + /* Variables in the offload table may need to be public for the runtime + loader to be able to locate them. (This is true for at least amdgcn.) */ + if (offload_vars) + for (auto it = offload_vars->begin (); it != offload_vars->end (); it++) + if (!TREE_PUBLIC (*it)) + { + TREE_PUBLIC (*it) = 1; + + if (dump_enabled_p () && dump_flags & TDF_DETAILS) + dump_printf (MSG_NOTE, "Make offload var public: %T\n", *it); + } + return 0; }