[flang-commits] [flang] [flang][acc][lowering] Declare undeclared acc routine bind(name) targets (PR #203088)

via flang-commits flang-commits at lists.llvm.org
Fri Jun 12 02:11:53 PDT 2026


================
@@ -4535,6 +4537,70 @@ void Fortran::lower::genOpenACCRoutineConstruct(
       workerDeviceTypes, vectorDeviceTypes);
 }
 
+void Fortran::lower::materializeOpenACCRoutineBindTargets(
+    Fortran::lower::AbstractConverter &converter,
+    Fortran::semantics::SemanticsContext &semaCtx,
+    const Fortran::semantics::Scope *scope) {
+  const Fortran::semantics::Scope &root =
+      scope ? *scope : semaCtx.globalScope();
+
+  // Recurse into child scopes first (modules, subprograms, etc.).
+  for (const Fortran::semantics::Scope &child : root.children())
+    materializeOpenACCRoutineBindTargets(converter, semaCtx, &child);
+
+  mlir::ModuleOp module = converter.getModuleOp();
+  mlir::SymbolTable *symbolTable = converter.getMLIRSymbolTable();
+
+  // Declare a single bind(name) target. A bind("string") target is a raw asm
+  // name used verbatim -- no Fortran-symbol resolution or name mangling --
+  // whereas a bind(symbol) target is mangled; a func.func is declared for both.
+  auto declareBindTarget =
+      [&](const Fortran::semantics::OpenACCRoutineDeviceTypeInfo &dti) {
+        const std::variant<std::string, Fortran::semantics::SymbolRef> *bind =
+            dti.bindName();
+        if (!bind)
+          return;
+        if (const auto *bindSym =
+                std::get_if<Fortran::semantics::SymbolRef>(bind)) {
+          // bind(identifier): declared with external-procedure mangling,
+          // matching the bind reference.
+          Fortran::evaluate::ProcedureDesignator proc(*bindSym);
+          (void)Fortran::lower::getOrDeclareFunction(proc, converter);
+        } else if (const auto *bindStr = std::get_if<std::string>(bind)) {
+          // bind("string"): the literal is its own external name, declared
+          // verbatim.
+          (void)Fortran::lower::getOrDeclareNamedFunction(*bindStr, converter);
----------------
jeanPerier wrote:

OK, and if the signature does not really matter, would creating the func.func on the fly when needed in the acc lowering be an option?

https://github.com/llvm/llvm-project/pull/203088


More information about the flang-commits mailing list