[flang-commits] [flang] [Flang][MLIR][OpenMP] Create a deferred declare target marking process for Bridge.cpp (PR #78502)
Sergio Afonso via flang-commits
flang-commits at lists.llvm.org
Thu Feb 22 03:42:08 PST 2024
================
@@ -4471,6 +4518,47 @@ bool Fortran::lower::isOpenMPDeviceDeclareTarget(
ompDecl.u);
}
+// In certain cases such as subroutine or function interfaces which declare
+// but do not define or directly call the subroutine or function in the same
+// module, their lowering is delayed until after the declare target construct
+// itself is processed, so there symbol is not within the table.
+//
+// This function will also return true if we encounter any device declare
+// target cases, to satisfy checking if we require the requires attributes
+// on the module.
+bool Fortran::lower::markOpenMPDeferredDeclareTargetFunctions(
+ mlir::Operation *mod,
+ llvm::SmallVectorImpl<OMPDeferredDeclTarInfo> &deferredDeclareTargets,
+ AbstractConverter &converter) {
+ bool deviceCodeFound = false;
+ if (auto modOp = llvm::dyn_cast<mlir::ModuleOp>(mod)) {
+ for (auto sym : deferredDeclareTargets) {
+ mlir::Operation *op =
+ modOp.lookupSymbol(converter.mangleName(std::get<2>(sym)));
+
+ // Due to interfaces being optionally emitted on usage in a module,
+ // not finding an operation at this point cannot be a hard error, we
+ // simply ignore it for now.
+ if (!op)
+ continue;
+
+ auto devType =
+ static_cast<mlir::omp::DeclareTargetDeviceType>(std::get<1>(sym));
+ if (!deviceCodeFound &&
+ devType != mlir::omp::DeclareTargetDeviceType::host) {
----------------
skatrak wrote:
Nit: Braces not necessary here I think
https://github.com/llvm/llvm-project/pull/78502
More information about the flang-commits
mailing list