[clang] [OpenMP 6.0 ]Codegen for Reduction over private variables with reduction clause (PR #134709)

CHANDRA GHALE via cfe-commits cfe-commits at lists.llvm.org
Wed May 7 09:53:52 PDT 2025


================
@@ -0,0 +1,538 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --include-generated-funcs --prefix-filecheck-ir-name _ --version 5
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fopenmp -fopenmp-version=60 -x c++ -std=c++17  -emit-llvm %s -o - | FileCheck %s
+// expected-no-diagnostics
+#define N 10
+class Sum {
+  int val;
+public:
+  Sum(int v = 0) : val(v) {}
+  Sum operator+(const Sum& rhs) const {
+    return Sum(val + rhs.val);
+  }
+  Sum& operator+=(const Sum& rhs) {
+    val += rhs.val;
+    return *this;
+  }
+};
+#pragma omp declare reduction(sum_reduction : Sum : omp_out += omp_in) initializer(omp_priv = Sum(0))
+
+void func_red(){
+  Sum result(0);
+  Sum array[N];
+
+  for (int i = 0; i < N; i++) {
+    array[i] = Sum(i);
+  }
+
+  #pragma omp parallel private(result)  num_threads(4)
+  {
+  #pragma omp  for reduction(sum_reduction:result)
+  for (int i = 0; i < N; i++) {
+    result = result + array[i];
+  }
+  }
+}
+
+void do_red(int n, int *v, int &sum_v)
+ {
+         sum_v = 0;
+        #pragma omp for reduction(original(private),+: sum_v)
----------------
chandraghale wrote:

Updated !!


https://github.com/llvm/llvm-project/pull/134709


More information about the cfe-commits mailing list