[flang-commits] [flang] f6a631d - [MLIR] Remove dependency on omp dialect in LLVM dialect.
Jan Sjodin via flang-commits
flang-commits at lists.llvm.org
Wed May 31 06:41:53 PDT 2023
Author: Jan Sjodin
Date: 2023-05-31T08:40:22-05:00
New Revision: f6a631d4060c5b539fd51b7221205ee05ec50ee8
URL: https://github.com/llvm/llvm-project/commit/f6a631d4060c5b539fd51b7221205ee05ec50ee8
DIFF: https://github.com/llvm/llvm-project/commit/f6a631d4060c5b539fd51b7221205ee05ec50ee8.diff
LOG: [MLIR] Remove dependency on omp dialect in LLVM dialect.
This fixes a buildbot failure where the dependency on the omp dialect
in the LLVM dialect caused error. Instead of accessing the interface
defined in the omp dialect we directly access the attributes
instead. To make this work the IsDeviceAttr is removed and replaced
with a BoolAttr instead.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D151745
Added:
Modified:
flang/test/Fir/omp-declare-target-data.fir
flang/test/Lower/OpenMP/omp-host-ir-flag.f90
flang/test/Lower/OpenMP/omp-is-device.f90
flang/test/Lower/OpenMP/rtl-flags.f90
mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td
mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
mlir/lib/Target/LLVMIR/CMakeLists.txt
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Target/LLVMIR/omptarget-region-device-llvm.mlir
mlir/test/Target/LLVMIR/omptarget-region-llvm.mlir
mlir/test/Target/LLVMIR/omptarget-region-parallel-llvm.mlir
Removed:
################################################################################
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<is_device = false>} {
+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<device_type = (any), capture_clause = (link)>{{.*}}} : !llvm.array<3 x i32>
fir.global @_QMtest_0Earray_1d(dense<[1, 2, 3]> : tensor<3xi32>) {omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (link)>} : !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<is_device = true>{{.*}}}
+!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<is_device = true>{{.*}}}
-!HOST: module attributes {{{.*}}, omp.is_device = #omp.isdevice<is_device = false>{{.*}}}
+!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<openmp_device_version = 11>, omp.is_device = #omp.isdevice<is_device = true>{{.*}}}
-!DEFAULT-DEVICE-FIR-VERSION: module attributes {{{.*}}, omp.flags = #omp.flags<openmp_device_version = 45>, omp.is_device = #omp.isdevice<is_device = true>, omp.version = #omp.version<version = 45>{{.*}}
-!DEFAULT-HOST-FIR: module attributes {{{.*}}, omp.is_device = #omp.isdevice<is_device = false>{{.*}}
-!DEFAULT-HOST-FIR-VERSION: module attributes {{{.*}}, omp.is_device = #omp.isdevice<is_device = false>, omp.version = #omp.version<version = 45>{{.*}}
+!DEFAULT-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags<openmp_device_version = 11>, omp.is_device = true{{.*}}}
+!DEFAULT-DEVICE-FIR-VERSION: module attributes {{{.*}}, omp.flags = #omp.flags<openmp_device_version = 45>, omp.is_device = true, omp.version = #omp.version<version = 45>{{.*}}
+!DEFAULT-HOST-FIR: module attributes {{{.*}}, omp.is_device = false{{.*}}
+!DEFAULT-HOST-FIR-VERSION: module attributes {{{.*}}, omp.is_device = false, omp.version = #omp.version<version = 45>{{.*}}
!DBG-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags<debug_kind = 1, openmp_device_version = 11>{{.*}}}
!DBG-EQ-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags<debug_kind = 111, openmp_device_version = 11>{{.*}}}
!TEAMS-OSUB-DEVICE-FIR: module attributes {{{.*}}, omp.flags = #omp.flags<assume_teams_oversubscription = true, openmp_device_version = 11>{{.*}}}
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<string name, string attrMnemonic,
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
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<mlir::omp::IsDeviceAttr>(isDevice))
- return ::llvm::dyn_cast<IsDeviceAttr>(isDevice).getIsDevice();
+ if (isDevice.isa<mlir::BoolAttr>())
+ return isDevice.dyn_cast<BoolAttr>().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<mlir::omp::OffloadModuleInterface>(mlirModule)) {
- isDevice = offloadMod.getIsDevice();
- hostIRFilePath = offloadMod.getHostIRFilePath();
- }
+
+ if (Attribute deviceAttr = mlirModule->getAttr("omp.is_device"))
+ if (::llvm::isa<mlir::BoolAttr>(deviceAttr))
+ isDevice = ::llvm::dyn_cast<mlir::BoolAttr>(deviceAttr).getValue();
+
+ if (Attribute filepath = mlirModule->getAttr("omp.host_ir_filepath"))
+ if (::llvm::isa<mlir::StringAttr>(filepath))
+ hostIRFilePath =
+ ::llvm::dyn_cast<mlir::StringAttr>(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<is_device = true>} {
+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<is_device = false>} {
+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<is_device = false>} {
+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
More information about the flang-commits
mailing list