Skip to content

Commit b2a1da3

Browse files
committed
less builder creation
1 parent a52655d commit b2a1da3

File tree

1 file changed

+53
-56
lines changed

1 file changed

+53
-56
lines changed

flang/lib/Lower/Bridge.cpp

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -397,40 +397,39 @@ class FirConverter : public Fortran::lower::AbstractConverter {
397397
// they are available before lowering any function that may use them.
398398
bool hasMainProgram = false;
399399
const Fortran::semantics::Symbol *globalOmpRequiresSymbol = nullptr;
400-
for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
401-
Fortran::common::visit(
402-
Fortran::common::visitors{
403-
[&](Fortran::lower::pft::FunctionLikeUnit &f) {
404-
if (f.isMainProgram())
405-
hasMainProgram = true;
406-
createGlobalOutsideOfFunctionLowering(
407-
[&]() { declareFunction(f); });
408-
if (!globalOmpRequiresSymbol)
409-
globalOmpRequiresSymbol = f.getScope().symbol();
410-
},
411-
[&](Fortran::lower::pft::ModuleLikeUnit &m) {
412-
lowerModuleDeclScope(m);
413-
createGlobalOutsideOfFunctionLowering([&]() {
400+
createBuilderOutsideOfFuncOpAndDo([&]() {
401+
for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
402+
Fortran::common::visit(
403+
Fortran::common::visitors{
404+
[&](Fortran::lower::pft::FunctionLikeUnit &f) {
405+
if (f.isMainProgram())
406+
hasMainProgram = true;
407+
declareFunction(f);
408+
if (!globalOmpRequiresSymbol)
409+
globalOmpRequiresSymbol = f.getScope().symbol();
410+
},
411+
[&](Fortran::lower::pft::ModuleLikeUnit &m) {
412+
lowerModuleDeclScope(m);
414413
for (Fortran::lower::pft::ContainedUnit &unit :
415414
m.containedUnitList)
416415
if (auto *f =
417416
std::get_if<Fortran::lower::pft::FunctionLikeUnit>(
418417
&unit))
419418
declareFunction(*f);
420-
});
421-
},
422-
[&](Fortran::lower::pft::BlockDataUnit &b) {
423-
if (!globalOmpRequiresSymbol)
424-
globalOmpRequiresSymbol = b.symTab.symbol();
425-
},
426-
[&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
427-
[&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
428-
},
429-
u);
430-
}
419+
},
420+
[&](Fortran::lower::pft::BlockDataUnit &b) {
421+
if (!globalOmpRequiresSymbol)
422+
globalOmpRequiresSymbol = b.symTab.symbol();
423+
},
424+
[&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
425+
[&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
426+
},
427+
u);
428+
}
429+
});
431430

432431
// Create definitions of intrinsic module constants.
433-
createGlobalOutsideOfFunctionLowering(
432+
createBuilderOutsideOfFuncOpAndDo(
434433
[&]() { createIntrinsicModuleDefinitions(pft); });
435434

436435
// Primary translation pass.
@@ -449,12 +448,12 @@ class FirConverter : public Fortran::lower::AbstractConverter {
449448
// Once all the code has been translated, create global runtime type info
450449
// data structures for the derived types that have been processed, as well
451450
// as fir.type_info operations for the dispatch tables.
452-
createGlobalOutsideOfFunctionLowering(
451+
createBuilderOutsideOfFuncOpAndDo(
453452
[&]() { typeInfoConverter.createTypeInfo(*this); });
454453

455454
// Generate the `main` entry point if necessary
456455
if (hasMainProgram)
457-
createGlobalOutsideOfFunctionLowering([&]() {
456+
createBuilderOutsideOfFuncOpAndDo([&]() {
458457
fir::runtime::genMain(*builder, toLocation(),
459458
bridge.getEnvironmentDefaults(),
460459
getFoldingContext().languageFeatures().IsEnabled(
@@ -5885,7 +5884,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
58855884
/// always positioned inside a region block when creating globals, the easiest
58865885
/// way to comply is to create a dummy function and to throw it away
58875886
/// afterwards.
5888-
void createGlobalOutsideOfFunctionLowering(
5887+
void createBuilderOutsideOfFuncOpAndDo(
58895888
const std::function<void()> &createGlobals) {
58905889
// FIXME: get rid of the bogus function context and instantiate the
58915890
// globals directly into the module.
@@ -5913,7 +5912,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
59135912

59145913
/// Instantiate the data from a BLOCK DATA unit.
59155914
void lowerBlockData(Fortran::lower::pft::BlockDataUnit &bdunit) {
5916-
createGlobalOutsideOfFunctionLowering([&]() {
5915+
createBuilderOutsideOfFuncOpAndDo([&]() {
59175916
Fortran::lower::AggregateStoreMap fakeMap;
59185917
for (const auto &[_, sym] : bdunit.symTab) {
59195918
if (sym->has<Fortran::semantics::ObjectEntityDetails>()) {
@@ -5927,7 +5926,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
59275926
/// Create fir::Global for all the common blocks that appear in the program.
59285927
void
59295928
lowerCommonBlocks(const Fortran::semantics::CommonBlockList &commonBlocks) {
5930-
createGlobalOutsideOfFunctionLowering(
5929+
createBuilderOutsideOfFuncOpAndDo(
59315930
[&]() { Fortran::lower::defineCommonBlocks(*this, commonBlocks); });
59325931
}
59335932

@@ -5997,36 +5996,34 @@ class FirConverter : public Fortran::lower::AbstractConverter {
59975996
/// declarative construct.
59985997
void lowerModuleDeclScope(Fortran::lower::pft::ModuleLikeUnit &mod) {
59995998
setCurrentPosition(mod.getStartingSourceLoc());
6000-
createGlobalOutsideOfFunctionLowering([&]() {
6001-
auto &scopeVariableListMap =
6002-
Fortran::lower::pft::getScopeVariableListMap(mod);
6003-
for (const auto &var : Fortran::lower::pft::getScopeVariableList(
6004-
mod.getScope(), scopeVariableListMap)) {
6005-
6006-
// Only define the variables owned by this module.
6007-
const Fortran::semantics::Scope *owningScope = var.getOwningScope();
6008-
if (owningScope && mod.getScope() != *owningScope)
6009-
continue;
5999+
auto &scopeVariableListMap =
6000+
Fortran::lower::pft::getScopeVariableListMap(mod);
6001+
for (const auto &var : Fortran::lower::pft::getScopeVariableList(
6002+
mod.getScope(), scopeVariableListMap)) {
60106003

6011-
// Very special case: The value of numeric_storage_size depends on
6012-
// compilation options and therefore its value is not yet known when
6013-
// building the builtins runtime. Instead, the parameter is folding a
6014-
// __numeric_storage_size() expression which is loaded into the user
6015-
// program. For the iso_fortran_env object file, omit the symbol as it
6016-
// is never used.
6017-
if (var.hasSymbol()) {
6018-
const Fortran::semantics::Symbol &sym = var.getSymbol();
6019-
const Fortran::semantics::Scope &owner = sym.owner();
6020-
if (sym.name() == "numeric_storage_size" && owner.IsModule() &&
6021-
DEREF(owner.symbol()).name() == "iso_fortran_env")
6022-
continue;
6023-
}
6004+
// Only define the variables owned by this module.
6005+
const Fortran::semantics::Scope *owningScope = var.getOwningScope();
6006+
if (owningScope && mod.getScope() != *owningScope)
6007+
continue;
60246008

6025-
Fortran::lower::defineModuleVariable(*this, var);
6009+
// Very special case: The value of numeric_storage_size depends on
6010+
// compilation options and therefore its value is not yet known when
6011+
// building the builtins runtime. Instead, the parameter is folding a
6012+
// __numeric_storage_size() expression which is loaded into the user
6013+
// program. For the iso_fortran_env object file, omit the symbol as it
6014+
// is never used.
6015+
if (var.hasSymbol()) {
6016+
const Fortran::semantics::Symbol &sym = var.getSymbol();
6017+
const Fortran::semantics::Scope &owner = sym.owner();
6018+
if (sym.name() == "numeric_storage_size" && owner.IsModule() &&
6019+
DEREF(owner.symbol()).name() == "iso_fortran_env")
6020+
continue;
60266021
}
6022+
6023+
Fortran::lower::defineModuleVariable(*this, var);
6024+
}
60276025
for (auto &eval : mod.evaluationList)
60286026
genFIR(eval);
6029-
});
60306027
}
60316028

60326029
/// Lower functions contained in a module.

0 commit comments

Comments
 (0)