[flang-commits] [flang] [flang] Rely on global initialization for simpler derived types (PR #114002)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 27 06:22:01 PST 2025
================
@@ -797,8 +798,59 @@ 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);
+ const auto *details =
+ sym.detailsIf<Fortran::semantics::ObjectEntityDetails>();
+ if (details && Fortran::lower::hasDefaultInitialization(sym) &&
+ declTy->category() ==
+ Fortran::semantics::DeclTypeSpec::Category::TypeDerived &&
+ !mlir::isa<fir::SequenceType>(symTy) &&
+ !sym.test(Fortran::semantics::Symbol::Flag::OmpPrivate) &&
+ !sym.test(Fortran::semantics::Symbol::Flag::OmpFirstPrivate)) {
+ std::string globalName = converter.mangleName(*declTy->AsDerived());
----------------
jeanPerier wrote:
Using the derived makes sense to me, but some prefix/suffix would be nice (fir.TypeInfoOp ops already uses that has MLIR symbol name, better avoid conflicts here), as well as using the compiler generated name prefix (doGenerated()).
I would go for `fir::NameUniquer::doGenerated(mangledName + kNameSeparator + kDerivedTypeInitSuffix)`
where `kDerivedTypeInitSuffix` can be defined as `init` in [Optimizer/Support/InternalNames.h](https://github.com/llvm/llvm-project/blob/main/flang/include/flang/Optimizer/Support/InternalNames.h).
https://github.com/llvm/llvm-project/pull/114002
More information about the flang-commits
mailing list