[01/13] Use aux struct in libgomp for infrequently-used/API-specific data

Message ID 80e0dba326a4414fd2dbe8401dbd8d8f08445129.1576648001.git.julian@codesourcery.com
State New
Headers show
Series
  • OpenACC 2.6 manual deep copy support
Related show

Commit Message

Julian Brown Dec. 18, 2019, 6:02 a.m.
This patch has been broken out of the "OpenACC 2.6 manual deep copy
support" patch, last posted here:

  https://gcc.gnu.org/ml/gcc-patches/2019-11/msg02376.html

This part is included for completeness. It is the same as the patch
posted by Thomas here:

  https://gcc.gnu.org/ml/gcc-patches/2019-12/msg01208.html

Tested together with other patches in this series with offloading
to NVPTX.

OK for mainline?

Thanks,

Julian

ChangeLog

	libgomp/
	* libgomp.h (struct splay_tree_aux): New.
	(struct splay_tree_key_s): Replace link_key field with aux pointer.
	* target.c (gomp_map_vars_internal): Adjust for link_key being moved
	to aux struct.
	(gomp_remove_var_internal): Free aux block if present.
	(gomp_load_image_to_device): Zero-initialise aux field instead of
	link_key field.
	(omp_target_associate_pointer): Zero-initialise aux field.
---
 libgomp/libgomp.h | 10 ++++++++--
 libgomp/target.c  | 23 ++++++++++++++++-------
 2 files changed, 24 insertions(+), 9 deletions(-)

-- 
2.23.0

Patch

diff --git a/libgomp/libgomp.h b/libgomp/libgomp.h
index 36dcca28353..0f1f11284d5 100644
--- a/libgomp/libgomp.h
+++ b/libgomp/libgomp.h
@@ -989,6 +989,13 @@  struct target_mem_desc {
 #define OFFSET_POINTER (~(uintptr_t) 1)
 #define OFFSET_STRUCT (~(uintptr_t) 2)
 
+/* Auxiliary structure for infrequently-used or API-specific data.  */
+
+struct splay_tree_aux {
+  /* Pointer to the original mapping of "omp declare target link" object.  */
+  splay_tree_key link_key;
+};
+
 struct splay_tree_key_s {
   /* Address of the host object.  */
   uintptr_t host_start;
@@ -1002,8 +1009,7 @@  struct splay_tree_key_s {
   uintptr_t refcount;
   /* Dynamic reference count.  */
   uintptr_t dynamic_refcount;
-  /* Pointer to the original mapping of "omp declare target link" object.  */
-  splay_tree_key link_key;
+  struct splay_tree_aux *aux;
 };
 
 /* The comparison function.  */
diff --git a/libgomp/target.c b/libgomp/target.c
index 82ed38c01ec..97c2b5c5e4d 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -907,13 +907,15 @@  gomp_map_vars_internal (struct gomp_device_descr *devicep,
 				      kind & typemask, cbufp);
 	    else
 	      {
-		k->link_key = NULL;
+		k->aux = NULL;
 		if (n && n->refcount == REFCOUNT_LINK)
 		  {
 		    /* Replace target address of the pointer with target address
 		       of mapped object in the splay tree.  */
 		    splay_tree_remove (mem_map, n);
-		    k->link_key = n;
+		    k->aux
+		      = gomp_malloc_cleared (sizeof (struct splay_tree_aux));
+		    k->aux->link_key = n;
 		  }
 		size_t align = (size_t) 1 << (kind >> rshift);
 		tgt->list[i].key = k;
@@ -1031,7 +1033,7 @@  gomp_map_vars_internal (struct gomp_device_descr *devicep,
 				kind);
 		  }
 
-		if (k->link_key)
+		if (k->aux && k->aux->link_key)
 		  {
 		    /* Set link pointer on target to the device address of the
 		       mapped object.  */
@@ -1146,8 +1148,14 @@  gomp_remove_var_internal (struct gomp_device_descr *devicep, splay_tree_key k,
 {
   bool is_tgt_unmapped = false;
   splay_tree_remove (&devicep->mem_map, k);
-  if (k->link_key)
-    splay_tree_insert (&devicep->mem_map, (splay_tree_node) k->link_key);
+  if (k->aux)
+    {
+      if (k->aux->link_key)
+	splay_tree_insert (&devicep->mem_map,
+			   (splay_tree_node) k->aux->link_key);
+      free (k->aux);
+      k->aux = NULL;
+    }
   if (aq)
     devicep->openacc.async.queue_callback_func (aq, gomp_unref_tgt_void,
 						(void *) k->tgt);
@@ -1366,7 +1374,7 @@  gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
       k->tgt_offset = target_table[i].start;
       k->refcount = REFCOUNT_INFINITY;
       k->dynamic_refcount = 0;
-      k->link_key = NULL;
+      k->aux = NULL;
       array->left = NULL;
       array->right = NULL;
       splay_tree_insert (&devicep->mem_map, array);
@@ -1399,7 +1407,7 @@  gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
       k->tgt_offset = target_var->start;
       k->refcount = target_size & link_bit ? REFCOUNT_LINK : REFCOUNT_INFINITY;
       k->dynamic_refcount = 0;
-      k->link_key = NULL;
+      k->aux = NULL;
       array->left = NULL;
       array->right = NULL;
       splay_tree_insert (&devicep->mem_map, array);
@@ -2661,6 +2669,7 @@  omp_target_associate_ptr (const void *host_ptr, const void *device_ptr,
       k->tgt_offset = (uintptr_t) device_ptr + device_offset;
       k->refcount = REFCOUNT_INFINITY;
       k->dynamic_refcount = 0;
+      k->aux = NULL;
       array->left = NULL;
       array->right = NULL;
       splay_tree_insert (&devicep->mem_map, array);