[OPENMP50]Codegen for scan directives in parallel for regions.
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 9 Jun 2020 15:55:25 +0000 (11:55 -0400)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 18 Jun 2020 15:56:55 +0000 (11:56 -0400)
commit1ec469cf4c20a0f80ab6507e3838cfcc3e4f9595
treea46c8c513bea90ff52c0f6a97263b58f70a48907
parent3ed2909feb34e5b68c6272def7d445a7ca4c5c6f
[OPENMP50]Codegen for scan directives in parallel for regions.

Summary:
Added codegen for scan directives in parallel for regions.

Emits the code for the directive with inscan reductions.
Original code:
```
 #pragma omp parallel for reduction(inscan, op : ...)
 for() {
   <input phase>;
   #pragma omp scan (in)exclusive(...)
   <scan phase>
 }
```
is transformed to something:

```
 #pragma omp parallel
{
size num_iters = <num_iters>;
<type> buffer[num_iters];
 #pragma omp for
for (i: 0..<num_iters>) {
  <input phase>;
  buffer[i] = red;
}
 #pragma omp barrier
for (int k = 0; k != ceil(log2(num_iters)); ++k)
for (size cnt = last_iter; cnt >= pow(2, k); --k)
  buffer[i] op= buffer[i-pow(2,k)];
 #pragma omp for
for (0..<num_iters>) {
  red = InclusiveScan ? buffer[i] : buffer[i-1];
  <scan phase>;
}
}
```

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, sstefan1, cfe-commits, caomhin

Tags: #clang

Differential Revision: https://reviews.llvm.org/D81478
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/test/OpenMP/parallel_for_scan_codegen.cpp [new file with mode: 0644]