diff mbox series

libgomp/target.c: Minor cleanup

Message ID fd202d3f-dbdd-8889-df16-8c4a90205203@codesourcery.com
State New
Headers show
Series libgomp/target.c: Minor cleanup | expand

Commit Message

Tobias Burnus Sept. 10, 2020, 9:17 a.m. UTC
Hi Jakub, hello all,

when looking at target.c, I stumbled over that code:
   size_t mapnum  → unsigned
   if (mapnum == 0)
     ...
     return;

   if (mapnum > 0 || ....)
     ...

I fail to see how the latter condition can ever become false;
hence, I removed the "if" and used the if-body unconditionally,
removing some now pointless assignments.

OK?

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter

Comments

Jakub Jelinek Sept. 10, 2020, 9:22 a.m. UTC | #1
On Thu, Sep 10, 2020 at 11:17:34AM +0200, Tobias Burnus wrote:
> Hi Jakub, hello all,
> 
> when looking at target.c, I stumbled over that code:
>   size_t mapnum  → unsigned
>   if (mapnum == 0)
>     ...
>     return;
> 
>   if (mapnum > 0 || ....)
>     ...

But it is not mapnum > 0 here but mapnum > 1
So, for mapnum == 1 and e.g. target enter data it doesn't need to create the
chunks stuff, for a single mapping there is nothing to merge together.

> diff --git a/libgomp/target.c b/libgomp/target.c
> index 3e292eb8c62..440aad6b048 100644
> --- a/libgomp/target.c
> +++ b/libgomp/target.c
> @@ -676,28 +676,23 @@ gomp_map_vars_internal (struct gomp_device_descr *devicep,
>    if (mapnum == 0)
>      {
>        tgt->tgt_start = 0;
>        tgt->tgt_end = 0;
>        return tgt;
>      }
>  
>    tgt_align = sizeof (void *);
>    tgt_size = 0;
> -  cbuf.chunks = NULL;
> -  cbuf.chunk_cnt = -1;
> +  cbuf.chunk_cnt = 0;
>    cbuf.use_cnt = 0;
> -  cbuf.buf = NULL;
> -  if (mapnum > 1 || pragma_kind == GOMP_MAP_VARS_TARGET)
> -    {
> -      size_t chunks_size = (mapnum + 1) * sizeof (struct gomp_coalesce_chunk);
> -      cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
> -      cbuf.chunk_cnt = 0;
> -    }
> +  size_t chunks_size = (mapnum + 1) * sizeof (struct gomp_coalesce_chunk);
> +  cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
> +
>    if (pragma_kind == GOMP_MAP_VARS_TARGET)
>      {
>        size_t align = 4 * sizeof (void *);
>        tgt_align = align;
>        tgt_size = mapnum * sizeof (void *);
>        cbuf.chunk_cnt = 1;
>        cbuf.use_cnt = 1 + (mapnum > 1);
>        cbuf.chunks[0].start = 0;
>        cbuf.chunks[0].end = tgt_size;


	Jakub
Tobias Burnus Sept. 10, 2020, 9:39 a.m. UTC | #2
On 9/10/20 11:22 AM, Jakub Jelinek wrote:

> But it is not mapnum > 0 here but mapnum >1

Error: need more coffee (well, tea)

Thanks for both the reasoning and catching this oversight of mine.

Tobias

-----------------
Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany
Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter
diff mbox series

Patch

libgomp/target.c: Minor cleanup

libgomp/ChangeLog:

	* target.c (gomp_map_vars_internal): Remove always-true condition
	and body unconditionally.

diff --git a/libgomp/target.c b/libgomp/target.c
index 3e292eb8c62..440aad6b048 100644
--- a/libgomp/target.c
+++ b/libgomp/target.c
@@ -676,28 +676,23 @@  gomp_map_vars_internal (struct gomp_device_descr *devicep,
   if (mapnum == 0)
     {
       tgt->tgt_start = 0;
       tgt->tgt_end = 0;
       return tgt;
     }
 
   tgt_align = sizeof (void *);
   tgt_size = 0;
-  cbuf.chunks = NULL;
-  cbuf.chunk_cnt = -1;
+  cbuf.chunk_cnt = 0;
   cbuf.use_cnt = 0;
-  cbuf.buf = NULL;
-  if (mapnum > 1 || pragma_kind == GOMP_MAP_VARS_TARGET)
-    {
-      size_t chunks_size = (mapnum + 1) * sizeof (struct gomp_coalesce_chunk);
-      cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
-      cbuf.chunk_cnt = 0;
-    }
+  size_t chunks_size = (mapnum + 1) * sizeof (struct gomp_coalesce_chunk);
+  cbuf.chunks = (struct gomp_coalesce_chunk *) gomp_alloca (chunks_size);
+
   if (pragma_kind == GOMP_MAP_VARS_TARGET)
     {
       size_t align = 4 * sizeof (void *);
       tgt_align = align;
       tgt_size = mapnum * sizeof (void *);
       cbuf.chunk_cnt = 1;
       cbuf.use_cnt = 1 + (mapnum > 1);
       cbuf.chunks[0].start = 0;
       cbuf.chunks[0].end = tgt_size;