[flang-commits] [flang] [Flang][MIF] Allocation of NON-ALLOCATABLE SAVE coarray (PR #205847)

via flang-commits flang-commits at lists.llvm.org
Thu Jul 9 08:27:08 PDT 2026


================
@@ -61,3 +62,25 @@ std::string mif::getFullUniqName(mlir::Value addr) {
   }
   return "";
 }
+
+mlir::func::FuncOp mif::getOrCreateInitFunc(mlir::OpBuilder &builder,
+                                            mlir::ModuleOp mod,
+                                            llvm::StringRef name) {
+
+  if (auto func = mod.lookupSymbol<mlir::func::FuncOp>(name))
+    return func;
+
+  auto funcType = builder.getFunctionType({}, {});
+  mlir::OpBuilder::InsertionGuard guard(builder);
+  builder.setInsertionPointToEnd(mod.getBody());
+
+  mlir::Location loc = mod.getLoc();
+  auto func = mlir::func::FuncOp::create(builder, loc, name, funcType);
----------------
jeanPerier wrote:

I would advise using fir::FIROpBuilder::createFunction declared [here](https://github.com/llvm/llvm-project/blob/7fff69bcb787957a2db55f2b954e9deb2b6bf11e/flang/include/flang/Optimizer/Builder/FIRBuilder.h#L448) so that you can benefit from using a SymbolMap to find the funcOp faster if it already exists (it does the lookup/create already, just need to add an EntryBlock/Return/setPublic if there is none already).

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


More information about the flang-commits mailing list