@@ -305,6 +305,33 @@ class VJPCloner::Implementation final
305
305
joinElements (directResults, Builder, loc));
306
306
}
307
307
308
+ void visitUnwindInst (UnwindInst *ui) {
309
+ Builder.setCurrentDebugScope (getOpScope (ui->getDebugScope ()));
310
+ auto loc = ui->getLoc ();
311
+ auto *origExit = ui->getParent ();
312
+
313
+ // Consume unused pullback values
314
+ if (borrowedPullbackContextValue) {
315
+ auto *pbTupleVal = buildPullbackValueTupleValue (ui);
316
+ // Initialize the top-level subcontext buffer with the top-level pullback
317
+ // tuple.
318
+ auto addr = emitProjectTopLevelSubcontext (
319
+ Builder, loc, borrowedPullbackContextValue, pbTupleVal->getType ());
320
+ Builder.createStore (
321
+ loc, pbTupleVal, addr,
322
+ pbTupleVal->getType ().isTrivial (*pullback) ?
323
+ StoreOwnershipQualifier::Trivial : StoreOwnershipQualifier::Init);
324
+
325
+ Builder.createEndBorrow (loc, borrowedPullbackContextValue);
326
+ Builder.emitDestroyValueOperation (loc, pullbackContextValue);
327
+ } else {
328
+ for (SILValue val : getPullbackValues (origExit))
329
+ Builder.emitDestroyValueOperation (loc, val);
330
+ }
331
+
332
+ Builder.createUnwind (loc);
333
+ }
334
+
308
335
void visitBranchInst (BranchInst *bi) {
309
336
Builder.setCurrentDebugScope (getOpScope (bi->getDebugScope ()));
310
337
// Build pullback struct value for original block.
0 commit comments