[PATCH] D106165: [flang][OpenMP] Add semantic check for target nesting

Peixin Qiao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 16 19:17:07 PDT 2021


peixin updated this revision to Diff 359515.
peixin added a comment.

@clementval Thanks for the comments. Upload the following update:

1. I am reminded that the counter is not necessary since the if branch `dirContext_.size() >= 1` already checks the directive nested. Delete the counter usage and checking `GetContext().directive == llvm::omp::Directive::OMPD_target` inside `dirContext_.size() >= 1` check is enough.
2. Add the error check in test case.
3. There is no this error info before, or at lease I did not find in f18 openmp semantic check. I test gfortran 9.3.0 and it gives the following warning:

     15 |   !$omp target update from(arrayA) to(arrayB)
  Warning: ‘target update’ construct inside of ‘target’ region
     23 |   !$omp target data map(to: a)
  Warning: ‘target data’ construct inside of ‘target’ region
     33 |   !$omp target enter data map(alloc:B)
  Warning: ‘target enter data’ construct inside of ‘target’ region
     38 |   !$omp target exit data map(delete:B)
  Warning: ‘target exit data’ construct inside of ‘target’ region

I also generate one similar c code to check `target data` directive according to OpenMP API Examples Version 5.0.1 as follows:

  extern void init(float*, float*, int);
  extern void output(float*, int);
  void vec_mult(float *p, float *v1, float *v2, int N)
  {
    int i;
    init(v1, v2, N);
    #pragma omp target
    #pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p[0:N])
    {
      for (i=0; i<N; i++)
        p[i] = v1[i] * v2[i];
    }
    output(p, N);
  }

Tested using gcc 9.3.0 and current clang and the results are as follows:

  $ clang -fopenmp temp.c 
  temp.c:8:3: error: region cannot be nested inside 'target' region
    #pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p[0:N])
    ^
  1 error generated.
  $ gcc -fopenmp temp.c 
  temp.c: In function ‘vec_mult’:
  temp.c:8:11: warning: ‘target data’ construct inside of ‘target’ region
      8 |   #pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p[0:N])
        |           ^~~

Then I use the similar error info as clang to keep the consistence.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106165/new/

https://reviews.llvm.org/D106165

Files:
  flang/lib/Semantics/check-omp-structure.cpp
  flang/lib/Semantics/check-omp-structure.h
  flang/test/Semantics/omp-target01.f90

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106165.359515.patch
Type: text/x-patch
Size: 4418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210717/7e732a92/attachment.bin>


More information about the llvm-commits mailing list