@@ -256,7 +256,7 @@ class SILInlineCloner
256
256
FullApplySite Apply;
257
257
Optional<BeginApplySite> BeginApply;
258
258
259
- SILInliner::DeletionFuncTy DeletionCallback ;
259
+ InstructionDeleter &deleter ;
260
260
261
261
// / The location representing the inlined instructions.
262
262
// /
@@ -272,18 +272,15 @@ class SILInlineCloner
272
272
// control path.
273
273
SILBasicBlock *ReturnToBB = nullptr ;
274
274
275
- // Keep track of the next instruction after inlining the call.
276
- SILBasicBlock::iterator NextIter;
277
-
278
275
public:
279
276
SILInlineCloner (SILFunction *CalleeFunction, FullApplySite Apply,
280
277
SILOptFunctionBuilder &FuncBuilder, InlineKind IKind,
281
278
SubstitutionMap ApplySubs,
282
- SILInliner::DeletionFuncTy deletionCallback );
279
+ InstructionDeleter &deleter );
283
280
284
281
SILFunction *getCalleeFunction () const { return &Original; }
285
282
286
- SILBasicBlock::iterator cloneInline (ArrayRef<SILValue> AppliedArgs);
283
+ void cloneInline (ArrayRef<SILValue> AppliedArgs);
287
284
288
285
protected:
289
286
SILValue borrowFunctionArgument (SILValue callArg, FullApplySite AI);
@@ -335,7 +332,7 @@ class SILInlineCloner
335
332
};
336
333
} // namespace swift
337
334
338
- std::pair< SILBasicBlock::iterator, SILBasicBlock *>
335
+ SILBasicBlock *
339
336
SILInliner::inlineFunction (SILFunction *calleeFunction, FullApplySite apply,
340
337
ArrayRef<SILValue> appliedArgs) {
341
338
PrettyStackTraceSILFunction calleeTraceRAII (" inlining" , calleeFunction);
@@ -344,15 +341,16 @@ SILInliner::inlineFunction(SILFunction *calleeFunction, FullApplySite apply,
344
341
&& " Asked to inline function that is unable to be inlined?!" );
345
342
346
343
SILInlineCloner cloner (calleeFunction, apply, FuncBuilder, IKind, ApplySubs,
347
- DeletionCallback );
348
- auto nextI = cloner.cloneInline (appliedArgs);
349
- return std::make_pair (nextI, cloner.getLastClonedBB () );
344
+ deleter );
345
+ cloner.cloneInline (appliedArgs);
346
+ return cloner.getLastClonedBB ();
350
347
}
351
348
352
- std::pair< SILBasicBlock::iterator, SILBasicBlock *>
349
+ SILBasicBlock *
353
350
SILInliner::inlineFullApply (FullApplySite apply,
354
351
SILInliner::InlineKind inlineKind,
355
- SILOptFunctionBuilder &funcBuilder) {
352
+ SILOptFunctionBuilder &funcBuilder,
353
+ InstructionDeleter &deleter) {
356
354
assert (apply.canOptimize ());
357
355
assert (!apply.getFunction ()->hasOwnership () ||
358
356
apply.getReferencedFunctionOrNull ()->hasOwnership ());
@@ -361,7 +359,7 @@ SILInliner::inlineFullApply(FullApplySite apply,
361
359
for (const auto arg : apply.getArguments ())
362
360
appliedArgs.push_back (arg);
363
361
364
- SILInliner Inliner (funcBuilder, inlineKind, apply.getSubstitutionMap ());
362
+ SILInliner Inliner (funcBuilder, deleter, inlineKind, apply.getSubstitutionMap ());
365
363
return Inliner.inlineFunction (apply.getReferencedFunctionOrNull (), apply,
366
364
appliedArgs);
367
365
}
@@ -370,11 +368,11 @@ SILInlineCloner::SILInlineCloner(
370
368
SILFunction *calleeFunction, FullApplySite apply,
371
369
SILOptFunctionBuilder &funcBuilder, InlineKind inlineKind,
372
370
SubstitutionMap applySubs,
373
- SILInliner::DeletionFuncTy deletionCallback )
371
+ InstructionDeleter &deleter )
374
372
: SuperTy(*apply.getFunction(), *calleeFunction, applySubs,
375
373
/* DT=*/ nullptr, /* Inlining=*/ true),
376
374
FuncBuilder(funcBuilder), IKind(inlineKind), Apply(apply),
377
- DeletionCallback(deletionCallback ) {
375
+ deleter(deleter ) {
378
376
379
377
SILFunction &F = getBuilder ().getFunction ();
380
378
assert (apply.getFunction () && apply.getFunction () == &F
@@ -419,10 +417,8 @@ SILInlineCloner::SILInlineCloner(
419
417
}
420
418
421
419
// Clone the entire callee function into the caller function at the apply site.
422
- // Delete the original apply and all dead arguments except the callee. Return an
423
- // iterator the the first instruction after the original apply.
424
- SILBasicBlock::iterator
425
- SILInlineCloner::cloneInline (ArrayRef<SILValue> AppliedArgs) {
420
+ // Delete the original apply and all dead arguments except the callee.
421
+ void SILInlineCloner::cloneInline (ArrayRef<SILValue> AppliedArgs) {
426
422
assert (getCalleeFunction ()->getArguments ().size () == AppliedArgs.size ()
427
423
&& " Unexpected number of callee arguments." );
428
424
@@ -506,8 +502,6 @@ SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
506
502
507
503
// Visit original BBs in depth-first preorder, starting with the
508
504
// entry block, cloning all instructions and terminators.
509
- //
510
- // NextIter is initialized during `fixUp`.
511
505
cloneFunctionBody (getCalleeFunction (), callerBlock, entryArgs);
512
506
513
507
// For non-throwing applies, the inlined body now unconditionally branches to
@@ -520,7 +514,6 @@ SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
520
514
//
521
515
// Once all calls in a function are inlined, unconditional branches are
522
516
// eliminated by mergeBlocks.
523
- return NextIter;
524
517
}
525
518
526
519
void SILInlineCloner::visitTerminator (SILBasicBlock *BB) {
@@ -578,25 +571,8 @@ void SILInlineCloner::preFixUp(SILFunction *calleeFunction) {
578
571
}
579
572
580
573
void SILInlineCloner::postFixUp (SILFunction *calleeFunction) {
581
- NextIter = std::next (Apply.getInstruction ()->getIterator ());
582
-
583
- assert (!Apply.getInstruction ()->hasUsesOfAnyResult ());
584
-
585
- auto callbacks = InstModCallbacks ().onDelete ([&](SILInstruction *deadInst) {
586
- if (NextIter == deadInst->getIterator ())
587
- ++NextIter;
588
- deadInst->eraseFromParent ();
589
- });
590
- if (DeletionCallback) {
591
- callbacks =
592
- callbacks.onNotifyWillBeDeleted ([this ](SILInstruction *toDeleteInst) {
593
- DeletionCallback (toDeleteInst);
594
- });
595
- }
596
- InstructionDeleter deleter (callbacks);
597
- callbacks.notifyWillBeDeleted (Apply.getInstruction ());
574
+ deleter.getCallbacks ().notifyWillBeDeleted (Apply.getInstruction ());
598
575
deleter.forceDelete (Apply.getInstruction ());
599
- deleter.cleanupDeadInstructions ();
600
576
}
601
577
602
578
SILValue SILInlineCloner::borrowFunctionArgument (SILValue callArg,
0 commit comments