[llvm-branch-commits] [mlir] [MLIR][OpenMP] Add omp.target_triples attribute to the OffloadModuleInterface (PR #100154)
Sergio Afonso via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jul 23 09:39:32 PDT 2024
https://github.com/skatrak created https://github.com/llvm/llvm-project/pull/100154
The `OffloadModuleInterface` holds getter/setter methods to access OpenMP dialect module-level discardable attributes used to hold general OpenMP compilation information.
This patch adds the `omp.target_triples` attribute, which is intended to hold the list of offloading target triples linked to the host module in which it appears. This attribute should be empty when `omp.is_target_device=true`.
>From 3dbb22595bcf691a619483ea51b3620a9de87263 Mon Sep 17 00:00:00 2001
From: Sergio Afonso <safonsof at amd.com>
Date: Tue, 23 Jul 2024 16:32:16 +0100
Subject: [PATCH] [MLIR][OpenMP] Add omp.target_triples attribute to the
OffloadModuleInterface
The `OffloadModuleInterface` holds getter/setter methods to access OpenMP
dialect module-level discardable attributes used to hold general OpenMP
compilation information.
This patch adds the `omp.target_triples` attribute, which is intended to hold
the list of offloading target triples linked to the host module in which it
appears. This attribute should be empty when `omp.is_target_device=true`.
---
.../Dialect/OpenMP/OpenMPOpsInterfaces.td | 28 +++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
index 385aa8b1b016a..9e62dcd9253d6 100644
--- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
+++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td
@@ -351,6 +351,34 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
(ins "::mlir::omp::ClauseRequires":$clauses), [{}], [{
$_op->setAttr(mlir::StringAttr::get($_op->getContext(), "omp.requires"),
mlir::omp::ClauseRequiresAttr::get($_op->getContext(), clauses));
+ }]>,
+ InterfaceMethod<
+ /*description=*/[{
+ Get the omp.target_triples attribute on the operator if it's present and
+ return its value. If it doesn't exist, return an empty array by default.
+ }],
+ /*retTy=*/"::llvm::ArrayRef<::mlir::Attribute>",
+ /*methodName=*/"getTargetTriples",
+ (ins), [{}], [{
+ if (Attribute triplesAttr = $_op->getAttr("omp.target_triples"))
+ if (auto triples = ::llvm::dyn_cast<::mlir::ArrayAttr>(triplesAttr))
+ return triples.getValue();
+ return {};
+ }]>,
+ InterfaceMethod<
+ /*description=*/[{
+ Set the omp.target_triples attribute on the operation.
+ }],
+ /*retTy=*/"void",
+ /*methodName=*/"setTargetTriples",
+ (ins "::llvm::ArrayRef<::std::string>":$targetTriples), [{}], [{
+ auto names = ::llvm::to_vector(::llvm::map_range(
+ targetTriples, [&](::std::string str) -> ::mlir::Attribute {
+ return mlir::StringAttr::get($_op->getContext(), str);
+ }));
+ $_op->setAttr(
+ ::mlir::StringAttr::get($_op->getContext(), "omp.target_triples"),
+ ::mlir::ArrayAttr::get($_op->getContext(), names));
}]>
];
}
More information about the llvm-branch-commits
mailing list