@@ -681,7 +681,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
681
681
case SILDeclRef::Kind::Func: {
682
682
auto *fd = cast<FuncDecl>(constant.getDecl ());
683
683
684
- preEmitFunction (constant, fd, f, fd);
684
+ preEmitFunction (constant, f, fd);
685
685
PrettyStackTraceSILFunction X (" silgen emitFunction" , f);
686
686
SILGenFunction (*this , *f, fd).emitFunction (fd);
687
687
postEmitFunction (constant, f);
@@ -694,12 +694,12 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
694
694
if (decl->getDeclContext ()->getSelfClassDecl () &&
695
695
(decl->isDesignatedInit () ||
696
696
decl->isObjC ())) {
697
- preEmitFunction (constant, decl, f, decl);
697
+ preEmitFunction (constant, f, decl);
698
698
PrettyStackTraceSILFunction X (" silgen emitConstructor" , f);
699
699
SILGenFunction (*this , *f, decl).emitClassConstructorAllocator (decl);
700
700
postEmitFunction (constant, f);
701
701
} else {
702
- preEmitFunction (constant, decl, f, decl);
702
+ preEmitFunction (constant, f, decl);
703
703
PrettyStackTraceSILFunction X (" silgen emitConstructor" , f);
704
704
f->createProfiler (decl, constant, ForDefinition);
705
705
SILGenFunction (*this , *f, decl).emitValueConstructor (decl);
@@ -712,7 +712,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
712
712
auto *decl = cast<ConstructorDecl>(constant.getDecl ());
713
713
assert (decl->getDeclContext ()->getSelfClassDecl ());
714
714
715
- preEmitFunction (constant, decl, f, decl);
715
+ preEmitFunction (constant, f, decl);
716
716
PrettyStackTraceSILFunction X (" silgen constructor initializer" , f);
717
717
f->createProfiler (decl, constant, ForDefinition);
718
718
SILGenFunction (*this , *f, decl).emitClassConstructorInitializer (decl);
@@ -729,7 +729,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
729
729
case DefaultArgumentKind::Normal: {
730
730
auto arg = param->getTypeCheckedDefaultExpr ();
731
731
auto loc = RegularLocation::getAutoGeneratedLocation (arg);
732
- preEmitFunction (constant, arg, f, loc);
732
+ preEmitFunction (constant, f, loc);
733
733
PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
734
734
SILGenFunction SGF (*this , *f, initDC);
735
735
SGF.emitGeneratorFunction (constant, arg);
@@ -740,7 +740,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
740
740
case DefaultArgumentKind::StoredProperty: {
741
741
auto arg = param->getStoredProperty ();
742
742
auto loc = RegularLocation::getAutoGeneratedLocation (arg);
743
- preEmitFunction (constant, arg, f, loc);
743
+ preEmitFunction (constant, f, loc);
744
744
PrettyStackTraceSILFunction X (" silgen emitDefaultArgGenerator " , f);
745
745
SILGenFunction SGF (*this , *f, initDC);
746
746
SGF.emitGeneratorFunction (constant, arg);
@@ -778,7 +778,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
778
778
}
779
779
780
780
auto loc = RegularLocation::getAutoGeneratedLocation (init);
781
- preEmitFunction (constant, init, f, loc);
781
+ preEmitFunction (constant, f, loc);
782
782
PrettyStackTraceSILFunction X (" silgen emitStoredPropertyInitialization" , f);
783
783
f->createProfiler (init, constant, ForDefinition);
784
784
SILGenFunction SGF (*this , *f, initDC);
@@ -802,7 +802,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
802
802
auto *var = cast<VarDecl>(constant.getDecl ());
803
803
804
804
auto loc = RegularLocation::getAutoGeneratedLocation (var);
805
- preEmitFunction (constant, var, f, loc);
805
+ preEmitFunction (constant, f, loc);
806
806
PrettyStackTraceSILFunction X (
807
807
" silgen emitPropertyWrapperBackingInitializer" , f);
808
808
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo ();
@@ -825,7 +825,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
825
825
auto *onceFunc = found->second .second ;
826
826
827
827
auto loc = RegularLocation::getAutoGeneratedLocation (global);
828
- preEmitFunction (constant, global, f, loc);
828
+ preEmitFunction (constant, f, loc);
829
829
PrettyStackTraceSILFunction X (" silgen emitGlobalAccessor" , f);
830
830
SILGenFunction (*this , *f, global->getDeclContext ())
831
831
.emitGlobalAccessor (global, onceToken, onceFunc);
@@ -837,7 +837,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
837
837
auto *decl = cast<EnumElementDecl>(constant.getDecl ());
838
838
839
839
auto loc = RegularLocation::getAutoGeneratedLocation (decl);
840
- preEmitFunction (constant, decl, f, loc);
840
+ preEmitFunction (constant, f, loc);
841
841
PrettyStackTraceSILFunction X (" silgen enum constructor" , f);
842
842
SILGenFunction (*this , *f, decl->getDeclContext ()).emitEnumConstructor (decl);
843
843
postEmitFunction (constant, f);
@@ -846,7 +846,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
846
846
847
847
case SILDeclRef::Kind::Destroyer: {
848
848
auto *dd = cast<DestructorDecl>(constant.getDecl ());
849
- preEmitFunction (constant, dd, f, dd);
849
+ preEmitFunction (constant, f, dd);
850
850
PrettyStackTraceSILFunction X (" silgen emitDestroyingDestructor" , f);
851
851
SILGenFunction (*this , *f, dd).emitDestroyingDestructor (dd);
852
852
postEmitFunction (constant, f);
@@ -858,7 +858,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
858
858
auto *cd = cast<ClassDecl>(dd->getDeclContext ());
859
859
860
860
if (usesObjCAllocator (cd)) {
861
- preEmitFunction (constant, dd, f, dd);
861
+ preEmitFunction (constant, f, dd);
862
862
PrettyStackTraceSILFunction X (" silgen emitDestructor -dealloc" , f);
863
863
f->createProfiler (dd, constant, ForDefinition);
864
864
SILGenFunction (*this , *f, dd).emitObjCDestructor (constant);
@@ -867,7 +867,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
867
867
}
868
868
869
869
auto loc = RegularLocation::getAutoGeneratedLocation (dd);
870
- preEmitFunction (constant, dd, f, loc);
870
+ preEmitFunction (constant, f, loc);
871
871
PrettyStackTraceSILFunction X (" silgen emitDeallocatingDestructor" , f);
872
872
f->createProfiler (dd, constant, ForDefinition);
873
873
SILGenFunction (*this , *f, dd).emitDeallocatingDestructor (dd);
@@ -878,7 +878,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
878
878
case SILDeclRef::Kind::IVarInitializer: {
879
879
auto *cd = cast<ClassDecl>(constant.getDecl ());
880
880
auto loc = RegularLocation::getAutoGeneratedLocation (cd);
881
- preEmitFunction (constant, cd, f, loc);
881
+ preEmitFunction (constant, f, loc);
882
882
PrettyStackTraceSILFunction X (" silgen emitDestructor ivar initializer" , f);
883
883
SILGenFunction (*this , *f, cd).emitIVarInitializer (constant);
884
884
postEmitFunction (constant, f);
@@ -888,7 +888,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
888
888
case SILDeclRef::Kind::IVarDestroyer: {
889
889
auto *cd = cast<ClassDecl>(constant.getDecl ());
890
890
auto loc = RegularLocation::getAutoGeneratedLocation (cd);
891
- preEmitFunction (constant, cd, f, loc);
891
+ preEmitFunction (constant, f, loc);
892
892
PrettyStackTraceSILFunction X (" silgen emitDestructor ivar destroyer" , f);
893
893
SILGenFunction (*this , *f, cd).emitIVarDestroyer (constant);
894
894
postEmitFunction (constant, f);
@@ -934,19 +934,8 @@ static void emitOrDelayFunction(SILGenModule &SGM,
934
934
SGM.emitFunctionDefinition (constant, f);
935
935
}
936
936
937
- void SILGenModule::preEmitFunction (SILDeclRef constant,
938
- llvm::PointerUnion<ValueDecl *,
939
- Expr *> astNode,
940
- SILFunction *F,
937
+ void SILGenModule::preEmitFunction (SILDeclRef constant, SILFunction *F,
941
938
SILLocation Loc) {
942
- // By default, use the astNode to create the location.
943
- if (Loc.isNull ()) {
944
- if (auto *decl = astNode.get <ValueDecl *>())
945
- Loc = RegularLocation (decl);
946
- else
947
- Loc = RegularLocation (astNode.get <Expr *>());
948
- }
949
-
950
939
assert (F->empty () && " already emitted function?!" );
951
940
952
941
if (F->getLoweredFunctionType ()->isPolymorphic ())
@@ -960,14 +949,12 @@ void SILGenModule::preEmitFunction(SILDeclRef constant,
960
949
llvm::dbgs () << " : " ;
961
950
F->getLoweredType ().print (llvm::dbgs ());
962
951
llvm::dbgs () << ' \n ' ;
963
- if (astNode) {
964
- if (auto *decl = astNode.dyn_cast <ValueDecl *>()) {
965
- decl->dump (llvm::dbgs ());
966
- } else {
967
- astNode.get <Expr *>()->dump (llvm::dbgs ());
968
- llvm::dbgs () << " \n " ;
969
- }
952
+ if (auto *decl = Loc.getAsASTNode <ValueDecl>()) {
953
+ decl->dump (llvm::dbgs ());
970
954
llvm::dbgs () << ' \n ' ;
955
+ } else if (auto *expr = Loc.getAsASTNode <Expr>()) {
956
+ expr->dump (llvm::dbgs ());
957
+ llvm::dbgs () << " \n " ;
971
958
});
972
959
}
973
960
@@ -1220,7 +1207,7 @@ SILFunction *SILGenModule::emitClosure(AbstractClosureExpr *ce) {
1220
1207
// initializer of the containing type.
1221
1208
if (!f->isExternalDeclaration ())
1222
1209
return f;
1223
- preEmitFunction (constant, ce, f, ce);
1210
+ preEmitFunction (constant, f, ce);
1224
1211
PrettyStackTraceSILFunction X (" silgen closureexpr" , f);
1225
1212
SILGenFunction (*this , *f, ce).emitClosure (ce);
1226
1213
postEmitFunction (constant, f);
@@ -1421,7 +1408,7 @@ void SILGenModule::emitObjCMethodThunk(FuncDecl *method) {
1421
1408
// ObjC entry points are always externally usable, so can't be delay-emitted.
1422
1409
1423
1410
SILFunction *f = getFunction (thunk, ForDefinition);
1424
- preEmitFunction (thunk, method, f, method);
1411
+ preEmitFunction (thunk, f, method);
1425
1412
PrettyStackTraceSILFunction X (" silgen emitObjCMethodThunk" , f);
1426
1413
f->setBare (IsBare);
1427
1414
f->setThunk (IsThunk);
@@ -1447,7 +1434,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
1447
1434
// delayed.
1448
1435
{
1449
1436
SILFunction *f = getFunction (getterRef, ForDefinition);
1450
- preEmitFunction (getterRef, prop, f, thunkBodyLoc);
1437
+ preEmitFunction (getterRef, f, thunkBodyLoc);
1451
1438
PrettyStackTraceSILFunction X (" silgen objc property getter thunk" , f);
1452
1439
f->setBare (IsBare);
1453
1440
f->setThunk (IsThunk);
@@ -1463,7 +1450,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
1463
1450
auto setterRef = SILDeclRef (setter, SILDeclRef::Kind::Func).asForeign ();
1464
1451
1465
1452
SILFunction *f = getFunction (setterRef, ForDefinition);
1466
- preEmitFunction (setterRef, prop, f, thunkBodyLoc);
1453
+ preEmitFunction (setterRef, f, thunkBodyLoc);
1467
1454
PrettyStackTraceSILFunction X (" silgen objc property setter thunk" , f);
1468
1455
f->setBare (IsBare);
1469
1456
f->setThunk (IsThunk);
@@ -1483,7 +1470,7 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
1483
1470
1484
1471
SILFunction *f = getFunction (thunk, ForDefinition);
1485
1472
auto loc = RegularLocation::getAutoGeneratedLocation (constructor);
1486
- preEmitFunction (thunk, constructor, f, loc);
1473
+ preEmitFunction (thunk, f, loc);
1487
1474
PrettyStackTraceSILFunction X (" silgen objc constructor thunk" , f);
1488
1475
f->setBare (IsBare);
1489
1476
f->setThunk (IsThunk);
0 commit comments