Add parsing, sema analysis and serialization/deserialization for 'declare reduction' construct. User-defined reductions are defined as #pragma omp declare reduction( reduction-identifier : typename-list : combiner ) [initializer ( initializer-expr )] These custom reductions may be used in 'reduction' clauses of OpenMP constructs. The combiner specifies how partial results can be combined into a single value. The combiner can use the special variable identifiers omp_in and omp_out that are of the type of the variables being reduced with this reduction-identifier. Each of them will denote one of the values to be combined before executing the combiner. It is assumed that the special omp_out identifier will refer to the storage that holds the resulting combined value after executing the combiner. As the initializer-expr value of a user-defined reduction is not known a priori the initializer-clause can be used to specify one. Then the contents of the initializer-clause will be used as the initializer for private copies of reduction list items where the omp_priv identifier will refer to the storage to be initialized. The special identifier omp_orig can also appear in the initializer-clause and it will refer to the storage of the original variable to be reduced. Differential Revision: http://reviews.llvm.org/D11182 llvm-svn: 262582
43 lines
1.7 KiB
C
43 lines
1.7 KiB
C
// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
|
|
// RUN: %clang_cc1 -fopenmp -emit-pch -o %t %s
|
|
// RUN: %clang_cc1 -fopenmp -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
|
|
// expected-no-diagnostics
|
|
|
|
#ifndef HEADER
|
|
#define HEADER
|
|
|
|
#pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
|
|
// CHECK: #pragma omp declare reduction (+ : int : omp_out *= omp_in)
|
|
// CHECK-NEXT: #pragma omp declare reduction (+ : char : omp_out *= omp_in)
|
|
|
|
#pragma omp declare reduction(fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15)
|
|
// CHECK: #pragma omp declare reduction (fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15)
|
|
|
|
// CHECK: struct SSS {
|
|
struct SSS {
|
|
int field;
|
|
#pragma omp declare reduction(+ : int, char : omp_out *= omp_in)
|
|
// CHECK: #pragma omp declare reduction (+ : int : omp_out *= omp_in)
|
|
// CHECK-NEXT: #pragma omp declare reduction (+ : char : omp_out *= omp_in)
|
|
};
|
|
// CHECK: };
|
|
|
|
void init(struct SSS *priv, struct SSS orig);
|
|
|
|
#pragma omp declare reduction(fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
// CHECK: #pragma omp declare reduction (fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
|
|
// CHECK: int main() {
|
|
int main() {
|
|
#pragma omp declare reduction(fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
// CHECK: #pragma omp declare reduction (fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
{
|
|
#pragma omp declare reduction(fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
// CHECK: #pragma omp declare reduction (fun : struct SSS : omp_out = omp_in) initializer(init(&omp_priv, omp_orig))
|
|
}
|
|
return 0;
|
|
}
|
|
// CHECK: }
|
|
|
|
#endif
|