diff --git a/flang/test/Fir/omp-declare-target-data.fir b/flang/test/Fir/omp-declare-target-data.fir index 295f8e1985228..a4935a3075314 100644 --- a/flang/test/Fir/omp-declare-target-data.fir +++ b/flang/test/Fir/omp-declare-target-data.fir @@ -1,6 +1,6 @@ // RUN: fir-opt --fir-to-llvm-ir %s | FileCheck %s -module attributes {omp.is_device = #omp.isdevice} { +module attributes {omp.is_device = false} { // CHECK: llvm.mlir.global external @_QMtest_0Earray_1d(dense<[1, 2, 3]> : tensor<3xi32>) {{{.*}}omp.declare_target = #omp.declaretarget{{.*}}} : !llvm.array<3 x i32> fir.global @_QMtest_0Earray_1d(dense<[1, 2, 3]> : tensor<3xi32>) {omp.declare_target = #omp.declaretarget} : !fir.array<3xi32> diff --git a/flang/test/Lower/OpenMP/omp-host-ir-flag.f90 b/flang/test/Lower/OpenMP/omp-host-ir-flag.f90 index f25a024afb1d5..fd6d383aff8f4 100644 --- a/flang/test/Lower/OpenMP/omp-host-ir-flag.f90 +++ b/flang/test/Lower/OpenMP/omp-host-ir-flag.f90 @@ -1,6 +1,6 @@ !RUN: %flang_fc1 -emit-llvm-bc -fopenmp -o %t.bc %s 2>&1 !RUN: %flang_fc1 -emit-mlir -fopenmp -fopenmp-is-device -fopenmp-host-ir-file-path %t.bc -o - %s 2>&1 | FileCheck %s -!CHECK: module attributes {{{.*}}, omp.host_ir_filepath = "{{.*}}.bc", omp.is_device = #omp.isdevice{{.*}}} +!CHECK: module attributes {{{.*}}, omp.host_ir_filepath = "{{.*}}.bc", omp.is_device = true{{.*}}} subroutine omp_subroutine() end subroutine omp_subroutine diff --git a/flang/test/Lower/OpenMP/omp-is-device.f90 b/flang/test/Lower/OpenMP/omp-is-device.f90 index 03f4d4bc589ee..63840aca56c0c 100644 --- a/flang/test/Lower/OpenMP/omp-is-device.f90 +++ b/flang/test/Lower/OpenMP/omp-is-device.f90 @@ -5,10 +5,10 @@ !RUN: bbc -fopenmp -emit-fir -o - %s | FileCheck %s --check-prefix=HOST !RUN: bbc -fopenmp-is-device -emit-fir -o - %s | FileCheck %s --check-prefix=DEVICE-FLAG-ONLY -!DEVICE: module attributes {{{.*}}, omp.is_device = #omp.isdevice{{.*}}} -!HOST: module attributes {{{.*}}, omp.is_device = #omp.isdevice{{.*}}} +!DEVICE: module attributes {{{.*}}, omp.is_device = true{{.*}}} +!HOST: module attributes {{{.*}}, omp.is_device = false{{.*}}} !DEVICE-FLAG-ONLY: module attributes {{{.*}}" -!DEVICE-FLAG-ONLY-NOT: , omp.is_device = #omp.isdevice<{{.*}}> +!DEVICE-FLAG-ONLY-NOT: , omp.is_device = {{.*}} !DEVICE-FLAG-ONLY-SAME: } subroutine omp_subroutine() end subroutine omp_subroutine diff --git a/flang/test/Lower/OpenMP/rtl-flags.f90 b/flang/test/Lower/OpenMP/rtl-flags.f90 index a104d13b23ba6..461184a1c8d17 100644 --- a/flang/test/Lower/OpenMP/rtl-flags.f90 +++ b/flang/test/Lower/OpenMP/rtl-flags.f90 @@ -20,10 +20,10 @@ !RUN: bbc -emit-fir -fopenmp -fopenmp-assume-no-nested-parallelism -fopenmp-is-device -o - %s | FileCheck %s --check-prefix=NEST-PAR-DEVICE-FIR !RUN: bbc -emit-fir -fopenmp -fopenmp-target-debug=1 -fopenmp-assume-teams-oversubscription -fopenmp-assume-no-nested-parallelism -fopenmp-assume-threads-oversubscription -fopenmp-assume-no-thread-state -fopenmp-is-device -o - %s | FileCheck %s --check-prefix=ALL-DEVICE-FIR -!DEFAULT-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags, omp.is_device = #omp.isdevice{{.*}}} -!DEFAULT-DEVICE-FIR-VERSION: module attributes {{{.*}}, omp.flags = #omp.flags, omp.is_device = #omp.isdevice, omp.version = #omp.version{{.*}} -!DEFAULT-HOST-FIR: module attributes {{{.*}}, omp.is_device = #omp.isdevice{{.*}} -!DEFAULT-HOST-FIR-VERSION: module attributes {{{.*}}, omp.is_device = #omp.isdevice, omp.version = #omp.version{{.*}} +!DEFAULT-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags, omp.is_device = true{{.*}}} +!DEFAULT-DEVICE-FIR-VERSION: module attributes {{{.*}}, omp.flags = #omp.flags, omp.is_device = true, omp.version = #omp.version{{.*}} +!DEFAULT-HOST-FIR: module attributes {{{.*}}, omp.is_device = false{{.*}} +!DEFAULT-HOST-FIR-VERSION: module attributes {{{.*}}, omp.is_device = false, omp.version = #omp.version{{.*}} !DBG-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags{{.*}}} !DBG-EQ-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags{{.*}}} !TEAMS-OSUB-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags{{.*}}} diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td index 75c1f1c26155e..878040ebe94ab 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -45,14 +45,6 @@ class OpenMP_Attr { - let parameters = (ins - "bool":$is_device - ); - - let assemblyFormat = "`<` struct(params) `>`"; -} - def VersionAttr : OpenMP_Attr<"Version", "version"> { let parameters = (ins "uint32_t":$version diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td index 0331f9ff1eb29..789962999f128 100644 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -126,27 +126,27 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> { let methods = [ InterfaceMethod< /*description=*/[{ - Set the attribute IsDeviceAttr on the current module with the - specified boolean argument. + Set the attribute on the current module with the specified boolean + argument. }], /*retTy=*/"void", /*methodName=*/"setIsDevice", (ins "bool":$isDevice), [{}], [{ $_op->setAttr( mlir::StringAttr::get($_op->getContext(), llvm::Twine{"omp.is_device"}), - mlir::omp::IsDeviceAttr::get($_op->getContext(), isDevice)); + mlir::BoolAttr::get($_op->getContext(), isDevice)); }]>, InterfaceMethod< /*description=*/[{ - Get the IsDeviceAttr attribute on the current module if it exists and return - its value, if it doesn't exist it returns false by default. + Get the attribute on the current module if it exists and + return its value, if it doesn't exist it returns false by default. }], /*retTy=*/"bool", /*methodName=*/"getIsDevice", (ins), [{}], [{ if (Attribute isDevice = $_op->getAttr("omp.is_device")) - if (::llvm::isa(isDevice)) - return ::llvm::dyn_cast(isDevice).getIsDevice(); + if (isDevice.isa()) + return isDevice.dyn_cast().getValue(); return false; }]>, InterfaceMethod< diff --git a/mlir/lib/Target/LLVMIR/CMakeLists.txt b/mlir/lib/Target/LLVMIR/CMakeLists.txt index 147b1fdd30d27..f2d95949a9740 100644 --- a/mlir/lib/Target/LLVMIR/CMakeLists.txt +++ b/mlir/lib/Target/LLVMIR/CMakeLists.txt @@ -39,7 +39,6 @@ add_mlir_translation_library(MLIRTargetLLVMIRExport MLIRLLVMDialect MLIRLLVMIRTransforms MLIRTranslateLib - MLIROpenMPDialect ) add_mlir_translation_library(MLIRToLLVMIRTranslationRegistration diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp index 9b8e9a3ee1f3e..52e500442b94e 100644 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1276,11 +1276,15 @@ llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() { bool isDevice = false; llvm::StringRef hostIRFilePath = ""; - if (auto offloadMod = - dyn_cast(mlirModule)) { - isDevice = offloadMod.getIsDevice(); - hostIRFilePath = offloadMod.getHostIRFilePath(); - } + + if (Attribute deviceAttr = mlirModule->getAttr("omp.is_device")) + if (::llvm::isa(deviceAttr)) + isDevice = ::llvm::dyn_cast(deviceAttr).getValue(); + + if (Attribute filepath = mlirModule->getAttr("omp.host_ir_filepath")) + if (::llvm::isa(filepath)) + hostIRFilePath = + ::llvm::dyn_cast(filepath).getValue(); ompBuilder->initialize(hostIRFilePath); diff --git a/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir index 3e385e0d7d367..1ccef44c3b4cd 100644 --- a/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir +++ b/mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir @@ -1,6 +1,6 @@ // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s -module attributes {omp.is_device = #omp.isdevice} { +module attributes {omp.is_device = true} { llvm.func @omp_target_region_() { %0 = llvm.mlir.constant(20 : i32) : i32 %1 = llvm.mlir.constant(10 : i32) : i32 diff --git a/mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir index 68b2f4994eff7..8adc670b72ad7 100644 --- a/mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir +++ b/mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir @@ -1,6 +1,6 @@ // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s -module attributes {omp.is_device = #omp.isdevice} { +module attributes {omp.is_device = false} { llvm.func @omp_target_region_() { %0 = llvm.mlir.constant(20 : i32) : i32 %1 = llvm.mlir.constant(10 : i32) : i32 diff --git a/mlir/test/Target/LLVMIR/omptarget-region-parallel-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-region-parallel-llvm.mlir index 455edda301c20..1230dbdcb10d0 100644 --- a/mlir/test/Target/LLVMIR/omptarget-region-parallel-llvm.mlir +++ b/mlir/test/Target/LLVMIR/omptarget-region-parallel-llvm.mlir @@ -1,6 +1,6 @@ // RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s -module attributes {omp.is_device = #omp.isdevice} { +module attributes {omp.is_device = false} { llvm.func @omp_target_region_() { %0 = llvm.mlir.constant(20 : i32) : i32 %1 = llvm.mlir.constant(10 : i32) : i32