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

via flang-commits flang-commits at lists.llvm.org
Thu Jun 11 01:05:00 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:

So these fun.func will always be created with any kind of signature/attributes.
What will these fun.func symbols later used for in the acc pipeline?

I am trying to understand if their ABI matter in any ways (e.g., calls will be emitted to them), or if they will just be used to get some procedure addresses.

That is, should they for instance clone the decorated procedure signature?

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


More information about the flang-commits mailing list