[PATCH] [OPENMP] Codegen for 'reduction' clause in 'parallel' directive.

Alexey Bataev a.bataev at hotmail.com
Thu Apr 9 05:23:46 PDT 2015


Hi rjmccall, hfinkel, fraggamuffin, ejstotzer,

Emit a code for reduction clause. Next code should be emitted for reductions:
```
static kmp_critical_name lock = { 0 };

void reduce_func(void *lhs[<n>], void *rhs[<n>]) {
  *(Type0*)lhs[0] = ReductionOperation0(*(Type0*)lhs[0], *(Type0*)rhs[0]);
  ...
  *(Type<n>-1*)lhs[<n>-1] =
  ReductionOperation<n>-1(*(Type<n>-1*)lhs[<n>-1],
  *(Type<n>-1*)rhs[<n>-1]);
}

 ...
 void *RedList[<n>] = {&<RHSExprs>[0], ..., &<RHSExprs>[<n>-1]};
 switch (__kmpc_reduce{_nowait}(<loc>, <gtid>, <n>, sizeof(RedList), RedList, reduce_func, &<lock>)) {
 case 1:
  <LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]);
  ...
  <LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]);
 __kmpc_end_reduce{_nowait}(<loc>, <gtid>, &<lock>);
 break;
 case 2:
  Atomic(<LHSExprs>[0] = ReductionOperation0(*<LHSExprs>[0], *<RHSExprs>[0]));
  ...
  Atomic(<LHSExprs>[<n>-1] = ReductionOperation<n>-1(*<LHSExprs>[<n>-1], *<RHSExprs>[<n>-1]));
 break;
 default:;
 }
```
Reduction variables are a kind of a private variables, they have private copies, but initial values are chosen in accordance with the reduction operation.

http://reviews.llvm.org/D8915

Files:
  include/clang/AST/DataRecursiveASTVisitor.h
  include/clang/AST/OpenMPClause.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Stmt.cpp
  lib/AST/StmtProfile.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp
  test/OpenMP/for_reduction_messages.cpp
  test/OpenMP/for_simd_reduction_messages.cpp
  test/OpenMP/parallel_codegen.cpp
  test/OpenMP/parallel_for_reduction_messages.cpp
  test/OpenMP/parallel_for_simd_reduction_messages.cpp
  test/OpenMP/parallel_reduction_codegen.cpp
  test/OpenMP/parallel_reduction_messages.cpp
  test/OpenMP/parallel_sections_reduction_messages.cpp
  test/OpenMP/sections_codegen.cpp
  test/OpenMP/sections_reduction_messages.cpp
  test/OpenMP/simd_reduction_messages.cpp
  test/OpenMP/teams_reduction_messages.cpp
  tools/libclang/CIndex.cpp

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8915.23478.patch
Type: text/x-patch
Size: 180223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150409/cce0332f/attachment.bin>


More information about the cfe-commits mailing list