Skip to content

Commit 3547122

Browse files
committed
SILGen: Simplify prepareEpilog() utility method
1 parent e4a4dfe commit 3547122

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
@@ -1539,7 +1539,7 @@ class SourceFileScope {
15391539
sgm.TopLevelSGF = new SILGenFunction(sgm, *toplevel, sf);
15401540
sgm.TopLevelSGF->MagicFunctionName = sgm.SwiftModule->getName();
15411541
auto moduleCleanupLoc = CleanupLocation::getModuleCleanupLocation();
1542-
sgm.TopLevelSGF->prepareEpilog(Type(), true, moduleCleanupLoc);
1542+
sgm.TopLevelSGF->prepareEpilog(false, true, moduleCleanupLoc);
15431543

15441544
// Create the argc and argv arguments.
15451545
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);
@@ -210,7 +210,7 @@ void SILGenFunction::emitObjCDestructor(SILDeclRef dtor) {
210210
// Create a basic block to jump to for the implicit destruction behavior
211211
// of releasing the elements and calling the superclass destructor.
212212
// We won't actually emit the block until we finish with the destructor body.
213-
prepareEpilog(Type(), false, CleanupLocation::get(loc));
213+
prepareEpilog(false, false, CleanupLocation::get(loc));
214214

215215
emitProfilerIncrement(dd->getBody());
216216
// 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());
@@ -743,7 +741,7 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, Expr *value,
743741
dc, interfaceType, /*throws=*/false, SourceLoc());
744742
if (EmitProfilerIncrement)
745743
emitProfilerIncrement(value);
746-
prepareEpilog(value->getType(), false, CleanupLocation::get(Loc));
744+
prepareEpilog(true, false, CleanupLocation::get(Loc));
747745

748746
{
749747
llvm::Optional<SILGenFunction::OpaqueValueRAII> opaqueValue;
@@ -776,21 +774,19 @@ void SILGenFunction::emitGeneratorFunction(SILDeclRef function, VarDecl *var) {
776774
auto decl = function.getAbstractFunctionDecl();
777775
auto *dc = decl->getInnermostDeclContext();
778776
auto interfaceType = var->getValueInterfaceType();
779-
auto varType = var->getType();
780777

781778
// If this is the backing storage for a property with an attached
782779
// wrapper that was initialized with '=', the stored property initializer
783780
// will be in terms of the original property's type.
784781
if (auto originalProperty = var->getOriginalWrappedProperty()) {
785782
if (originalProperty->isPropertyMemberwiseInitializedWithWrappedType()) {
786783
interfaceType = originalProperty->getValueInterfaceType();
787-
varType = originalProperty->getType();
788784
}
789785
}
790786

791787
emitProlog(/*paramList*/ nullptr, /*selfParam*/ nullptr, interfaceType, dc,
792788
/*throws=*/false, SourceLoc());
793-
prepareEpilog(varType, false, CleanupLocation::get(loc));
789+
prepareEpilog(true, false, CleanupLocation::get(loc));
794790

795791
auto pbd = var->getParentPatternBinding();
796792
const auto i = pbd->getPatternEntryIndexForVarDecl(var);

lib/SILGen/SILGenFunction.h

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

0 commit comments

Comments
 (0)