diff --git a/flang/test/Fir/omp-declare-target-data.fir b/flang/test/Fir/omp-declare-target-data.fir --- 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 --- 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 --- 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 --- 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 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -45,14 +45,6 @@ let mnemonic = attrMnemonic; } -def IsDeviceAttr : OpenMP_Attr<"IsDevice", "isdevice"> { - 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 --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td @@ -126,27 +126,27 @@ 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 --- a/mlir/lib/Target/LLVMIR/CMakeLists.txt +++ b/mlir/lib/Target/LLVMIR/CMakeLists.txt @@ -39,7 +39,6 @@ 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 --- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp +++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp @@ -1276,11 +1276,15 @@ 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 --- 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 --- 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 --- 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