Skip to content

Commit a6a462f

Browse files
authored
[MLIR][OpenMP] Add omp.target_triples attribute to the OffloadModuleInterface (#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`.
1 parent 08decd2 commit a6a462f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPOpsInterfaces.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,34 @@ def OffloadModuleInterface : OpInterface<"OffloadModuleInterface"> {
351351
(ins "::mlir::omp::ClauseRequires":$clauses), [{}], [{
352352
$_op->setAttr(mlir::StringAttr::get($_op->getContext(), "omp.requires"),
353353
mlir::omp::ClauseRequiresAttr::get($_op->getContext(), clauses));
354+
}]>,
355+
InterfaceMethod<
356+
/*description=*/[{
357+
Get the omp.target_triples attribute on the operator if it's present and
358+
return its value. If it doesn't exist, return an empty array by default.
359+
}],
360+
/*retTy=*/"::llvm::ArrayRef<::mlir::Attribute>",
361+
/*methodName=*/"getTargetTriples",
362+
(ins), [{}], [{
363+
if (Attribute triplesAttr = $_op->getAttr("omp.target_triples"))
364+
if (auto triples = ::llvm::dyn_cast<::mlir::ArrayAttr>(triplesAttr))
365+
return triples.getValue();
366+
return {};
367+
}]>,
368+
InterfaceMethod<
369+
/*description=*/[{
370+
Set the omp.target_triples attribute on the operation.
371+
}],
372+
/*retTy=*/"void",
373+
/*methodName=*/"setTargetTriples",
374+
(ins "::llvm::ArrayRef<::std::string>":$targetTriples), [{}], [{
375+
auto names = ::llvm::to_vector(::llvm::map_range(
376+
targetTriples, [&](::std::string str) -> ::mlir::Attribute {
377+
return mlir::StringAttr::get($_op->getContext(), str);
378+
}));
379+
$_op->setAttr(
380+
::mlir::StringAttr::get($_op->getContext(), "omp.target_triples"),
381+
::mlir::ArrayAttr::get($_op->getContext(), names));
354382
}]>
355383
];
356384
}

0 commit comments

Comments
 (0)