Skip to content

Commit b9f0578

Browse files
committed
SILGen: refactor emitCleanupsForBranch
1 parent 0a81f7f commit b9f0578

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

lib/SILGen/Cleanup.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,17 @@ void CleanupManager::emitBranchAndCleanups(JumpDest dest,
167167
SILLocation branchLoc,
168168
ArrayRef<SILValue> args,
169169
ForUnwind_t forUnwind) {
170-
emitCleanupsForBranch(dest, branchLoc, args, forUnwind);
170+
emitCleanupsBeforeBranch(dest, forUnwind);
171171
SGF.getBuilder().createBranch(branchLoc, dest.getBlock(), args);
172172
}
173173

174-
/// emitBranchAndCleanups - Emit the cleanups necessary before branching to
174+
/// emitCleanupsBeforeBranch - Emit the cleanups necessary before branching to
175175
/// the given jump destination. This does not pop the cleanup stack, nor does
176176
/// it emit the actual branch.
177-
void CleanupManager::emitCleanupsForBranch(JumpDest dest,
178-
SILLocation branchLoc,
179-
ArrayRef<SILValue> args,
180-
ForUnwind_t forUnwind) {
177+
void CleanupManager::emitCleanupsBeforeBranch(JumpDest dest,
178+
ForUnwind_t forUnwind) {
181179
SILGenBuilder &builder = SGF.getBuilder();
182-
assert(builder.hasValidInsertionPoint() && "Emitting branch in invalid spot");
180+
assert(builder.hasValidInsertionPoint() && "no insertion point for cleanups");
183181
emitCleanups(dest.getDepth(), dest.getCleanupLocation(),
184182
forUnwind, /*popCleanups=*/false);
185183
}

lib/SILGen/Cleanup.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,13 @@ class LLVM_LIBRARY_VISIBILITY CleanupManager {
226226
ArrayRef<SILValue> args = {},
227227
ForUnwind_t forUnwind = NotForUnwind);
228228

229-
/// Emit a branch to the given jump destination,
230-
/// threading out through any cleanups we need to run. This does not pop the
231-
/// cleanup stack.
229+
/// Emit the cleanups necessary before branching to
230+
/// the given jump destination. This does not pop the cleanup stack, nor does
231+
/// it emit the actual branch.
232232
///
233233
/// \param dest The destination scope and block.
234-
/// \param branchLoc The location of the branch instruction.
235-
/// \param args Arguments to pass to the destination block.
236-
void emitCleanupsForBranch(JumpDest dest, SILLocation branchLoc,
237-
ArrayRef<SILValue> args = {},
234+
/// \param forUnwind Whether the cleanups for this dest is for unwinding.
235+
void emitCleanupsBeforeBranch(JumpDest dest,
238236
ForUnwind_t forUnwind = NotForUnwind);
239237

240238
/// emitCleanupsForReturn - Emit the top-level cleanups needed prior to a

lib/SILGen/SILGenStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,8 +1749,8 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
17491749
B.createDestroyAddr(loc, exn);
17501750
}
17511751

1752-
// Branch to the cleanup destination.
1753-
Cleanups.emitCleanupsForBranch(ThrowDest, loc, args, IsForUnwind);
1752+
// Emit clean-ups needed prior to entering throw block.
1753+
Cleanups.emitCleanupsBeforeBranch(ThrowDest, IsForUnwind);
17541754

17551755
if (indirectErrorAddr && !exn->getType().isAddress()) {
17561756
// Forward the error value into the return slot now. This has to happen

0 commit comments

Comments
 (0)