Commit 2a656a93 by Julian Brown Committed by Julian Brown

Use aux struct in libgomp for infrequently-used/API-specific data

	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.

Co-Authored-By: Thomas Schwinge <thomas@codesourcery.com>

From-SVN: r279620
parent 8cce8b85
2019-12-19 Julian Brown <julian@codesourcery.com>
Thomas Schwinge <thomas@codesourcery.com>
* 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.
2019-12-18 Jakub Jelinek <jakub@redhat.com> 2019-12-18 Jakub Jelinek <jakub@redhat.com>
PR middle-end/86416 PR middle-end/86416
......
...@@ -989,6 +989,13 @@ struct target_mem_desc { ...@@ -989,6 +989,13 @@ struct target_mem_desc {
#define OFFSET_POINTER (~(uintptr_t) 1) #define OFFSET_POINTER (~(uintptr_t) 1)
#define OFFSET_STRUCT (~(uintptr_t) 2) #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 { struct splay_tree_key_s {
/* Address of the host object. */ /* Address of the host object. */
uintptr_t host_start; uintptr_t host_start;
...@@ -1002,8 +1009,7 @@ struct splay_tree_key_s { ...@@ -1002,8 +1009,7 @@ struct splay_tree_key_s {
uintptr_t refcount; uintptr_t refcount;
/* Dynamic reference count. */ /* Dynamic reference count. */
uintptr_t dynamic_refcount; uintptr_t dynamic_refcount;
/* Pointer to the original mapping of "omp declare target link" object. */ struct splay_tree_aux *aux;
splay_tree_key link_key;
}; };
/* The comparison function. */ /* The comparison function. */
......
...@@ -931,13 +931,15 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, ...@@ -931,13 +931,15 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
kind & typemask, cbufp); kind & typemask, cbufp);
else else
{ {
k->link_key = NULL; k->aux = NULL;
if (n && n->refcount == REFCOUNT_LINK) if (n && n->refcount == REFCOUNT_LINK)
{ {
/* Replace target address of the pointer with target address /* Replace target address of the pointer with target address
of mapped object in the splay tree. */ of mapped object in the splay tree. */
splay_tree_remove (mem_map, n); 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); size_t align = (size_t) 1 << (kind >> rshift);
tgt->list[i].key = k; tgt->list[i].key = k;
...@@ -1055,7 +1057,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep, ...@@ -1055,7 +1057,7 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
kind); kind);
} }
if (k->link_key) if (k->aux && k->aux->link_key)
{ {
/* Set link pointer on target to the device address of the /* Set link pointer on target to the device address of the
mapped object. */ mapped object. */
...@@ -1170,8 +1172,14 @@ gomp_remove_var_internal (struct gomp_device_descr *devicep, splay_tree_key k, ...@@ -1170,8 +1172,14 @@ gomp_remove_var_internal (struct gomp_device_descr *devicep, splay_tree_key k,
{ {
bool is_tgt_unmapped = false; bool is_tgt_unmapped = false;
splay_tree_remove (&devicep->mem_map, k); splay_tree_remove (&devicep->mem_map, k);
if (k->link_key) if (k->aux)
splay_tree_insert (&devicep->mem_map, (splay_tree_node) k->link_key); {
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) if (aq)
devicep->openacc.async.queue_callback_func (aq, gomp_unref_tgt_void, devicep->openacc.async.queue_callback_func (aq, gomp_unref_tgt_void,
(void *) k->tgt); (void *) k->tgt);
...@@ -1398,7 +1406,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version, ...@@ -1398,7 +1406,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
k->tgt_offset = target_table[i].start; k->tgt_offset = target_table[i].start;
k->refcount = REFCOUNT_INFINITY; k->refcount = REFCOUNT_INFINITY;
k->dynamic_refcount = 0; k->dynamic_refcount = 0;
k->link_key = NULL; k->aux = NULL;
array->left = NULL; array->left = NULL;
array->right = NULL; array->right = NULL;
splay_tree_insert (&devicep->mem_map, array); splay_tree_insert (&devicep->mem_map, array);
...@@ -1431,7 +1439,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version, ...@@ -1431,7 +1439,7 @@ gomp_load_image_to_device (struct gomp_device_descr *devicep, unsigned version,
k->tgt_offset = target_var->start; k->tgt_offset = target_var->start;
k->refcount = target_size & link_bit ? REFCOUNT_LINK : REFCOUNT_INFINITY; k->refcount = target_size & link_bit ? REFCOUNT_LINK : REFCOUNT_INFINITY;
k->dynamic_refcount = 0; k->dynamic_refcount = 0;
k->link_key = NULL; k->aux = NULL;
array->left = NULL; array->left = NULL;
array->right = NULL; array->right = NULL;
splay_tree_insert (&devicep->mem_map, array); splay_tree_insert (&devicep->mem_map, array);
...@@ -2693,6 +2701,7 @@ omp_target_associate_ptr (const void *host_ptr, const void *device_ptr, ...@@ -2693,6 +2701,7 @@ omp_target_associate_ptr (const void *host_ptr, const void *device_ptr,
k->tgt_offset = (uintptr_t) device_ptr + device_offset; k->tgt_offset = (uintptr_t) device_ptr + device_offset;
k->refcount = REFCOUNT_INFINITY; k->refcount = REFCOUNT_INFINITY;
k->dynamic_refcount = 0; k->dynamic_refcount = 0;
k->aux = NULL;
array->left = NULL; array->left = NULL;
array->right = NULL; array->right = NULL;
splay_tree_insert (&devicep->mem_map, array); splay_tree_insert (&devicep->mem_map, array);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment