[flang-commits] [flang] [flang] Rely on global initialization for simpler derived types (PR #114002)

via flang-commits flang-commits at lists.llvm.org
Tue Oct 29 03:09:53 PDT 2024


================
@@ -793,11 +794,35 @@ void Fortran::lower::defaultInitializeAtRuntime(
         })
         .end();
   } else {
-    mlir::Value box = builder.createBox(loc, exv);
-    fir::runtime::genDerivedTypeInitialize(builder, loc, box);
+    /// For "simpler" types, relying on "_FortranAInitialize"
+    /// leads to poor runtime performance. Hence optimize
+    /// the same.
+    const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType();
+    mlir::Type symTy = converter.genType(var);
+    if (!var.isAlias() && !hasAllocatableDirectComponent(sym) &&
----------------
jeanPerier wrote:

var.isAlias is also irrelevant here if we are calling defaultInitializeAtRuntime on it. It may be a workaround around issues when hijackings defineGlobal, but as advised below, I think you should do it slightly differently, so this is not needed.

Then I would advise keeping this utility working with Symbol. It is generally unsafe to blindly do `pft::Variable{*sym}` because tests like `var.isAlias` would typcally not work as expected (pft::Variable are created after an analysis of the Scope in the bridge, and re-creating them directly from symbols has precedents, but is not good practice I think).

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


More information about the flang-commits mailing list