@@ -676,17 +676,15 @@ bool SILGenModule::hasFunction(SILDeclRef constant) {
676
676
677
677
void SILGenModule::visitFuncDecl (FuncDecl *fd) { emitFunction (fd); }
678
678
679
- static void emitDelayedFunction (SILGenModule &SGM,
680
- SILDeclRef constant,
681
- SILFunction *f) {
679
+ void SILGenModule::emitFunctionDefinition (SILDeclRef constant, SILFunction *f) {
682
680
switch (constant.kind ) {
683
681
case SILDeclRef::Kind::Func: {
684
682
auto *fd = cast<FuncDecl>(constant.getDecl ());
685
683
686
- SGM. preEmitFunction (constant, fd, f, fd);
684
+ preEmitFunction (constant, fd, f, fd);
687
685
PrettyStackTraceSILFunction X (" silgen emitFunction" , f);
688
- SILGenFunction (SGM , *f, fd).emitFunction (fd);
689
- SGM. postEmitFunction (constant, f);
686
+ SILGenFunction (* this , *f, fd).emitFunction (fd);
687
+ postEmitFunction (constant, f);
690
688
break ;
691
689
}
692
690
@@ -696,16 +694,16 @@ static void emitDelayedFunction(SILGenModule &SGM,
696
694
if (decl->getDeclContext ()->getSelfClassDecl () &&
697
695
(decl->isDesignatedInit () ||
698
696
decl->isObjC ())) {
699
- SGM. preEmitFunction (constant, decl, f, decl);
697
+ preEmitFunction (constant, decl, f, decl);
700
698
PrettyStackTraceSILFunction X (" silgen emitConstructor" , f);
701
- SILGenFunction (SGM , *f, decl).emitClassConstructorAllocator (decl);
702
- SGM. postEmitFunction (constant, f);
699
+ SILGenFunction (* this , *f, decl).emitClassConstructorAllocator (decl);
700
+ postEmitFunction (constant, f);
703
701
} else {
704
- SGM. preEmitFunction (constant, decl, f, decl);
702
+ preEmitFunction (constant, decl, f, decl);
705
703
PrettyStackTraceSILFunction X (" silgen emitConstructor" , f);
706
704
f->createProfiler (decl, constant, ForDefinition);
707
- SILGenFunction (SGM , *f, decl).emitValueConstructor (decl);
708
- SGM. postEmitFunction (constant, f);
705
+ SILGenFunction (* this , *f, decl).emitValueConstructor (decl);
706
+ postEmitFunction (constant, f);
709
707
}
710
708
break ;
711
709
}
@@ -714,11 +712,11 @@ static void emitDelayedFunction(SILGenModule &SGM,
714
712
auto *decl = cast<ConstructorDecl>(constant.getDecl ());
715
713
assert (decl->getDeclContext ()->getSelfClassDecl ());
716
714
717
- SGM. preEmitFunction (constant, decl, f, decl);
715
+ preEmitFunction (constant, decl, f, decl);
718
716
PrettyStackTraceSILFunction X (" silgen constructor initializer" , f);
719
717
f->createProfiler (decl, constant, ForDefinition);
720
- SILGenFunction (SGM , *f, decl).emitClassConstructorInitializer (decl);
721
- SGM. postEmitFunction (constant, f);
718
+ SILGenFunction (* this , *f, decl).emitClassConstructorInitializer (decl);
719
+ postEmitFunction (constant, f);
722
720
break ;
723
721
}
724
722
@@ -731,22 +729,22 @@ static void emitDelayedFunction(SILGenModule &SGM,
731
729
case DefaultArgumentKind::Normal: {
732
730
auto arg = param->getTypeCheckedDefaultExpr ();
733
731
auto loc = RegularLocation::getAutoGeneratedLocation (arg);
734
- SGM. preEmitFunction (constant, arg, f, loc);
732
+ preEmitFunction (constant, arg, f, loc);
735
733
PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
736
- SILGenFunction SGF (SGM , *f, initDC);
734
+ SILGenFunction SGF (* this , *f, initDC);
737
735
SGF.emitGeneratorFunction (constant, arg);
738
- SGM. postEmitFunction (constant, f);
736
+ postEmitFunction (constant, f);
739
737
break ;
740
738
}
741
739
742
740
case DefaultArgumentKind::StoredProperty: {
743
741
auto arg = param->getStoredProperty ();
744
742
auto loc = RegularLocation::getAutoGeneratedLocation (arg);
745
- SGM. preEmitFunction (constant, arg, f, loc);
743
+ preEmitFunction (constant, arg, f, loc);
746
744
PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
747
- SILGenFunction SGF (SGM , *f, initDC);
745
+ SILGenFunction SGF (* this , *f, initDC);
748
746
SGF.emitGeneratorFunction (constant, arg);
749
- SGM. postEmitFunction (constant, f);
747
+ postEmitFunction (constant, f);
750
748
break ;
751
749
}
752
750
@@ -780,78 +778,122 @@ static void emitDelayedFunction(SILGenModule &SGM,
780
778
}
781
779
782
780
auto loc = RegularLocation::getAutoGeneratedLocation (init);
783
- SGM. preEmitFunction (constant, init, f, loc);
781
+ preEmitFunction (constant, init, f, loc);
784
782
PrettyStackTraceSILFunction X (" silgen emitStoredPropertyInitialization" , f);
785
783
f->createProfiler (init, constant, ForDefinition);
786
- SILGenFunction SGF (SGM , *f, initDC);
784
+ SILGenFunction SGF (* this , *f, initDC);
787
785
788
786
// If this is a stored property initializer inside a type at global scope,
789
787
// it may close over a global variable. If we're emitting top-level code,
790
788
// then emit a "mark_function_escape" that lists the captured global
791
789
// variables so that definite initialization can reason about this
792
790
// escape point.
793
- if (!var->getDeclContext ()->isLocalContext () &&
794
- SGM. TopLevelSGF && SGM. TopLevelSGF ->B .hasValidInsertionPoint ()) {
795
- SGM. emitMarkFunctionEscapeForTopLevelCodeGlobals (var, captureInfo);
791
+ if (!var->getDeclContext ()->isLocalContext () && TopLevelSGF &&
792
+ TopLevelSGF->B .hasValidInsertionPoint ()) {
793
+ emitMarkFunctionEscapeForTopLevelCodeGlobals (var, captureInfo);
796
794
}
797
795
798
796
SGF.emitGeneratorFunction (constant, init, /* EmitProfilerIncrement=*/ true );
799
- SGM. postEmitFunction (constant, f);
797
+ postEmitFunction (constant, f);
800
798
break ;
801
799
}
802
800
803
801
case SILDeclRef::Kind::PropertyWrapperBackingInitializer: {
804
802
auto *var = cast<VarDecl>(constant.getDecl ());
805
803
806
804
auto loc = RegularLocation::getAutoGeneratedLocation (var);
807
- SGM. preEmitFunction (constant, var, f, loc);
805
+ preEmitFunction (constant, var, f, loc);
808
806
PrettyStackTraceSILFunction X (
809
807
" silgen emitPropertyWrapperBackingInitializer" , f);
810
808
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo ();
811
809
assert (wrapperInfo.initializeFromOriginal );
812
810
f->createProfiler (wrapperInfo.initializeFromOriginal , constant,
813
811
ForDefinition);
814
812
auto varDC = var->getInnermostDeclContext ();
815
- SILGenFunction SGF (SGM , *f, varDC);
813
+ SILGenFunction SGF (* this , *f, varDC);
816
814
SGF.emitGeneratorFunction (constant, wrapperInfo.initializeFromOriginal );
817
- SGM. postEmitFunction (constant, f);
815
+ postEmitFunction (constant, f);
818
816
break ;
819
817
}
820
818
821
819
case SILDeclRef::Kind::GlobalAccessor: {
822
820
auto *global = cast<VarDecl>(constant.getDecl ());
823
- auto found = SGM. delayedGlobals .find (global);
824
- assert (found != SGM. delayedGlobals .end ());
821
+ auto found = delayedGlobals.find (global);
822
+ assert (found != delayedGlobals.end ());
825
823
826
824
auto *onceToken = found->second .first ;
827
825
auto *onceFunc = found->second .second ;
828
826
829
827
auto loc = RegularLocation::getAutoGeneratedLocation (global);
830
- SGM. preEmitFunction (constant, global, f, loc);
828
+ preEmitFunction (constant, global, f, loc);
831
829
PrettyStackTraceSILFunction X (" silgen emitGlobalAccessor" , f);
832
- SILGenFunction (SGM , *f, global->getDeclContext ())
830
+ SILGenFunction (* this , *f, global->getDeclContext ())
833
831
.emitGlobalAccessor (global, onceToken, onceFunc);
834
- SGM. postEmitFunction (constant, f);
832
+ postEmitFunction (constant, f);
835
833
break ;
836
834
}
837
835
838
836
case SILDeclRef::Kind::EnumElement: {
839
837
auto *decl = cast<EnumElementDecl>(constant.getDecl ());
840
838
841
839
auto loc = RegularLocation::getAutoGeneratedLocation (decl);
842
- SGM. preEmitFunction (constant, decl, f, loc);
840
+ preEmitFunction (constant, decl, f, loc);
843
841
PrettyStackTraceSILFunction X (" silgen enum constructor" , f);
844
- SILGenFunction (SGM , *f, decl->getDeclContext ()).emitEnumConstructor (decl);
845
- SGM. postEmitFunction (constant, f);
842
+ SILGenFunction (* this , *f, decl->getDeclContext ()).emitEnumConstructor (decl);
843
+ postEmitFunction (constant, f);
846
844
break ;
847
845
}
848
846
849
- case SILDeclRef::Kind::Destroyer:
850
- case SILDeclRef::Kind::Deallocator:
851
- case SILDeclRef::Kind::IVarInitializer:
852
- case SILDeclRef::Kind::IVarDestroyer:
853
- llvm_unreachable (" Cannot emit as a delayed function" );
854
- break ;
847
+ case SILDeclRef::Kind::Destroyer: {
848
+ auto *dd = cast<DestructorDecl>(constant.getDecl ());
849
+ preEmitFunction (constant, dd, f, dd);
850
+ PrettyStackTraceSILFunction X (" silgen emitDestroyingDestructor" , f);
851
+ SILGenFunction (*this , *f, dd).emitDestroyingDestructor (dd);
852
+ postEmitFunction (constant, f);
853
+ return ;
854
+ }
855
+
856
+ case SILDeclRef::Kind::Deallocator: {
857
+ auto *dd = cast<DestructorDecl>(constant.getDecl ());
858
+ auto *cd = cast<ClassDecl>(dd->getDeclContext ());
859
+
860
+ if (usesObjCAllocator (cd)) {
861
+ preEmitFunction (constant, dd, f, dd);
862
+ PrettyStackTraceSILFunction X (" silgen emitDestructor -dealloc" , f);
863
+ f->createProfiler (dd, constant, ForDefinition);
864
+ SILGenFunction (*this , *f, dd).emitObjCDestructor (constant);
865
+ postEmitFunction (constant, f);
866
+ return ;
867
+ }
868
+
869
+ auto loc = RegularLocation::getAutoGeneratedLocation (dd);
870
+ preEmitFunction (constant, dd, f, loc);
871
+ PrettyStackTraceSILFunction X (" silgen emitDeallocatingDestructor" , f);
872
+ f->createProfiler (dd, constant, ForDefinition);
873
+ SILGenFunction (*this , *f, dd).emitDeallocatingDestructor (dd);
874
+ postEmitFunction (constant, f);
875
+ return ;
876
+ }
877
+
878
+ case SILDeclRef::Kind::IVarInitializer: {
879
+ auto *cd = cast<ClassDecl>(constant.getDecl ());
880
+ auto loc = RegularLocation::getAutoGeneratedLocation (cd);
881
+ preEmitFunction (constant, cd, f, loc);
882
+ PrettyStackTraceSILFunction X (" silgen emitDestructor ivar initializer" , f);
883
+ SILGenFunction (*this , *f, cd).emitIVarInitializer (constant);
884
+ postEmitFunction (constant, f);
885
+ return ;
886
+ }
887
+
888
+ case SILDeclRef::Kind::IVarDestroyer: {
889
+ auto *cd = cast<ClassDecl>(constant.getDecl ());
890
+ auto loc = RegularLocation::getAutoGeneratedLocation (cd);
891
+ preEmitFunction (constant, cd, f, loc);
892
+ PrettyStackTraceSILFunction X (" silgen emitDestructor ivar destroyer" , f);
893
+ SILGenFunction (*this , *f, cd).emitIVarDestroyer (constant);
894
+ postEmitFunction (constant, f);
895
+ return ;
896
+ }
855
897
}
856
898
}
857
899
@@ -889,7 +931,7 @@ static void emitOrDelayFunction(SILGenModule &SGM,
889
931
return ;
890
932
}
891
933
892
- emitDelayedFunction ( SGM, constant, f);
934
+ SGM. emitFunctionDefinition ( constant, f);
893
935
}
894
936
895
937
void SILGenModule::preEmitFunction (SILDeclRef constant,
@@ -1232,12 +1274,7 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
1232
1274
// Destructors are a necessary part of class metadata, so can't be delayed.
1233
1275
if (dd->hasBody ()) {
1234
1276
SILDeclRef dealloc (dd, SILDeclRef::Kind::Deallocator);
1235
- SILFunction *f = getFunction (dealloc, ForDefinition);
1236
- preEmitFunction (dealloc, dd, f, dd);
1237
- PrettyStackTraceSILFunction X (" silgen emitDestructor -dealloc" , f);
1238
- f->createProfiler (dd, dealloc, ForDefinition);
1239
- SILGenFunction (*this , *f, dd).emitObjCDestructor (dealloc);
1240
- postEmitFunction (dealloc, f);
1277
+ emitFunctionDefinition (dealloc, getFunction (dealloc, ForDefinition));
1241
1278
}
1242
1279
1243
1280
// Emit the Objective-C -dealloc entry point if it has
@@ -1249,24 +1286,16 @@ void SILGenModule::emitObjCAllocatorDestructor(ClassDecl *cd,
1249
1286
if (requiresIVarInitialization (*this , cd)) {
1250
1287
auto ivarInitializer = SILDeclRef (cd, SILDeclRef::Kind::IVarInitializer)
1251
1288
.asForeign ();
1252
- SILFunction *f = getFunction (ivarInitializer, ForDefinition);
1253
- auto loc = RegularLocation::getAutoGeneratedLocation (dd);
1254
- preEmitFunction (ivarInitializer, dd, f, loc);
1255
- PrettyStackTraceSILFunction X (" silgen emitDestructor ivar initializer" , f);
1256
- SILGenFunction (*this , *f, cd).emitIVarInitializer (ivarInitializer);
1257
- postEmitFunction (ivarInitializer, f);
1289
+ emitFunctionDefinition (ivarInitializer,
1290
+ getFunction (ivarInitializer, ForDefinition));
1258
1291
}
1259
1292
1260
1293
// Emit the ivar destroyer, if needed.
1261
1294
if (hasNonTrivialIVars (cd)) {
1262
1295
auto ivarDestroyer = SILDeclRef (cd, SILDeclRef::Kind::IVarDestroyer)
1263
1296
.asForeign ();
1264
- SILFunction *f = getFunction (ivarDestroyer, ForDefinition);
1265
- auto loc = RegularLocation::getAutoGeneratedLocation (dd);
1266
- preEmitFunction (ivarDestroyer, dd, f, loc);
1267
- PrettyStackTraceSILFunction X (" silgen emitDestructor ivar destroyer" , f);
1268
- SILGenFunction (*this , *f, cd).emitIVarDestroyer (ivarDestroyer);
1269
- postEmitFunction (ivarDestroyer, f);
1297
+ emitFunctionDefinition (ivarDestroyer,
1298
+ getFunction (ivarDestroyer, ForDefinition));
1270
1299
}
1271
1300
}
1272
1301
@@ -1276,12 +1305,8 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
1276
1305
// Emit the ivar destroyer, if needed.
1277
1306
if (requiresIVarDestroyer (cd)) {
1278
1307
SILDeclRef ivarDestroyer (cd, SILDeclRef::Kind::IVarDestroyer);
1279
- SILFunction *f = getFunction (ivarDestroyer, ForDefinition);
1280
- auto loc = RegularLocation::getAutoGeneratedLocation (dd);
1281
- preEmitFunction (ivarDestroyer, dd, f, loc);
1282
- PrettyStackTraceSILFunction X (" silgen emitDestructor ivar destroyer" , f);
1283
- SILGenFunction (*this , *f, dd).emitIVarDestroyer (ivarDestroyer);
1284
- postEmitFunction (ivarDestroyer, f);
1308
+ emitFunctionDefinition (ivarDestroyer,
1309
+ getFunction (ivarDestroyer, ForDefinition));
1285
1310
}
1286
1311
1287
1312
// If the class would use the Objective-C allocator, only emit -dealloc.
@@ -1294,24 +1319,14 @@ void SILGenModule::emitDestructor(ClassDecl *cd, DestructorDecl *dd) {
1294
1319
// Destructors are a necessary part of class metadata, so can't be delayed.
1295
1320
if (dd->hasBody ()) {
1296
1321
SILDeclRef destroyer (dd, SILDeclRef::Kind::Destroyer);
1297
- SILFunction *f = getFunction (destroyer, ForDefinition);
1298
- RegularLocation loc (dd);
1299
- preEmitFunction (destroyer, dd, f, loc);
1300
- PrettyStackTraceSILFunction X (" silgen emitDestroyingDestructor" , f);
1301
- SILGenFunction (*this , *f, dd).emitDestroyingDestructor (dd);
1302
- postEmitFunction (destroyer, f);
1322
+ emitFunctionDefinition (destroyer, getFunction (destroyer, ForDefinition));
1303
1323
}
1304
1324
1305
1325
// Emit the deallocating destructor.
1306
1326
{
1307
1327
SILDeclRef deallocator (dd, SILDeclRef::Kind::Deallocator);
1308
- SILFunction *f = getFunction (deallocator, ForDefinition);
1309
- auto loc = RegularLocation::getAutoGeneratedLocation (dd);
1310
- preEmitFunction (deallocator, dd, f, loc);
1311
- PrettyStackTraceSILFunction X (" silgen emitDeallocatingDestructor" , f);
1312
- f->createProfiler (dd, deallocator, ForDefinition);
1313
- SILGenFunction (*this , *f, dd).emitDeallocatingDestructor (dd);
1314
- postEmitFunction (deallocator, f);
1328
+ emitFunctionDefinition (deallocator,
1329
+ getFunction (deallocator, ForDefinition));
1315
1330
}
1316
1331
}
1317
1332
@@ -1910,8 +1925,8 @@ class SILGenModuleRAII {
1910
1925
|| !SGM.pendingConformances .empty ()) {
1911
1926
while (!SGM.forcedFunctions .empty ()) {
1912
1927
auto &front = SGM.forcedFunctions .front ();
1913
- emitDelayedFunction ( SGM, front,
1914
- SGM.getEmittedFunction (front, ForDefinition));
1928
+ SGM. emitFunctionDefinition (
1929
+ front, SGM.getEmittedFunction (front, ForDefinition));
1915
1930
SGM.forcedFunctions .pop_front ();
1916
1931
}
1917
1932
while (!SGM.pendingConformances .empty ()) {
0 commit comments