Skip to content

Commit def818b

Browse files
author
Zak Kent
committed
[NFC] [SILGen] Refactor emitOrDelayFunction into a SILGenModule method
1 parent 80e4e04 commit def818b

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,42 +1158,40 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
11581158
}
11591159
}
11601160

1161-
/// Emit a function now, if it's externally usable or has been referenced in
1162-
/// the current TU, or remember how to emit it later if not.
1163-
static void emitOrDelayFunction(SILGenModule &SGM, SILDeclRef constant) {
1161+
void SILGenModule::emitOrDelayFunction(SILDeclRef constant) {
11641162
assert(!constant.isThunk());
11651163
assert(!constant.isClangImported());
11661164

1167-
auto emitAfter = SGM.lastEmittedFunction;
1165+
auto emitAfter = lastEmittedFunction;
11681166

11691167
// Implicit decls may be delayed if they can't be used externally.
11701168
auto linkage = constant.getLinkage(ForDefinition);
11711169
bool mayDelay = !constant.hasUserWrittenCode() &&
11721170
!constant.isDynamicallyReplaceable() &&
1173-
!isPossiblyUsedExternally(linkage, SGM.M.isWholeModule());
1171+
!isPossiblyUsedExternally(linkage, M.isWholeModule());
11741172

11751173
if (!mayDelay) {
1176-
SGM.emitFunctionDefinition(constant, SGM.getFunction(constant, ForDefinition));
1174+
emitFunctionDefinition(constant, getFunction(constant, ForDefinition));
11771175
return;
11781176
}
11791177

11801178
// If the function is already forced then it was previously delayed and then
11811179
// referenced. We don't need to emit or delay it again.
1182-
if (SGM.forcedFunctions.contains(constant))
1180+
if (forcedFunctions.contains(constant))
11831181
return;
11841182

1185-
if (auto *f = SGM.getEmittedFunction(constant, ForDefinition)) {
1186-
SGM.emitFunctionDefinition(constant, f);
1183+
if (auto *f = getEmittedFunction(constant, ForDefinition)) {
1184+
emitFunctionDefinition(constant, f);
11871185
return;
11881186
}
11891187

11901188
// This is a delayable function so remember how to emit it in case it gets
11911189
// referenced later.
1192-
SGM.delayedFunctions.insert({constant, emitAfter});
1190+
delayedFunctions.insert({constant, emitAfter});
11931191
// Even though we didn't emit the function now, update the
11941192
// lastEmittedFunction so that we preserve the original ordering that
11951193
// the symbols would have been emitted in.
1196-
SGM.lastEmittedFunction = constant;
1194+
lastEmittedFunction = constant;
11971195
}
11981196

11991197
void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
@@ -1432,7 +1430,7 @@ void SILGenModule::emitFunction(FuncDecl *fd) {
14321430
emitAbstractFuncDecl(fd);
14331431

14341432
if (fd->hasBody())
1435-
emitOrDelayFunction(*this, SILDeclRef(decl));
1433+
emitOrDelayFunction(SILDeclRef(decl));
14361434
}
14371435

14381436
void SILGenModule::addGlobalVariable(VarDecl *global) {
@@ -1457,11 +1455,11 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
14571455
// initializers, have separate entry points for allocation and
14581456
// initialization.
14591457
if (decl->isDesignatedInit() || decl->isObjC()) {
1460-
emitOrDelayFunction(*this, constant);
1458+
emitOrDelayFunction(constant);
14611459

14621460
if (decl->hasBody()) {
14631461
SILDeclRef initConstant(decl, SILDeclRef::Kind::Initializer);
1464-
emitOrDelayFunction(*this, initConstant);
1462+
emitOrDelayFunction(initConstant);
14651463
}
14661464

14671465
return;
@@ -1471,7 +1469,7 @@ void SILGenModule::emitConstructor(ConstructorDecl *decl) {
14711469
// Struct and enum constructors do everything in a single function, as do
14721470
// non-@objc convenience initializers for classes.
14731471
if (decl->hasBody()) {
1474-
emitOrDelayFunction(*this, constant);
1472+
emitOrDelayFunction(constant);
14751473
}
14761474
}
14771475

@@ -1620,7 +1618,7 @@ void SILGenModule::emitDefaultArgGenerator(SILDeclRef constant,
16201618

16211619
case DefaultArgumentKind::Normal:
16221620
case DefaultArgumentKind::StoredProperty:
1623-
emitOrDelayFunction(*this, constant);
1621+
emitOrDelayFunction(constant);
16241622
break;
16251623

16261624
case DefaultArgumentKind::Inherited:
@@ -1638,7 +1636,7 @@ void SILGenModule::
16381636
emitStoredPropertyInitialization(PatternBindingDecl *pbd, unsigned i) {
16391637
auto *var = pbd->getAnchoringVarDecl(i);
16401638
SILDeclRef constant(var, SILDeclRef::Kind::StoredPropertyInitializer);
1641-
emitOrDelayFunction(*this, constant);
1639+
emitOrDelayFunction(constant);
16421640
}
16431641

16441642
void SILGenModule::
@@ -1647,12 +1645,12 @@ emitPropertyWrapperBackingInitializer(VarDecl *var) {
16471645

16481646
if (initInfo.hasInitFromWrappedValue()) {
16491647
SILDeclRef constant(var, SILDeclRef::Kind::PropertyWrapperBackingInitializer);
1650-
emitOrDelayFunction(*this, constant);
1648+
emitOrDelayFunction(constant);
16511649
}
16521650

16531651
if (initInfo.hasInitFromProjectedValue()) {
16541652
SILDeclRef constant(var, SILDeclRef::Kind::PropertyWrapperInitFromProjectedValue);
1655-
emitOrDelayFunction(*this, constant);
1653+
emitOrDelayFunction(constant);
16561654
}
16571655
}
16581656

@@ -1687,7 +1685,7 @@ void SILGenModule::emitGlobalAccessor(VarDecl *global,
16871685
SILFunction *onceFunc) {
16881686
SILDeclRef accessor(global, SILDeclRef::Kind::GlobalAccessor);
16891687
delayedGlobals[global] = std::make_pair(onceToken, onceFunc);
1690-
emitOrDelayFunction(*this, accessor);
1688+
emitOrDelayFunction(accessor);
16911689
}
16921690

16931691
void SILGenModule::emitArgumentGenerators(SILDeclRef::Loc decl,

lib/SILGen/SILGen.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
7575
llvm::DenseMap<VarDecl *, std::pair<SILGlobalVariable *,
7676
SILFunction *>> delayedGlobals;
7777

78-
/// The most recent declaration we considered for emission.
79-
SILDeclRef lastEmittedFunction;
80-
8178
/// Bookkeeping to ensure that useConformancesFrom{ObjectiveC,}Type() is
8279
/// only called once for each unique type, as an optimization.
8380
llvm::DenseSet<TypeBase *> usedConformancesFromTypes;
@@ -310,6 +307,10 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
310307
/// Emits the function definition for a given SILDeclRef.
311308
void emitFunctionDefinition(SILDeclRef constant, SILFunction *f);
312309

310+
/// Emit a function now, if it's externally usable or has been referenced in
311+
/// the current TU, or remember how to emit it later if not.
312+
void emitOrDelayFunction(SILDeclRef constant);
313+
313314
/// Generates code for the given closure expression and adds the
314315
/// SILFunction to the current SILModule under the name SILDeclRef(ce).
315316
SILFunction *emitClosure(AbstractClosureExpr *ce);
@@ -613,6 +614,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
613614
void tryEmitPropertyDescriptor(AbstractStorageDecl *decl);
614615

615616
private:
617+
/// The most recent declaration we considered for emission.
618+
SILDeclRef lastEmittedFunction;
619+
616620
/// Emit the deallocator for a class that uses the objc allocator.
617621
void emitObjCAllocatorDestructor(ClassDecl *cd, DestructorDecl *dd);
618622
};

0 commit comments

Comments
 (0)