From patchwork Thu Oct 3 16:35:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 1171274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-510166-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="qAgNkN/J"; 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 46kdsh1jwqz9sVW for ; Fri, 4 Oct 2019 02:35:36 +1000 (AEST) 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:mime-version :content-transfer-encoding:content-type; q=dns; s=default; b=gxj vkZyewk7k1cJ2xwxY5JivzXGxqsErTjoANOvZk3oznTGGmYpHTZm9IvOma36Ew7C x9BXF+/sY1zf9wmp2O9X+EWXn7BfegikU2BqoOHZ9pAWCvTL8wDCSf+/qznujp98 toK5Qwuscw2JVlpYShd+6oXq7RZMM4QbfdHg/Q/I= 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:mime-version :content-transfer-encoding:content-type; s=default; bh=nLfjqng+5 CVNQBulZ56A0cRjiuQ=; b=qAgNkN/JmnfjDrmOSBr9HAmV9u7rH2Xws2Fl3ZUEA ETCim+nY+xCMsiJPq2FPURMbgk3WvmgLu8fS+1WvDt7w3Lja0olzV/DZ5E4HCLFm BYHZ2Qe3k0S/dZWznZ82gqqfjhCAgiUWUNTz0Oe37+rNQk85bpVHTGoIK6rXHqnX TM= Received: (qmail 27320 invoked by alias); 3 Oct 2019 16:35:28 -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 27171 invoked by uid 89); 3 Oct 2019 16:35:28 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy=libgomph, comprises, libgomp.h, Special X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Oct 2019 16:35:26 +0000 IronPort-SDR: cUU6M6G5mLXV6OX9IsHfK65b3CUhW+jD/0tVxQOTfn1Qbi0KlZNXyORKp/bHRn5K966ISyLcja bON/ja0w5KLcao4MZtblETd5369RttzW1ziYeRxuo/xBjHTYeq2qgx2q0+EhbvP5H/eTwcvwd0 iVh3BglNz1fHQ6q1/iEOopRwRe9lxtUHXKWUZUGbSyw7rPu0ABif4JPvGS33WqyzENt0bF7Q/0 yMIM92Ze6Djeyzf1Ua+9rfbODq4lifChlRLQrn/aCZjIZgHgWz6z1hLyWrqikqXjI0FhPkWSxf K0M= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 03 Oct 2019 08:35:25 -0800 IronPort-SDR: DCKm/zztnr17WLZpe2Hb8yX+3RdSUmu29antmeX+L+z0b5VgNvkjDKECNhNx1wF6qWfDNZkaeh DDRbXFoVeXlvsxDEQAidnjRW6GyMy0/T7gWtvb4goRltxi5Q4GiQdvQO7VmxHZ+/6uFeld0yoX xuGBN8m8o5mcbslN+BTU1kbhBbrQCpN/YHaQCSW0J1ufCi36erYRKGr7vgu/DLmjTl1FNDAmiz PgqOkzVvK3txR05D9jk3PegxZJnSii3c2ZA0TZZKesvmfqEZFSw/cyxb2JvjEtMj6b51zEcndN vpk= From: Julian Brown To: CC: Jakub Jelinek , Thomas Schwinge Subject: [PATCH] Libgomp magic offset value self-documentation Date: Thu, 3 Oct 2019 09:35:03 -0700 Message-ID: <20191003163505.49997-1-julian@codesourcery.com> MIME-Version: 1.0 X-IsSubscribed: yes This patch provides some macros naming special offset field values used in libgomp/target.c. It was previously posted as part of the series supporting OpenACC 2.6 manual deep copy here: https://gcc.gnu.org/ml/gcc-patches/2018-11/msg00825.html Parts of that patch were committed already by Thomas in: https://gcc.gnu.org/ml/gcc-patches/2018-12/msg01723.html This patch comprises the remaining parts. Tested (alongside other patches) with offloading to NVPTX. OK for trunk? Thanks, Julian 2019-10-02 Julian Brown Cesar Philippidis libgomp/ * libgomp.h (OFFSET_INLINED, OFFSET_POINTER, OFFSET_STRUCT): Define. * target.c (FIELD_TGT_EMPTY): Define. (gomp_map_val): Use OFFSET_* macros instead of magic constants. Write as switch instead of list of ifs. (gomp_map_vars_internal): Use OFFSET_* and FIELD_TGT_EMPTY macros. --- libgomp/libgomp.h | 5 +++++ libgomp/target.c | 44 +++++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h index abb5c2263c4..178eb600ccd 100644 --- a/libgomp/libgomp.h +++ b/libgomp/libgomp.h @@ -903,6 +903,11 @@ struct target_mem_desc { artificial pointer to "omp declare target link" object. */ #define REFCOUNT_LINK (~(uintptr_t) 1) +/* Special offset values. */ +#define OFFSET_INLINED (~(uintptr_t) 0) +#define OFFSET_POINTER (~(uintptr_t) 1) +#define OFFSET_STRUCT (~(uintptr_t) 2) + struct splay_tree_key_s { /* Address of the host object. */ uintptr_t host_start; diff --git a/libgomp/target.c b/libgomp/target.c index 1c9ca68ba10..a83cb48108a 100644 --- a/libgomp/target.c +++ b/libgomp/target.c @@ -44,6 +44,8 @@ #include "plugin-suffix.h" #endif +#define FIELD_TGT_EMPTY (~(size_t) 0) + static void gomp_target_init (void); /* The whole initialization code for offloading plugins is only run one. */ @@ -497,17 +499,25 @@ gomp_map_val (struct target_mem_desc *tgt, void **hostaddrs, size_t i) return tgt->list[i].key->tgt->tgt_start + tgt->list[i].key->tgt_offset + tgt->list[i].offset; - if (tgt->list[i].offset == ~(uintptr_t) 0) - return (uintptr_t) hostaddrs[i]; - if (tgt->list[i].offset == ~(uintptr_t) 1) - return 0; - if (tgt->list[i].offset == ~(uintptr_t) 2) - return tgt->list[i + 1].key->tgt->tgt_start - + tgt->list[i + 1].key->tgt_offset - + tgt->list[i + 1].offset - + (uintptr_t) hostaddrs[i] - - (uintptr_t) hostaddrs[i + 1]; - return tgt->tgt_start + tgt->list[i].offset; + + switch (tgt->list[i].offset) + { + case OFFSET_INLINED: + return (uintptr_t) hostaddrs[i]; + + case OFFSET_POINTER: + return 0; + + case OFFSET_STRUCT: + return tgt->list[i + 1].key->tgt->tgt_start + + tgt->list[i + 1].key->tgt_offset + + tgt->list[i + 1].offset + + (uintptr_t) hostaddrs[i] + - (uintptr_t) hostaddrs[i + 1]; + + default: + return tgt->tgt_start + tgt->list[i].offset; + } } static inline __attribute__((always_inline)) struct target_mem_desc * @@ -575,7 +585,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, || (kind & typemask) == GOMP_MAP_FIRSTPRIVATE_INT) { tgt->list[i].key = NULL; - tgt->list[i].offset = ~(uintptr_t) 0; + tgt->list[i].offset = OFFSET_INLINED; continue; } else if ((kind & typemask) == GOMP_MAP_USE_DEVICE_PTR) @@ -596,7 +606,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, cur_node.host_end = (uintptr_t) hostaddrs[last] + sizes[last]; tgt->list[i].key = NULL; - tgt->list[i].offset = ~(uintptr_t) 2; + tgt->list[i].offset = OFFSET_STRUCT; splay_tree_key n = splay_tree_lookup (mem_map, &cur_node); if (n == NULL) { @@ -629,7 +639,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, else if ((kind & typemask) == GOMP_MAP_ALWAYS_POINTER) { tgt->list[i].key = NULL; - tgt->list[i].offset = ~(uintptr_t) 1; + tgt->list[i].offset = OFFSET_POINTER; has_firstprivate = true; continue; } @@ -659,7 +669,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, if (!n) { tgt->list[i].key = NULL; - tgt->list[i].offset = ~(uintptr_t) 1; + tgt->list[i].offset = OFFSET_POINTER; continue; } } @@ -884,12 +894,12 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, size_t align = (size_t) 1 << (kind >> rshift); tgt->list[i].key = k; k->tgt = tgt; - if (field_tgt_clear != ~(size_t) 0) + if (field_tgt_clear != FIELD_TGT_EMPTY) { k->tgt_offset = k->host_start - field_tgt_base + field_tgt_offset; if (i == field_tgt_clear) - field_tgt_clear = ~(size_t) 0; + field_tgt_clear = FIELD_TGT_EMPTY; } else {