]> granicus.if.org Git - clang/commit
[OPENMP] Codegen for 'reduction' clause in 'for' directive.
authorAlexey Bataev <a.bataev@hotmail.com>
Wed, 22 Apr 2015 13:43:03 +0000 (13:43 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Wed, 22 Apr 2015 13:43:03 +0000 (13:43 +0000)
commit7d7afee099fd15feb3d63b3caea80f81fe6730bc
tree8619d079fb21d73253f8b9b9cd433c395cdd76a6
parent45360e9df6137cf8a6f0e8b1504552b4c357d7c3
[OPENMP] Codegen for 'reduction' clause in 'for' directive.

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.
Differential Revision: http://reviews.llvm.org/D9139

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@235506 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGStmtOpenMP.cpp
test/OpenMP/for_reduction_codegen.cpp [new file with mode: 0644]