Skip to content

Commit ba7ecfb

Browse files
committed
SIL: small refactoring of swift::findInitializer
NFC
1 parent 0685b28 commit ba7ecfb

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

include/swift/SIL/SILGlobalVariable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ SILFunction *getCalleeOfOnceCall(BuiltinInst *BI);
260260
/// Given an addressor, AddrF, find the call to the global initializer if
261261
/// present, otherwise return null. If an initializer is returned, then
262262
/// `CallToOnce` is initialized to the corresponding builtin "once" call.
263-
SILFunction *findInitializer(SILModule *Module, SILFunction *AddrF,
264-
BuiltinInst *&CallToOnce);
263+
SILFunction *findInitializer(SILFunction *AddrF, BuiltinInst *&CallToOnce);
265264

266265
/// Helper for getVariableOfGlobalInit(), so GlobalOpts can deeply inspect and
267266
/// rewrite the initialization pattern.

lib/SIL/IR/SILGlobalVariable.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ SILGlobalVariable *swift::getVariableOfGlobalInit(SILFunction *AddrF) {
220220
// and the globalinit_func is called by "once" from a single location,
221221
// continue; otherwise bail.
222222
BuiltinInst *CallToOnce;
223-
auto *InitF = findInitializer(&AddrF->getModule(), AddrF, CallToOnce);
223+
auto *InitF = findInitializer(AddrF, CallToOnce);
224224

225-
if (!InitF || !InitF->getName().startswith("globalinit_"))
225+
if (!InitF)
226226
return nullptr;
227227

228228
// If the globalinit_func is trivial, continue; otherwise bail.
@@ -247,8 +247,8 @@ SILFunction *swift::getCalleeOfOnceCall(BuiltinInst *BI) {
247247
}
248248

249249
// Find the globalinit_func by analyzing the body of the addressor.
250-
SILFunction *swift::findInitializer(SILModule *Module, SILFunction *AddrF,
251-
BuiltinInst *&CallToOnce) {
250+
SILFunction *swift::findInitializer(SILFunction *AddrF,
251+
BuiltinInst *&CallToOnce) {
252252
// We only handle a single SILBasicBlock for now.
253253
if (AddrF->size() != 1)
254254
return nullptr;
@@ -272,7 +272,10 @@ SILFunction *swift::findInitializer(SILModule *Module, SILFunction *AddrF,
272272
}
273273
if (!CallToOnce)
274274
return nullptr;
275-
return getCalleeOfOnceCall(CallToOnce);
275+
SILFunction *callee = getCalleeOfOnceCall(CallToOnce);
276+
if (!callee->getName().startswith("globalinit_"))
277+
return nullptr;
278+
return callee;
276279
}
277280

278281
SILGlobalVariable *

lib/SILOptimizer/IPO/GlobalOpt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,8 @@ bool SILGlobalOpt::optimizeInitializer(SILFunction *AddrF,
431431
// If the addressor contains a single "once" call, it calls globalinit_func,
432432
// and the globalinit_func is called by "once" from a single location,
433433
// continue; otherwise bail.
434-
auto *InitF = findInitializer(Module, AddrF, CallToOnce);
435-
if (!InitF || !InitF->getName().startswith("globalinit_") ||
436-
InitializerCount[InitF] > 1)
434+
auto *InitF = findInitializer(AddrF, CallToOnce);
435+
if (!InitF || InitializerCount[InitF] > 1)
437436
return false;
438437

439438
// If the globalinit_func is trivial, continue; otherwise bail.

0 commit comments

Comments
 (0)