Skip to content

[globalopt] Eliminate indentation by inverting a condition into an ea… #15486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lib/SILOptimizer/IPO/GlobalOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,30 +806,29 @@ void SILGlobalOpt::optimizeInitializer(SILFunction *AddrF,
}

SILGlobalVariable *SILGlobalOpt::getVariableOfGlobalInit(SILFunction *AddrF) {
if (AddrF->isGlobalInit()) {
// If the addressor contains a single "once" call, it calls globalinit_func,
// and the globalinit_func is called by "once" from a single location,
// continue; otherwise bail.
BuiltinInst *CallToOnce;
auto *InitF = findInitializer(Module, AddrF, CallToOnce);

if (!InitF || !InitF->getName().startswith("globalinit_")
|| InitializerCount[InitF] > 1)
return nullptr;
if (!AddrF->isGlobalInit())
return nullptr;

// If the globalinit_func is trivial, continue; otherwise bail.
SingleValueInstruction *dummyInitVal;
auto *SILG = getVariableOfStaticInitializer(InitF, dummyInitVal);
if (!SILG || !SILG->isDefinition())
return nullptr;
// If the addressor contains a single "once" call, it calls globalinit_func,
// and the globalinit_func is called by "once" from a single location,
// continue; otherwise bail.
BuiltinInst *CallToOnce;
auto *InitF = findInitializer(Module, AddrF, CallToOnce);

return SILG;
}
return nullptr;
if (!InitF || !InitF->getName().startswith("globalinit_")
|| InitializerCount[InitF] > 1)
return nullptr;

// If the globalinit_func is trivial, continue; otherwise bail.
SingleValueInstruction *dummyInitVal;
auto *SILG = getVariableOfStaticInitializer(InitF, dummyInitVal);
if (!SILG || !SILG->isDefinition())
return nullptr;

return SILG;
}

static bool canBeChangedExternally(SILGlobalVariable *SILG) {

// Don't assume anything about globals which are imported from other modules.
if (isAvailableExternally(SILG->getLinkage()))
return true;
Expand Down