Skip to content

Commit 60c947f

Browse files
committed
SILGen: Simplify prepareEpilog() utility method
1 parent 998f2de commit 60c947f

File tree

6 files changed

+16
-22
lines changed

6 files changed

+16
-22
lines changed

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,7 +1536,7 @@ class SourceFileScope {
15361536
sgm.TopLevelSGF = new SILGenFunction(sgm, *toplevel, sf);
15371537
sgm.TopLevelSGF->MagicFunctionName = sgm.SwiftModule->getName();
15381538
auto moduleCleanupLoc = CleanupLocation::getModuleCleanupLocation();
1539-
sgm.TopLevelSGF->prepareEpilog(Type(), true, moduleCleanupLoc);
1539+
sgm.TopLevelSGF->prepareEpilog(false, true, moduleCleanupLoc);
15401540

15411541
// Create the argc and argv arguments.
15421542
auto prologueLoc = RegularLocation::getModuleLocation();

lib/SILGen/SILGenConstructor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
281281
// Create a basic block to jump to for the implicit 'self' return.
282282
// We won't emit this until after we've emitted the body.
283283
// The epilog takes a void return because the return of 'self' is implicit.
284-
prepareEpilog(Type(), ctor->hasThrows(), CleanupLocation(ctor));
284+
prepareEpilog(false, ctor->hasThrows(), CleanupLocation(ctor));
285285

286286
// If the constructor can fail, set up an alternative epilog for constructor
287287
// failure.
@@ -659,7 +659,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
659659

660660
// Create a basic block to jump to for the implicit 'self' return.
661661
// We won't emit the block until after we've emitted the body.
662-
prepareEpilog(Type(), ctor->hasThrows(),
662+
prepareEpilog(false, ctor->hasThrows(),
663663
CleanupLocation::get(endOfInitLoc));
664664

665665
auto resultType = ctor->mapTypeIntoContext(ctor->getResultInterfaceType());
@@ -1000,7 +1000,7 @@ void SILGenFunction::emitIVarInitializer(SILDeclRef ivarInitializer) {
10001000
VarLocs[selfDecl] = VarLoc::get(selfArg);
10011001

10021002
auto cleanupLoc = CleanupLocation::get(loc);
1003-
prepareEpilog(TupleType::getEmpty(getASTContext()), false, cleanupLoc);
1003+
prepareEpilog(false, false, cleanupLoc);
10041004

10051005
// Emit the initializers.
10061006
emitMemberInitializers(cd, selfDecl, cd);

lib/SILGen/SILGenDestructor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void SILGenFunction::emitDestroyingDestructor(DestructorDecl *dd) {
3333
// Create a basic block to jump to for the implicit destruction behavior
3434
// of releasing the elements and calling the superclass destructor.
3535
// We won't actually emit the block until we finish with the destructor body.
36-
prepareEpilog(Type(), false, CleanupLocation::get(Loc));
36+
prepareEpilog(false, false, CleanupLocation::get(Loc));
3737

3838
emitProfilerIncrement(dd->getBody());
3939
// Emit the destructor body.
@@ -166,7 +166,7 @@ void SILGenFunction::emitIVarDestroyer(SILDeclRef ivarDestroyer) {
166166
emitSelfDecl(cd->getDestructor()->getImplicitSelfDecl()));
167167

168168
auto cleanupLoc = CleanupLocation::get(loc);
169-
prepareEpilog(TupleType::getEmpty(getASTContext()), false, cleanupLoc);
169+
prepareEpilog(false, false, cleanupLoc);
170170
{
171171
Scope S(*this, cleanupLoc);
172172
emitClassMemberDestruction(selfValue, cd, cleanupLoc);
@@ -206,7 +206,7 @@ void SILGenFunction::emitObjCDestructor(SILDeclRef dtor) {
206206
// Create a basic block to jump to for the implicit destruction behavior
207207
// of releasing the elements and calling the superclass destructor.
208208
// We won't actually emit the block until we finish with the destructor body.
209-
prepareEpilog(Type(), false, CleanupLocation::get(loc));
209+
prepareEpilog(false, false, CleanupLocation::get(loc));
210210

211211
emitProfilerIncrement(dd->getBody());
212212
// Emit the destructor body.

lib/SILGen/SILGenEpilog.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
using namespace swift;
1919
using namespace Lowering;
2020

21-
void SILGenFunction::prepareEpilog(Type resultType, bool isThrowing,
21+
void SILGenFunction::prepareEpilog(bool hasDirectResults, bool isThrowing,
2222
CleanupLocation CleanupL) {
2323
auto *epilogBB = createBasicBlock();
2424

2525
// If we have any direct results, receive them via BB arguments.
26-
// But callers can disable this by passing a null result type.
27-
if (resultType) {
26+
if (hasDirectResults) {
2827
auto fnConv = F.getConventions();
2928
// Set NeedsReturn for indirect or direct results. This ensures that SILGen
3029
// emits unreachable if there is no source level return.

lib/SILGen/SILGenFunction.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,7 @@ void SILGenFunction::emitFunction(FuncDecl *fd) {
487487
auto captureInfo = SGM.M.Types.getLoweredLocalCaptures(SILDeclRef(fd));
488488
emitProlog(captureInfo, fd->getParameters(), fd->getImplicitSelfDecl(), fd,
489489
fd->getResultInterfaceType(), fd->hasThrows(), fd->getThrowsLoc());
490-
Type resultTy = fd->mapTypeIntoContext(fd->getResultInterfaceType());
491-
prepareEpilog(resultTy, fd->hasThrows(), CleanupLocation(fd));
490+
prepareEpilog(true, fd->hasThrows(), CleanupLocation(fd));
492491

493492
emitProfilerIncrement(fd->getBody());
494493
emitStmt(fd->getBody());
@@ -506,8 +505,7 @@ void SILGenFunction::emitClosure(AbstractClosureExpr *ace) {
506505
SILDeclRef(ace));
507506
emitProlog(captureInfo, ace->getParameters(), /*selfParam=*/nullptr,
508507
ace, resultIfaceTy, ace->isBodyThrowing(), ace->getLoc());
509-
prepareEpilog(ace->getResultType(), ace->isBodyThrowing(),
510-
CleanupLocation(ace));
508+
prepareEpilog(true, ace->isBodyThrowing(), CleanupLocation(ace));
511509
emitProfilerIncrement(ace);
512510
if (auto *ce = dyn_cast<ClosureExpr>(ace)) {
513511
emitStmt(ce->getBody());
@@ -773,7 +771,7 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
773771
dc, interfaceType, /*throws=*/false, SourceLoc());
774772
if (EmitProfilerIncrement)
775773
emitProfilerIncrement(value);
776-
prepareEpilog(value->getType(), false, CleanupLocation::get(Loc));
774+
prepareEpilog(true, false, CleanupLocation::get(Loc));
777775

778776
{
779777
llvm::Optional<SILGenFunction::OpaqueValueRAII> opaqueValue;
@@ -806,21 +804,19 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, VarDecl *var) {
806804
auto decl = function.getAbstractFunctionDecl();
807805
auto *dc = decl->getInnermostDeclContext();
808806
auto interfaceType = var->getValueInterfaceType();
809-
auto varType = var->getType();
810807

811808
// If this is the backing storage for a property with an attached
812809
// wrapper that was initialized with '=', the stored property initializer
813810
// will be in terms of the original property's type.
814811
if (auto originalProperty = var->getOriginalWrappedProperty()) {
815812
if (originalProperty->isPropertyMemberwiseInitializedWithWrappedType()) {
816813
interfaceType = originalProperty->getValueInterfaceType();
817-
varType = originalProperty->getType();
818814
}
819815
}
820816

821817
emitProlog(/*paramList*/ nullptr, /*selfParam*/ nullptr, interfaceType, dc,
822818
/*throws=*/false, SourceLoc());
823-
prepareEpilog(varType, false, CleanupLocation::get(loc));
819+
prepareEpilog(true, false, CleanupLocation::get(loc));
824820

825821
auto pbd = var->getParentPatternBinding();
826822
const auto i = pbd->getPatternEntryIndexForVarDecl(var);

lib/SILGen/SILGenFunction.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,13 +828,12 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
828828
/// Create (but do not emit) the epilog branch, and save the
829829
/// current cleanups depth as the destination for return statement branches.
830830
///
831-
/// \param returnType If non-null, the epilog block will be created with an
832-
/// argument of this type to receive the return value for
833-
/// the function.
831+
/// \param hasDirectResults If true, the epilog block will be created with
832+
/// arguments for each direct result of this function.
834833
/// \param isThrowing If true, create an error epilog block.
835834
/// \param L The SILLocation which should be associated with
836835
/// cleanup instructions.
837-
void prepareEpilog(Type returnType, bool isThrowing, CleanupLocation L);
836+
void prepareEpilog(bool hasDirectResults, bool isThrowing, CleanupLocation L);
838837
void prepareRethrowEpilog(CleanupLocation l);
839838
void prepareCoroutineUnwindEpilog(CleanupLocation l);
840839

0 commit comments

Comments
 (0)