Skip to content

[flang][OpenMP] Enable delayed privatization for omp parallel by default #90945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

ergawy
Copy link
Member

@ergawy ergawy commented May 3, 2024

Flips the delayed privatization switch to be on by default. After the recent fixes related to delayed privatization, the gfortran test suite runs successfully with delayed privatization turned on by defuault for omp parallel.

@ergawy ergawy marked this pull request as draft May 3, 2024 07:33
@ergawy ergawy force-pushed the delayed_privatization_21 branch from 13edc47 to e2bd438 Compare May 7, 2024 12:37
@ergawy ergawy changed the title [WIP][flang][OpenMP] Enable delayed privatization by default [flang][OpenMP] Enable delayed privatization by default Jun 5, 2024
@ergawy ergawy changed the title [flang][OpenMP] Enable delayed privatization by default [flang][OpenMP] Enable delayed privatization for omp parallel by default Jun 9, 2024
@ergawy ergawy force-pushed the delayed_privatization_21 branch from ca83608 to 03e9921 Compare June 9, 2024 10:15
@ergawy ergawy force-pushed the delayed_privatization_21 branch from 03e9921 to 33c2f9c Compare June 10, 2024 05:44
@ergawy ergawy marked this pull request as ready for review June 10, 2024 05:44
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Jun 10, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-flang-openmp

Author: Kareem Ergawy (ergawy)

Changes

Flips the delayed privatization switch to be on by default. After the recent fixes related to delayed privatization, the gfortran test suite runs successfully with delayed privatization turned on by defuault for omp parallel.


Full diff: https://github.com/llvm/llvm-project/pull/90945.diff

15 Files Affected:

  • (modified) flang/lib/Lower/OpenMP/Utils.cpp (+1-1)
  • (modified) flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90 (+7-2)
  • (modified) flang/test/Lower/OpenMP/copyprivate.f90 (+3-1)
  • (modified) flang/test/Lower/OpenMP/default-clause-byref.f90 (+7-2)
  • (modified) flang/test/Lower/OpenMP/default-clause.f90 (+7-2)
  • (modified) flang/test/Lower/OpenMP/firstprivate-commonblock.f90 (+3-1)
  • (modified) flang/test/Lower/OpenMP/hlfir-seqloop-parallel.f90 (+7-2)
  • (modified) flang/test/Lower/OpenMP/implicit-dsa.f90 (+3-1)
  • (modified) flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90 (+2-1)
  • (modified) flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90 (+4-1)
  • (modified) flang/test/Lower/OpenMP/parallel-private-clause-str.f90 (+6-2)
  • (modified) flang/test/Lower/OpenMP/parallel-private-clause.f90 (+2-1)
  • (modified) flang/test/Lower/OpenMP/parallel-wsloop.f90 (+2-1)
  • (modified) flang/test/Lower/OpenMP/private-commonblock.f90 (+3-1)
  • (modified) flang/test/Lower/OpenMP/unstructured.f90 (+2-1)
diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 36d96f37ff36a..d4513311553cc 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -34,7 +34,7 @@ llvm::cl::opt<bool> enableDelayedPrivatization(
     "openmp-enable-delayed-privatization",
     llvm::cl::desc(
         "Emit `[first]private` variables as clauses on the MLIR ops."),
-    llvm::cl::init(false));
+    llvm::cl::init(true));
 
 llvm::cl::opt<bool> enableDelayedPrivatizationStaging(
     "openmp-enable-delayed-privatization-staging",
diff --git a/flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90 b/flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90
index 773452206993f..c59c10d1c7b76 100644
--- a/flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90
+++ b/flang/test/Lower/OpenMP/Todo/omp-default-clause-inner-loop.f90
@@ -1,7 +1,12 @@
 ! This test checks the lowering of parallel do
 
-! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | FileCheck %s
-! RUN: bbc -fopenmp -emit-fir -hlfir=false %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+! RUN: bbc -fopenmp -emit-fir -hlfir=false \
+! RUN:   --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
 
 ! The string "EXPECTED" denotes the expected FIR
 
diff --git a/flang/test/Lower/OpenMP/copyprivate.f90 b/flang/test/Lower/OpenMP/copyprivate.f90
index 9b76a996ef3e1..d1efb14de027f 100644
--- a/flang/test/Lower/OpenMP/copyprivate.f90
+++ b/flang/test/Lower/OpenMP/copyprivate.f90
@@ -1,5 +1,7 @@
 ! Test COPYPRIVATE.
-! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false -o - %s 2>&1 \
+! RUN: | FileCheck %s
 
 !CHECK-DAG: func private @_copy_i64(%{{.*}}: !fir.ref<i64>, %{{.*}}: !fir.ref<i64>)
 !CHECK-DAG: func private @_copy_f32(%{{.*}}: !fir.ref<f32>, %{{.*}}: !fir.ref<f32>)
diff --git a/flang/test/Lower/OpenMP/default-clause-byref.f90 b/flang/test/Lower/OpenMP/default-clause-byref.f90
index 7893c4d7d5732..b69142626ad95 100644
--- a/flang/test/Lower/OpenMP/default-clause-byref.f90
+++ b/flang/test/Lower/OpenMP/default-clause-byref.f90
@@ -1,8 +1,13 @@
 ! This test checks lowering of OpenMP parallel directive
 ! with `DEFAULT` clause present.
 
-! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --force-byref-reduction %s -o - | FileCheck %s
-! RUN: bbc -fopenmp -emit-hlfir --force-byref-reduction %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp -mmlir --force-byref-reduction \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+! RUN: bbc -fopenmp -emit-hlfir --force-byref-reduction \
+! RUN:   --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
 
 
 !CHECK: func @_QQmain() attributes {fir.bindc_name = "default_clause_lowering"} {
diff --git a/flang/test/Lower/OpenMP/default-clause.f90 b/flang/test/Lower/OpenMP/default-clause.f90
index 60a9c5efbb2a1..7a642e871198d 100644
--- a/flang/test/Lower/OpenMP/default-clause.f90
+++ b/flang/test/Lower/OpenMP/default-clause.f90
@@ -1,8 +1,13 @@
 ! This test checks lowering of OpenMP parallel directive
 ! with `DEFAULT` clause present.
 
-! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
-! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+! RUN: bbc -fopenmp -emit-hlfir \
+! RUN:   --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
 
 
 !CHECK: func @_QQmain() attributes {fir.bindc_name = "default_clause_lowering"} {
diff --git a/flang/test/Lower/OpenMP/firstprivate-commonblock.f90 b/flang/test/Lower/OpenMP/firstprivate-commonblock.f90
index d0fcdac76ad79..9b30492a91ba4 100644
--- a/flang/test/Lower/OpenMP/firstprivate-commonblock.f90
+++ b/flang/test/Lower/OpenMP/firstprivate-commonblock.f90
@@ -1,4 +1,6 @@
-! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false -o - %s 2>&1 \
+! RUN: | FileCheck %s
 
 !CHECK: func.func @_QPfirstprivate_common() {
 !CHECK: %[[val_0:.*]] = fir.address_of(@c_) : !fir.ref<!fir.array<8xi8>>
diff --git a/flang/test/Lower/OpenMP/hlfir-seqloop-parallel.f90 b/flang/test/Lower/OpenMP/hlfir-seqloop-parallel.f90
index 271b97819e606..084f2de6360a3 100644
--- a/flang/test/Lower/OpenMP/hlfir-seqloop-parallel.f90
+++ b/flang/test/Lower/OpenMP/hlfir-seqloop-parallel.f90
@@ -1,8 +1,13 @@
 ! This test checks lowering of sequential loops in OpenMP parallel.
 ! The loop indices of these loops should be privatised.
 
-! RUN: bbc -hlfir -fopenmp -emit-hlfir %s -o - | FileCheck %s
-! RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -fopenmp %s -o - | FileCheck %s
+! RUN: bbc -fopenmp -emit-hlfir \
+! RUN:   --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+! RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
 
 
 subroutine sb1
diff --git a/flang/test/Lower/OpenMP/implicit-dsa.f90 b/flang/test/Lower/OpenMP/implicit-dsa.f90
index 0f67d5bfd194f..e9472f1351e75 100644
--- a/flang/test/Lower/OpenMP/implicit-dsa.f90
+++ b/flang/test/Lower/OpenMP/implicit-dsa.f90
@@ -1,4 +1,6 @@
-!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false -o - %s 2>&1 \
+! RUN: | FileCheck %s
 
 ! Checks lowering of OpenMP variables with implicitly determined DSAs.
 
diff --git a/flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90 b/flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90
index 93dcd4b74b004..50c36bdccbd5a 100644
--- a/flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90
+++ b/flang/test/Lower/OpenMP/parallel-firstprivate-clause-scalar.f90
@@ -1,7 +1,8 @@
 ! This test checks lowering of `FIRSTPRIVATE` clause for scalar types.
 
 ! REQUIRES: shell
-! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s --check-prefix=CHECK
+! RUN: bbc -fopenmp -emit-hlfir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s --check-prefix=CHECK
 
 !CHECK-DAG: func @_QPfirstprivate_complex(%[[ARG1:.*]]: !fir.ref<!fir.complex<4>>{{.*}}, %[[ARG2:.*]]: !fir.ref<!fir.complex<8>>{{.*}}) {
 !CHECK:    %[[ARG1_DECL:.*]]:2 = hlfir.declare %[[ARG1]] dummy_scope %{{[0-9]+}} {uniq_name = "_QFfirstprivate_complexEarg1"} : (!fir.ref<!fir.complex<4>>, !fir.dscope) -> (!fir.ref<!fir.complex<4>>, !fir.ref<!fir.complex<4>>)
diff --git a/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90 b/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
index 19c7b78298eab..eb32201512a5f 100644
--- a/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
+++ b/flang/test/Lower/OpenMP/parallel-private-clause-fixes.f90
@@ -1,6 +1,9 @@
 ! This test checks a few bug fixes in the PRIVATE clause lowering
 
-! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
+! RUN: bbc -fopenmp -emit-hlfir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+
 
 ! CHECK-LABEL: multiple_private_fix
 ! CHECK-SAME:  %[[GAMA:.*]]: !fir.ref<i32> {fir.bindc_name = "gama"}
diff --git a/flang/test/Lower/OpenMP/parallel-private-clause-str.f90 b/flang/test/Lower/OpenMP/parallel-private-clause-str.f90
index 19ea37c5339b5..840f898e5dd67 100644
--- a/flang/test/Lower/OpenMP/parallel-private-clause-str.f90
+++ b/flang/test/Lower/OpenMP/parallel-private-clause-str.f90
@@ -2,8 +2,12 @@
 ! `PRIVATE` clause present for strings
 
 ! REQUIRES: shell
-! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
-!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+! RUN: bbc -fopenmp -emit-hlfir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
+
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false -o - %s 2>&1 \
+! RUN: | FileCheck %s
 
 !CHECK:  func.func @_QPtest_allocatable_string(%{{.*}}: !fir.ref<i32> {fir.bindc_name = "n"}) {
 !CHECK:    %[[C_BOX_REF:.*]] = fir.alloca !fir.box<!fir.heap<!fir.char<1,?>>> {bindc_name = "c", uniq_name = "_QFtest_allocatable_stringEc"}
diff --git a/flang/test/Lower/OpenMP/parallel-private-clause.f90 b/flang/test/Lower/OpenMP/parallel-private-clause.f90
index 7f5bc2565e679..b2c38f22caf75 100644
--- a/flang/test/Lower/OpenMP/parallel-private-clause.f90
+++ b/flang/test/Lower/OpenMP/parallel-private-clause.f90
@@ -2,7 +2,8 @@
 ! `PRIVATE` clause present.
 
 ! REQUIRES: shell
-! RUN: bbc --use-desc-for-alloc=false -fopenmp -emit-hlfir %s -o - | \
+! RUN: bbc --use-desc-for-alloc=false -fopenmp -emit-hlfir \
+! RUN:   --openmp-enable-delayed-privatization=false %s -o - | \
 ! RUN:   FileCheck %s --check-prefix=FIRDialect
 
 !FIRDialect: func @_QPprivate_clause(%[[ARG1:.*]]: !fir.ref<i32> {fir.bindc_name = "arg1"}, %[[ARG2:.*]]: !fir.ref<!fir.array<10xi32>> {fir.bindc_name = "arg2"}, %[[ARG3:.*]]: !fir.boxchar<1> {fir.bindc_name = "arg3"}, %[[ARG4:.*]]: !fir.boxchar<1> {fir.bindc_name = "arg4"}) {
diff --git a/flang/test/Lower/OpenMP/parallel-wsloop.f90 b/flang/test/Lower/OpenMP/parallel-wsloop.f90
index e5c303d7bb2ed..0288d6d6fa73e 100644
--- a/flang/test/Lower/OpenMP/parallel-wsloop.f90
+++ b/flang/test/Lower/OpenMP/parallel-wsloop.f90
@@ -1,6 +1,7 @@
 ! This test checks lowering of OpenMP DO Directive (Worksharing).
 
-! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
+! RUN: bbc -fopenmp -emit-hlfir --openmp-enable-delayed-privatization=false %s -o - \
+! RUN: | FileCheck %s
 
 ! CHECK-LABEL: func @_QPsimple_parallel_do()
 subroutine simple_parallel_do
diff --git a/flang/test/Lower/OpenMP/private-commonblock.f90 b/flang/test/Lower/OpenMP/private-commonblock.f90
index ee580594f7c3f..b8f459bac201e 100644
--- a/flang/test/Lower/OpenMP/private-commonblock.f90
+++ b/flang/test/Lower/OpenMP/private-commonblock.f90
@@ -1,4 +1,6 @@
-! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -fopenmp \
+! RUN:   -mmlir --openmp-enable-delayed-privatization=false -o - %s 2>&1 \
+! RUN: | FileCheck %s
 
 !CHECK: func.func @_QPprivate_common() {
 !CHECK: omp.parallel {
diff --git a/flang/test/Lower/OpenMP/unstructured.f90 b/flang/test/Lower/OpenMP/unstructured.f90
index b36e4f37a7458..1c33d32a31e62 100644
--- a/flang/test/Lower/OpenMP/unstructured.f90
+++ b/flang/test/Lower/OpenMP/unstructured.f90
@@ -1,6 +1,7 @@
 ! Test unstructured code adjacent to and inside OpenMP constructs.
 
-! RUN: bbc %s -fopenmp -emit-hlfir -o "-" | FileCheck %s
+! RUN: bbc %s -fopenmp -emit-hlfir --openmp-enable-delayed-privatization=false -o "-" \
+! RUN: | FileCheck %s
 
 ! CHECK-LABEL: func @_QPss1{{.*}} {
 ! CHECK:   br ^bb1

@kiranchandramohan
Copy link
Contributor

@luporl Is it possible to do a quick run with the Fujitsu test?

@luporl
Copy link
Contributor

luporl commented Jun 10, 2024

@luporl Is it possible to do a quick run with the Fujitsu test?

I have not been running Fujitsu testsuite as a whole, but I can give it a try.
However, I don't think it will be quick to compile and run all tests. And I would need to run the testsuite twice: without this patch, to get a list of the failing tests, and then with the patch, to check if new failures occur.

@ergawy
Copy link
Member Author

ergawy commented Jun 11, 2024

@luporl Is it possible to do a quick run with the Fujitsu test?

I have not been running Fujitsu testsuite as a whole, but I can give it a try. However, I don't think it will be quick to compile and run all tests. And I would need to run the testsuite twice: without this patch, to get a list of the failing tests, and then with the patch, to check if new failures occur.

@kiranchandramohan @luporl if the test suite you guys are refering to is the same as this: https://github.com/fujitsu/compiler-test-suite, I can give it a try on my side. Or is it something that is not open source?

@luporl
Copy link
Contributor

luporl commented Jun 11, 2024

@luporl Is it possible to do a quick run with the Fujitsu test?

I have not been running Fujitsu testsuite as a whole, but I can give it a try. However, I don't think it will be quick to compile and run all tests. And I would need to run the testsuite twice: without this patch, to get a list of the failing tests, and then with the patch, to check if new failures occur.

@kiranchandramohan @luporl if the test suite you guys are refering to is the same as this: https://github.com/fujitsu/compiler-test-suite, I can give it a try on my side. Or is it something that is not open source?

It is that test suite indeed. Not every Fortran test was added to https://github.com/fujitsu/compiler-test-suite yet, but not breaking any new test from the already published ones should be enough.

I'm having some trouble running it. For some reason cmake is not detecting the test cases. I'll try to investigate it, but maybe you have better luck with it.

@luporl
Copy link
Contributor

luporl commented Jun 11, 2024

I'm having some trouble running it. For some reason cmake is not detecting the test cases. I'll try to investigate it, but maybe you have better luck with it.

-DTEST_SUITE_FUJITSU_FORCE_UNSUPPORTED_PLATFORM=ON was needed.

After that I got several CMake cannot determine linker language for target errors, because CMake doesn't recognize .f03 and .f08 as Fortran sources (.f and .f90 works though).
I worked around that with:

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,7 @@ function(llvm_set_own_fortran_module_directory)
   get_directory_property(targets BUILDSYSTEM_TARGETS)
   foreach(target ${targets})
     set_target_properties(${target} PROPERTIES Fortran_MODULE_DIRECTORY "${target}.d")
+    set_target_properties(${target} PROPERTIES LINKER_LANGUAGE Fortran)
   endforeach()
 endfunction()

With that it was possible to build the tests, that are now running.

@luporl
Copy link
Contributor

luporl commented Jun 11, 2024

Lower/OpenMP/critical.f90 is failing on my machine.
It seems the CI haven't caught it because it is marked as unsupported, which means it's probably skipping tests that require OpenMP runtime.

@luporl
Copy link
Contributor

luporl commented Jun 11, 2024

Fujitsu testsuite results:

Before:

Total Discovered Tests: 32226
  Passed            : 30911 (95.92%)
  Failed            :  1112 (3.45%)
  Executable Missing:   203 (0.63%)

After:

Total Discovered Tests: 32226
  Passed            : 30913 (95.93%)
  Failed            :  1072 (3.33%)
  Executable Missing:   241 (0.75%)

2 tests now pass:

test-suite :: Fujitsu/Fortran/0134/Fujitsu-Fortran-0134_0199.test
test-suite :: Fujitsu/Fortran/0292/Fujitsu-Fortran-0292_0009.test

But several failures became "executable missing", which means the compilation failed.
With the patch applied, after the build stage I see a bunch of core files.
It would be nice to take a look at these crashes.

This is one of them:

FAILED: Fujitsu/Fortran/0007/CMakeFiles/Fujitsu-Fortran-0007_0019.dir/0007_0019.f90.o Fujitsu/Fortran/0007/Fujitsu-Fortran-0007_0019.d/m0.mod Fujitsu/Fortran/0007/Fujitsu-Fortran-0007_0019.d/m1.mod
/home/leandro.lupori/git/flang-luporl/install/bin/flang-new -I/home/leandro.lupori/git/llvm-test-suite/Fujitsu/Fortran/0007 -module-dirFujitsu/Fortran/0007/Fujitsu-Fortran-0007_0019.d -fopenmp -c Fujitsu/Fortran/0007/CMakeFiles/Fujitsu-
Fortran-0007_0019.dir/0007_0019.f90-pp.f90 -o Fujitsu/Fortran/0007/CMakeFiles/Fujitsu-Fortran-0007_0019.dir/0007_0019.f90.o
flang-new: /home/leandro.lupori/git/flang-luporl/llvm-project/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp:1789: Operation *parentLLVMModule(Operation *): Assertion `module && "unexpected operation outside of a module"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/leandro.lupori/git/flang-luporl/install/bin/flang-new -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -I /home/leandro.lupori/git/llvm-test-suite/Fujitsu/Fortran/0007 -mrelocation-model pic -pic-level 2
 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature +neon -module-dir Fujitsu/Fortran/0007/Fujitsu-Fortran-0007_0019.d -fopenmp -resource-dir /home/leandro.lup
ori/git/flang-luporl/install/bin/.. -mframe-pointer=non-leaf -o Fujitsu/Fortran/0007/CMakeFiles/Fujitsu-Fortran-0007_0019.dir/0007_0019.f90.o -x f95-cpp-input Fujitsu/Fortran/0007/CMakeFiles/Fujitsu-Fortran-0007_0019.dir/0007_0019.f90-p
p.f90
 #0 0x0000aaaad364ba68 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e57a68)
 #1 0x0000aaaad36498b4 llvm::sys::RunSignalHandlers() (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e558b4)
 #2 0x0000aaaad364c460 SignalHandler(int) Signals.cpp:0:0
 #3 0x0000ffffbb7bf5c0 (linux-vdso.so.1+0x5c0)
 #4 0x0000ffffbb2df200 __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x0000ffffbb29a67c gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x0000ffffbb287130 abort ./stdlib/abort.c:81:7
 #7 0x0000ffffbb293fd0 __assert_fail_base ./assert/assert.c:89:7
 #8 0x0000ffffbb294040 __assert_perror_fail ./assert/assert-perr.c:31:1
 #9 0x0000aaaad5ae0910 parentLLVMModule(mlir::Operation*) LLVMDialect.cpp:0:0
#10 0x0000aaaad5ae084c mlir::LLVM::AddressOfOp::getGlobal(mlir::SymbolTableCollection&) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x52ec84c)
#11 0x0000aaaad55d2260 convertOperationImpl(mlir::Operation&, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) LLVMToLLVMIRTranslation.cpp:0:0
#12 0x0000aaaad583b580 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5047580)
#13 0x0000aaaad583c098 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5048098)
#14 0x0000aaaad50bc274 inlineConvertOmpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, llvm::SmallVectorImpl<llvm::Value*>*) OpenMPToLLVMIRTranslation.cpp:0:0
#15 0x0000aaaad50bfe8c llvm::IRBuilderBase::InsertPoint llvm::function_ref<llvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value&, llvm::Value*&)>::callback_fn<co
nvertOmpParallel(mlir::omp::ParallelOp, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_2>(long, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value&, llvm::Value*&) OpenMPToLLVMIRTrans
lation.cpp:0:0
#16 0x0000aaaad6c23ba0 llvm::OpenMPIRBuilder::createParallel(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoin
t)>, llvm::function_ref<llvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value&, llvm::Value*&)>, std::function<void (llvm::IRBuilderBase::InsertPoint)>, llvm::Val
ue*, llvm::Value*, llvm::omp::ProcBindKind, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x642fba0)
#17 0x0000aaaad50af298 convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#18 0x0000aaaad583b580 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5047580)
#19 0x0000aaaad583c098 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5048098)
#20 0x0000aaaad50ba794 convertOmpOpRegions(mlir::Region&, llvm::StringRef, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&, mlir::LogicalResult&, llvm::SmallVectorImpl<llvm::PHINode*>*) OpenMPToLLVMIRTranslation.cpp:0:0
#21 0x0000aaaad50be1d0 void llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint)>::callback_fn<convertOmpParallel(mlir::omp::ParallelOp, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&)::$_1>
(long, llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint) OpenMPToLLVMIRTranslation.cpp:0:0
#22 0x0000aaaad6c230b8 llvm::OpenMPIRBuilder::createParallel(llvm::OpenMPIRBuilder::LocationDescription const&, llvm::IRBuilderBase::InsertPoint, llvm::function_ref<void (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoin
t)>, llvm::function_ref<llvm::IRBuilderBase::InsertPoint (llvm::IRBuilderBase::InsertPoint, llvm::IRBuilderBase::InsertPoint, llvm::Value&, llvm::Value&, llvm::Value*&)>, std::function<void (llvm::IRBuilderBase::InsertPoint)>, llvm::Val
ue*, llvm::Value*, llvm::omp::ProcBindKind, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x642f0b8)
#23 0x0000aaaad50af298 convertHostOrTargetOperation(mlir::Operation*, llvm::IRBuilderBase&, mlir::LLVM::ModuleTranslation&) OpenMPToLLVMIRTranslation.cpp:0:0
#24 0x0000aaaad583b580 mlir::LLVM::ModuleTranslation::convertOperation(mlir::Operation&, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5047580)
#25 0x0000aaaad583c098 mlir::LLVM::ModuleTranslation::convertBlockImpl(mlir::Block&, bool, llvm::IRBuilderBase&, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x5048098)
#26 0x0000aaaad583f1c0 mlir::LLVM::ModuleTranslation::convertOneFunction(mlir::LLVM::LLVMFuncOp) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x504b1c0)
#27 0x0000aaaad5841038 mlir::LLVM::ModuleTranslation::convertFunctions() (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x504d038)
#28 0x0000aaaad584304c mlir::translateModuleToLLVMIR(mlir::Operation*, llvm::LLVMContext&, llvm::StringRef, bool) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x504f04c)
#29 0x0000aaaad3683c60 Fortran::frontend::CodeGenAction::generateLLVMIR() (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e8fc60)
#30 0x0000aaaad36867f4 Fortran::frontend::CodeGenAction::executeAction() (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e927f4)
#31 0x0000aaaad3678244 Fortran::frontend::FrontendAction::execute() (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e84244)
#32 0x0000aaaad36637f4 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e6f7f4)
#33 0x0000aaaad367bff4 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2e87ff4)
#34 0x0000aaaad32bb42c fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2ac742c)
#35 0x0000aaaad32b9cb8 main (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2ac5cb8)
#36 0x0000ffffbb2873fc __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#37 0x0000ffffbb2874cc call_init ./csu/../csu/libc-start.c:128:20
#38 0x0000ffffbb2874cc __libc_start_main ./csu/../csu/libc-start.c:379:5
#39 0x0000aaaad32b9770 _start (/home/leandro.lupori/git/flang-luporl/install/bin/flang-new+0x2ac5770)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git ([email protected]:luporl/llvm-project.git 33c2f9ce4fd76dc48ed8b934be51badb075b6e57)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/leandro.lupori/git/flang-luporl/install/bin
Build config: +assertions
flang-new: note: diagnostic msg:

@luporl
Copy link
Contributor

luporl commented Jun 11, 2024

I'm also seeing 2 failures on gfortran testsuite (tested on AArch64):

Failed Tests (2):
  test-suite :: Fortran/gfortran/regression/gomp/appendix-a/gfortran-regression-compile-regression__gomp__appendix-a__a_23_1_f90.test
  test-suite :: Fortran/gfortran/regression/gomp/appendix-a/gfortran-regression-compile-regression__gomp__appendix-a__a_23_3_f90.test

@ergawy
Copy link
Member Author

ergawy commented Jun 12, 2024

Thanks a lot @luporl for the testing.

Lower/OpenMP/critical.f90 is failing on my machine. It seems the CI haven't caught it because it is marked as unsupported, which means it's probably skipping tests that require OpenMP runtime.

I think some changes in main lately broke that test. I have an updated version locally that runs successfully. I will commit this and other updates to expectations in other tests later today.

@ergawy
Copy link
Member Author

ergawy commented Jun 12, 2024

But several failures became "executable missing", which means the compilation failed. With the patch applied, after the build stage I see a bunch of core files. It would be nice to take a look at these crashes.

I will take a look 👀 ...

@ergawy
Copy link
Member Author

ergawy commented Jun 12, 2024

I'm also seeing 2 failures on gfortran testsuite (tested on AArch64):

Failed Tests (2):
  test-suite :: Fortran/gfortran/regression/gomp/appendix-a/gfortran-regression-compile-regression__gomp__appendix-a__a_23_1_f90.test
  test-suite :: Fortran/gfortran/regression/gomp/appendix-a/gfortran-regression-compile-regression__gomp__appendix-a__a_23_3_f90.test

I think these were intermittently broken indeed. But merging with the latest main seems to fix them:

Total Discovered Tests: 6199
  Passed: 6199 (100.00%)

@kiranchandramohan
Copy link
Contributor

Thanks @luporl for running the suite and the results.

But several failures became "executable missing", which means the compilation failed. With the patch applied, after the build stage I see a bunch of core files. It would be nice to take a look at these crashes.

I will take a look 👀 ...

Are these issues fixed by #92430?

@ergawy
Copy link
Member Author

ergawy commented Jun 12, 2024

Are these issues fixed by #92430?

Unfortunately not. So far I found 3 issues from Fujitsu tests.

Cloning omp.private without a parent module

This is what causes the sample test Leandro mentioned above. A fix for this would be:

@@ -1275,7 +1275,11 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
           // region. The privatizer is processed in-place (see below) before it
           // gets inlined in the parallel region and therefore processing the
           // original op is dangerous.
-          return {privVar, privatizer.clone()};
+
+          mlir::IRRewriter opCloner(&moduleTranslation.getContext());
+          opCloner.setInsertionPoint(privatizer);
+          return {privVar, llvm::cast<mlir::omp::PrivateClauseOp>(
+                               opCloner.clone(*privatizer))};

Properly mapping common blocks

This resulted in yet another test failing. This would be fixed by something like:

diff --git a/flang/lib/Lower/OpenMP/OpenMP.cpp b/flang/lib/Lower/OpenMP/OpenMP.cpp
index 6b391e11beb4..41806f045f82 100644
--- a/flang/lib/Lower/OpenMP/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP/OpenMP.cpp
@@ -1406,12 +1406,23 @@ genParallelOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
                       dsp.getAllSymbolsToPrivatize().end());
 
     for (auto [arg, prv] : llvm::zip_equal(allSymbols, region.getArguments())) {
-      converter.bindSymbol(*arg, hlfir::translateToExtendedValue(
-                                     loc, firOpBuilder, hlfir::Entity{prv},
-                                     /*contiguousHint=*/
-                                     evaluate::IsSimplyContiguous(
-                                         *arg, converter.getFoldingContext()))
-                                     .first);
+      mlir::BlockArgument blockArg = prv;
+      auto bind = [&](const semantics::Symbol *sym) {
+        converter.bindSymbol(*sym,
+                             hlfir::translateToExtendedValue(
+                                 loc, firOpBuilder, hlfir::Entity{blockArg},
+                                 /*contiguousHint=*/
+                                 evaluate::IsSimplyContiguous(
+                                     *sym, converter.getFoldingContext()))
+                                 .first);
+      };
+
+      if (const auto *commonDet =
+              arg->detailsIf<semantics::CommonBlockDetails>()) {
+        for (const auto &mem : commonDet->objects())
+          bind(&*mem);
+      } else
+        bind(arg);
     }

Properly handling common block when some of their items have equivalence with other variables

For example, input like this:

subroutine private_common
  common /c/ x
  real x, y
  equivalence (x,y)
  !$omp parallel firstprivate(/c/)
    !x = 3.14
    !y = 2.71
  !$omp end parallel
end subroutine

Currently produces omp.private ops that fail verficiation because the yielded type is not consistent with the symbol type:

  omp.private {type = firstprivate} @_QFprivate_commonEx_firstprivate_ptr_f32 : !fir.ptr<f32> alloc {
  ^bb0(%arg0: !fir.ptr<f32>):
    %0 = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFprivate_commonEx"}
    %1:2 = hlfir.declare %0 {uniq_name = "_QFprivate_commonEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
    omp.yield(%1#0 : !fir.ref<f32>)
  } copy {
  ^bb0(%arg0: !fir.ptr<f32>, %arg1: !fir.ref<f32>):
    %0 = fir.load %arg0 : !fir.ptr<f32>
    hlfir.assign %0 to %arg1 temporary_lhs : f32, !fir.ref<f32>
    omp.yield(%arg1 : !fir.ref<f32>)
  }

Still working on a proper fix for this.

@ergawy
Copy link
Member Author

ergawy commented Jun 19, 2024

Sorry for the delay here. I am working through the Fujistu failures but also busy with a few AMD-specific work items downstream. I opened: #96024 to handle one of the uncovered issues.

@ergawy ergawy force-pushed the delayed_privatization_21 branch from 33c2f9c to 3c23d1f Compare July 19, 2024 04:18
@ergawy ergawy marked this pull request as draft July 19, 2024 05:12
@ergawy ergawy force-pushed the delayed_privatization_21 branch 6 times, most recently from fb85891 to d9fd566 Compare July 25, 2024 05:10
@ergawy
Copy link
Member Author

ergawy commented Jul 25, 2024

Properly handling common block when some of their items have equivalence with other variables

This is now handled in #100531. Still have to verify it using Fujitsu tests.

@ergawy ergawy force-pushed the delayed_privatization_21 branch 4 times, most recently from 4d037f0 to f27e10e Compare August 1, 2024 12:07
@ergawy ergawy marked this pull request as ready for review August 1, 2024 12:09
@ergawy ergawy requested a review from tblah August 1, 2024 12:10
@ergawy
Copy link
Member Author

ergawy commented Aug 1, 2024

With the recently merged delayed privatization PRs, I now get the same results for both the gfortan and Fujitsu test suites with and without delayed privatization.

Also, in this PR, I updated all omp parallel tests to use delayed privatization by default and updated the test checks accordingly.

It would be great if someone else can also run gfortran and/or Fujitsu test suites to double check my results.

@tblah
Copy link
Contributor

tblah commented Aug 1, 2024

the gfortran testsuite and our internal tests all pass for me 🚀

@luporl
Copy link
Contributor

luporl commented Aug 1, 2024

I ran Fujitsu testsuite with and without this PR applied and the results were the same:

Total Discovered Tests: 32205
  Passed            : 31058 (96.44%)
  Failed            :  1092 (3.39%)
  Executable Missing:    55 (0.17%)

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG. Great work @ergawy.

@ergawy
Copy link
Member Author

ergawy commented Aug 2, 2024

Awesome, thanks for the approval and verification folks.

…fault

Flips the delayed privatization switch to be on by default. After the recent fixes related to delayed privatization, the gfortran test suite runs successfully with delayed privatization turned on by defuault for `omp parallel`.
@ergawy ergawy force-pushed the delayed_privatization_21 branch from f27e10e to 6b6c8ae Compare August 2, 2024 04:00
@ergawy ergawy merged commit 10df320 into llvm:main Aug 2, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants