Skip to content

Commit cc8344a

Browse files
committed
[SILGen] Remove astNode param from preEmitFunction
The AST node can be retrieved from the passed SILLocation.
1 parent ac63abc commit cc8344a

File tree

3 files changed

+30
-48
lines changed

3 files changed

+30
-48
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
681681
case SILDeclRef::Kind::Func: {
682682
auto *fd = cast<FuncDecl>(constant.getDecl());
683683

684-
preEmitFunction(constant, fd, f, fd);
684+
preEmitFunction(constant, f, fd);
685685
PrettyStackTraceSILFunction X("silgen emitFunction", f);
686686
SILGenFunction(*this, *f, fd).emitFunction(fd);
687687
postEmitFunction(constant, f);
@@ -694,12 +694,12 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
694694
if (decl->getDeclContext()->getSelfClassDecl() &&
695695
(decl->isDesignatedInit() ||
696696
decl->isObjC())) {
697-
preEmitFunction(constant, decl, f, decl);
697+
preEmitFunction(constant, f, decl);
698698
PrettyStackTraceSILFunction X("silgen emitConstructor", f);
699699
SILGenFunction(*this, *f, decl).emitClassConstructorAllocator(decl);
700700
postEmitFunction(constant, f);
701701
} else {
702-
preEmitFunction(constant, decl, f, decl);
702+
preEmitFunction(constant, f, decl);
703703
PrettyStackTraceSILFunction X("silgen emitConstructor", f);
704704
f->createProfiler(decl, constant, ForDefinition);
705705
SILGenFunction(*this, *f, decl).emitValueConstructor(decl);
@@ -712,7 +712,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
712712
auto *decl = cast<ConstructorDecl>(constant.getDecl());
713713
assert(decl->getDeclContext()->getSelfClassDecl());
714714

715-
preEmitFunction(constant, decl, f, decl);
715+
preEmitFunction(constant, f, decl);
716716
PrettyStackTraceSILFunction X("silgen constructor initializer", f);
717717
f->createProfiler(decl, constant, ForDefinition);
718718
SILGenFunction(*this, *f, decl).emitClassConstructorInitializer(decl);
@@ -729,7 +729,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
729729
case DefaultArgumentKind::Normal: {
730730
auto arg = param->getTypeCheckedDefaultExpr();
731731
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
732-
preEmitFunction(constant, arg, f, loc);
732+
preEmitFunction(constant, f, loc);
733733
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
734734
SILGenFunction SGF(*this, *f, initDC);
735735
SGF.emitGeneratorFunction(constant, arg);
@@ -740,7 +740,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
740740
case DefaultArgumentKind::StoredProperty: {
741741
auto arg = param->getStoredProperty();
742742
auto loc = RegularLocation::getAutoGeneratedLocation(arg);
743-
preEmitFunction(constant, arg, f, loc);
743+
preEmitFunction(constant, f, loc);
744744
PrettyStackTraceSILFunction X("silgen emitDefaultArgGenerator ", f);
745745
SILGenFunction SGF(*this, *f, initDC);
746746
SGF.emitGeneratorFunction(constant, arg);
@@ -778,7 +778,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
778778
}
779779

780780
auto loc = RegularLocation::getAutoGeneratedLocation(init);
781-
preEmitFunction(constant, init, f, loc);
781+
preEmitFunction(constant, f, loc);
782782
PrettyStackTraceSILFunction X("silgen emitStoredPropertyInitialization", f);
783783
f->createProfiler(init, constant, ForDefinition);
784784
SILGenFunction SGF(*this, *f, initDC);
@@ -802,7 +802,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
802802
auto *var = cast<VarDecl>(constant.getDecl());
803803

804804
auto loc = RegularLocation::getAutoGeneratedLocation(var);
805-
preEmitFunction(constant, var, f, loc);
805+
preEmitFunction(constant, f, loc);
806806
PrettyStackTraceSILFunction X(
807807
"silgen emitPropertyWrapperBackingInitializer", f);
808808
auto wrapperInfo = var->getPropertyWrapperBackingPropertyInfo();
@@ -825,7 +825,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
825825
auto *onceFunc = found->second.second;
826826

827827
auto loc = RegularLocation::getAutoGeneratedLocation(global);
828-
preEmitFunction(constant, global, f, loc);
828+
preEmitFunction(constant, f, loc);
829829
PrettyStackTraceSILFunction X("silgen emitGlobalAccessor", f);
830830
SILGenFunction(*this, *f, global->getDeclContext())
831831
.emitGlobalAccessor(global, onceToken, onceFunc);
@@ -837,7 +837,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
837837
auto *decl = cast<EnumElementDecl>(constant.getDecl());
838838

839839
auto loc = RegularLocation::getAutoGeneratedLocation(decl);
840-
preEmitFunction(constant, decl, f, loc);
840+
preEmitFunction(constant, f, loc);
841841
PrettyStackTraceSILFunction X("silgen enum constructor", f);
842842
SILGenFunction(*this, *f, decl->getDeclContext()).emitEnumConstructor(decl);
843843
postEmitFunction(constant, f);
@@ -846,7 +846,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
846846

847847
case SILDeclRef::Kind::Destroyer: {
848848
auto *dd = cast<DestructorDecl>(constant.getDecl());
849-
preEmitFunction(constant, dd, f, dd);
849+
preEmitFunction(constant, f, dd);
850850
PrettyStackTraceSILFunction X("silgen emitDestroyingDestructor", f);
851851
SILGenFunction(*this, *f, dd).emitDestroyingDestructor(dd);
852852
postEmitFunction(constant, f);
@@ -858,7 +858,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
858858
auto *cd = cast<ClassDecl>(dd->getDeclContext());
859859

860860
if (usesObjCAllocator(cd)) {
861-
preEmitFunction(constant, dd, f, dd);
861+
preEmitFunction(constant, f, dd);
862862
PrettyStackTraceSILFunction X("silgen emitDestructor -dealloc", f);
863863
f->createProfiler(dd, constant, ForDefinition);
864864
SILGenFunction(*this, *f, dd).emitObjCDestructor(constant);
@@ -867,7 +867,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
867867
}
868868

869869
auto loc = RegularLocation::getAutoGeneratedLocation(dd);
870-
preEmitFunction(constant, dd, f, loc);
870+
preEmitFunction(constant, f, loc);
871871
PrettyStackTraceSILFunction X("silgen emitDeallocatingDestructor", f);
872872
f->createProfiler(dd, constant, ForDefinition);
873873
SILGenFunction(*this, *f, dd).emitDeallocatingDestructor(dd);
@@ -878,7 +878,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
878878
case SILDeclRef::Kind::IVarInitializer: {
879879
auto *cd = cast<ClassDecl>(constant.getDecl());
880880
auto loc = RegularLocation::getAutoGeneratedLocation(cd);
881-
preEmitFunction(constant, cd, f, loc);
881+
preEmitFunction(constant, f, loc);
882882
PrettyStackTraceSILFunction X("silgen emitDestructor ivar initializer", f);
883883
SILGenFunction(*this, *f, cd).emitIVarInitializer(constant);
884884
postEmitFunction(constant, f);
@@ -888,7 +888,7 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
888888
case SILDeclRef::Kind::IVarDestroyer: {
889889
auto *cd = cast<ClassDecl>(constant.getDecl());
890890
auto loc = RegularLocation::getAutoGeneratedLocation(cd);
891-
preEmitFunction(constant, cd, f, loc);
891+
preEmitFunction(constant, f, loc);
892892
PrettyStackTraceSILFunction X("silgen emitDestructor ivar destroyer", f);
893893
SILGenFunction(*this, *f, cd).emitIVarDestroyer(constant);
894894
postEmitFunction(constant, f);
@@ -934,19 +934,8 @@ static void emitOrDelayFunction(SILGenModule &SGM,
934934
SGM.emitFunctionDefinition(constant, f);
935935
}
936936

937-
void SILGenModule::preEmitFunction(SILDeclRef constant,
938-
llvm::PointerUnion<ValueDecl *,
939-
Expr *> astNode,
940-
SILFunction *F,
937+
void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
941938
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-
950939
assert(F->empty() && "already emitted function?!");
951940

952941
if (F->getLoweredFunctionType()->isPolymorphic())
@@ -960,14 +949,12 @@ void SILGenModule::preEmitFunction(SILDeclRef constant,
960949
llvm::dbgs() << " : ";
961950
F->getLoweredType().print(llvm::dbgs());
962951
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());
970954
llvm::dbgs() << '\n';
955+
} else if (auto *expr = Loc.getAsASTNode<Expr>()) {
956+
expr->dump(llvm::dbgs());
957+
llvm::dbgs() << "\n";
971958
});
972959
}
973960

@@ -1220,7 +1207,7 @@ SILFunction *SILGenModule::emitClosure(AbstractClosureExpr *ce) {
12201207
// initializer of the containing type.
12211208
if (!f->isExternalDeclaration())
12221209
return f;
1223-
preEmitFunction(constant, ce, f, ce);
1210+
preEmitFunction(constant, f, ce);
12241211
PrettyStackTraceSILFunction X("silgen closureexpr", f);
12251212
SILGenFunction(*this, *f, ce).emitClosure(ce);
12261213
postEmitFunction(constant, f);
@@ -1421,7 +1408,7 @@ void SILGenModule::emitObjCMethodThunk(FuncDecl *method) {
14211408
// ObjC entry points are always externally usable, so can't be delay-emitted.
14221409

14231410
SILFunction *f = getFunction(thunk, ForDefinition);
1424-
preEmitFunction(thunk, method, f, method);
1411+
preEmitFunction(thunk, f, method);
14251412
PrettyStackTraceSILFunction X("silgen emitObjCMethodThunk", f);
14261413
f->setBare(IsBare);
14271414
f->setThunk(IsThunk);
@@ -1447,7 +1434,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
14471434
// delayed.
14481435
{
14491436
SILFunction *f = getFunction(getterRef, ForDefinition);
1450-
preEmitFunction(getterRef, prop, f, thunkBodyLoc);
1437+
preEmitFunction(getterRef, f, thunkBodyLoc);
14511438
PrettyStackTraceSILFunction X("silgen objc property getter thunk", f);
14521439
f->setBare(IsBare);
14531440
f->setThunk(IsThunk);
@@ -1463,7 +1450,7 @@ void SILGenModule::emitObjCPropertyMethodThunks(AbstractStorageDecl *prop) {
14631450
auto setterRef = SILDeclRef(setter, SILDeclRef::Kind::Func).asForeign();
14641451

14651452
SILFunction *f = getFunction(setterRef, ForDefinition);
1466-
preEmitFunction(setterRef, prop, f, thunkBodyLoc);
1453+
preEmitFunction(setterRef, f, thunkBodyLoc);
14671454
PrettyStackTraceSILFunction X("silgen objc property setter thunk", f);
14681455
f->setBare(IsBare);
14691456
f->setThunk(IsThunk);
@@ -1483,7 +1470,7 @@ void SILGenModule::emitObjCConstructorThunk(ConstructorDecl *constructor) {
14831470

14841471
SILFunction *f = getFunction(thunk, ForDefinition);
14851472
auto loc = RegularLocation::getAutoGeneratedLocation(constructor);
1486-
preEmitFunction(thunk, constructor, f, loc);
1473+
preEmitFunction(thunk, f, loc);
14871474
PrettyStackTraceSILFunction X("silgen objc constructor thunk", f);
14881475
f->setBare(IsBare);
14891476
f->setThunk(IsThunk);

lib/SILGen/SILGen.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
305305
/// Emits a thunk from a Swift function to the native Swift convention.
306306
void emitNativeToForeignThunk(SILDeclRef thunk);
307307

308-
void preEmitFunction(SILDeclRef constant,
309-
llvm::PointerUnion<ValueDecl *,
310-
Expr *> astNode,
311-
SILFunction *F,
312-
SILLocation L);
308+
void preEmitFunction(SILDeclRef constant, SILFunction *F, SILLocation L);
313309
void postEmitFunction(SILDeclRef constant, SILFunction *F);
314310

315311
/// Add a global variable to the SILModule.

lib/SILGen/SILGenThunk.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void SILGenModule::emitForeignToNativeThunk(SILDeclRef thunk) {
9595
f->setThunk(IsThunk);
9696
if (thunk.asForeign().isClangGenerated())
9797
f->setSerialized(IsSerializable);
98-
preEmitFunction(thunk, thunk.getDecl(), f, thunk.getDecl());
98+
preEmitFunction(thunk, f, thunk.getDecl());
9999
PrettyStackTraceSILFunction X("silgen emitForeignToNativeThunk", f);
100100
SILGenFunction(*this, *f, SwiftModule).emitForeignToNativeThunk(thunk);
101101
postEmitFunction(thunk, f);
@@ -107,10 +107,9 @@ void SILGenModule::emitNativeToForeignThunk(SILDeclRef thunk) {
107107

108108
SILFunction *f = getFunction(thunk, ForDefinition);
109109
if (thunk.hasDecl())
110-
preEmitFunction(thunk, thunk.getDecl(), f, thunk.getDecl());
110+
preEmitFunction(thunk, f, thunk.getDecl());
111111
else
112-
preEmitFunction(thunk, thunk.getAbstractClosureExpr(), f,
113-
thunk.getAbstractClosureExpr());
112+
preEmitFunction(thunk, f, thunk.getAbstractClosureExpr());
114113
PrettyStackTraceSILFunction X("silgen emitNativeToForeignThunk", f);
115114
f->setBare(IsBare);
116115
f->setThunk(IsThunk);

0 commit comments

Comments
 (0)