[flang-commits] [flang] 64f5a76 - [Flang][OpenMP] Disable function filtering for host

Andrew Gozillon via flang-commits flang-commits at lists.llvm.org
Tue Jul 18 13:18:47 PDT 2023


Author: Andrew Gozillon
Date: 2023-07-18T15:18:35-05:00
New Revision: 64f5a7642a05fc13f1931197c8a474d244179a83

URL: https://github.com/llvm/llvm-project/commit/64f5a7642a05fc13f1931197c8a474d244179a83
DIFF: https://github.com/llvm/llvm-project/commit/64f5a7642a05fc13f1931197c8a474d244179a83.diff

LOG: [Flang][OpenMP] Disable function filtering for host

This should be a temporary fix while we work
towards enabling function filtering for host
again via a future patch.

Added: 
    flang/test/Lower/OpenMP/function-filtering-2.f90

Modified: 
    flang/lib/Frontend/FrontendActions.cpp
    flang/test/Lower/OpenMP/function-filtering.f90
    mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
    mlir/test/Target/LLVMIR/openmp-llvm.mlir

Removed: 
    


################################################################################
diff  --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 7c44b463e01ddf..d1158cba4f59cb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -311,9 +311,14 @@ bool CodeGenAction::beginSourceFileAction() {
       isDevice = offloadMod.getIsTargetDevice();
 
     pm.addPass(fir::createOMPMarkDeclareTargetPass());
-    if (isDevice)
+    if (isDevice) {
       pm.addPass(fir::createOMPEarlyOutliningPass());
-    pm.addPass(fir::createOMPFunctionFilteringPass());
+      // FIXME: This should eventually be moved out of the
+      // if, so that it also functions for host, however,
+      // we must fix the filtering to function reasonably
+      // for host first.  
+      pm.addPass(fir::createOMPFunctionFilteringPass());
+    }
   }
 
   pm.enableVerifier(/*verifyPasses=*/true);

diff  --git a/flang/test/Lower/OpenMP/function-filtering-2.f90 b/flang/test/Lower/OpenMP/function-filtering-2.f90
new file mode 100644
index 00000000000000..dbad29bb7c1d76
--- /dev/null
+++ b/flang/test/Lower/OpenMP/function-filtering-2.f90
@@ -0,0 +1,38 @@
+! RUN: %flang_fc1 -fopenmp -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM-HOST %s
+! RUN: %flang_fc1 -fopenmp -emit-mlir %s -o - | FileCheck --check-prefix=MLIR-HOST %s
+! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM-DEVICE %s
+! RUN: %flang_fc1 -fopenmp -fopenmp-is-target-device -emit-mlir %s -o - | FileCheck --check-prefix=MLIR-DEVICE %s
+
+! MLIR-HOST: func.func @{{.*}}implicit_invocation(
+! MLIR-DEVICE: func.func @{{.*}}implicit_invocation() attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>}
+! LLVM-HOST: define {{.*}} @{{.*}}implicit_invocation{{.*}}(
+! LLVM-DEVICE: define {{.*}} @{{.*}}implicit_invocation{{.*}}(
+subroutine implicit_invocation()
+end subroutine implicit_invocation
+
+! MLIR-HOST: func.func @{{.*}}declaretarget(
+! MLIR-DEVICE: func.func @{{.*}}declaretarget() attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>}
+! LLVM-HOST: define {{.*}} @{{.*}}declaretarget{{.*}}(
+! LLVM-DEVICE: define {{.*}} @{{.*}}declaretarget{{.*}}(
+subroutine declaretarget()
+!$omp declare target to(declaretarget) device_type(nohost)
+    call implicit_invocation()
+end subroutine declaretarget
+
+! MLIR-HOST: func.func @{{.*}}no_declaretarget(
+! MLIR-DEVICE: func.func @{{.*}}no_declaretarget() attributes {omp.declare_target = #omp.declaretarget<device_type = (nohost), capture_clause = (to)>}
+! LLVM-HOST: define {{.*}} @{{.*}}no_declaretarget{{.*}}(
+! LLVM-DEVICE: define {{.*}} @{{.*}}no_declaretarget{{.*}}(
+subroutine no_declaretarget()
+end subroutine no_declaretarget
+
+! MLIR-HOST: func.func @{{.*}}main(
+! MLIR-DEVICE: func.func @{{.*}}main_omp_outline{{.*}}() attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>, omp.outline_parent_name = "_QQmain"} 
+! LLVM-HOST: define {{.*}} @{{.*}}main{{.*}}(
+! LLVM-DEVICE: define {{.*}} @{{.*}}__omp_offloading{{.*}}main_{{.*}}(
+program main
+!$omp target
+    call declaretarget()
+    call no_declaretarget()
+!$omp end target
+end program main

diff  --git a/flang/test/Lower/OpenMP/function-filtering.f90 b/flang/test/Lower/OpenMP/function-filtering.f90
index 4386cb43c144f6..117cef6677d321 100644
--- a/flang/test/Lower/OpenMP/function-filtering.f90
+++ b/flang/test/Lower/OpenMP/function-filtering.f90
@@ -7,9 +7,12 @@
 ! after running the whole set of translation and transformation passes from
 ! Fortran.
 
-! MLIR-HOST-NOT: func.func @{{.*}}device_fn(
+! DISABLED, this portion of the test is disabled via the removal of the colon for the time 
+! being as filtering is enabled for device only for the time being while a fix is in progress. 
+! MLIR-HOST-NOT func.func @{{.*}}device_fn(
+! LLVM-HOST-NOT define {{.*}} @{{.*}}device_fn{{.*}}(
+
 ! MLIR-DEVICE: func.func @{{.*}}device_fn(
-! LLVM-HOST-NOT: define {{.*}} @{{.*}}device_fn{{.*}}(
 ! LLVM-DEVICE: define {{.*}} @{{.*}}device_fn{{.*}}(
 function device_fn() result(x)
   !$omp declare target to(device_fn) device_type(nohost)

diff  --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index f20adefc29a74f..d2d302fbd9def1 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -1687,6 +1687,11 @@ convertDeclareTargetAttr(Operation *op,
     if (auto offloadMod = dyn_cast<omp::OffloadModuleInterface>(
             op->getParentOfType<ModuleOp>().getOperation())) {
       bool isDeviceCompilation = offloadMod.getIsTargetDevice();
+      // FIXME: Temporarily disabled for host as it causes some issues when
+      // lowering while removing functions at the current time.
+      if (!isDeviceCompilation)
+        return success();
+      
       omp::DeclareTargetDeviceType declareType =
           declareTargetAttr.getDeviceType().getValue();
 

diff  --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
index 15eb0b353a3e8b..6469868b8751ff 100644
--- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -2547,7 +2547,9 @@ module attributes {omp.flags = #omp.flags<assume_teams_oversubscription = true,
 // -----
 
 module attributes {omp.is_target_device = false} {
-  // CHECK-NOT: @filter_host_nohost
+  // DISABLED, this portion of the test is disabled via the removal of the colon for the time 
+  // being as filtering is enabled for device only for the time being while a fix is in progress. 
+  // CHECK-NOT @filter_host_nohost
   llvm.func @filter_host_nohost() -> ()
       attributes {
         omp.declare_target =


        


More information about the flang-commits mailing list