@@ -264,8 +264,7 @@ SILInstruction *CallSiteDescriptor::getClosure() const {
264
264
265
265
// / Update the callsite to pass in the correct arguments.
266
266
static void rewriteApplyInst (const CallSiteDescriptor &CSDesc,
267
- SILFunction *NewF,
268
- CallGraph &CG) {
267
+ SILFunction *NewF) {
269
268
FullApplySite AI = CSDesc.getApplyInst ();
270
269
SILInstruction *Closure = CSDesc.getClosure ();
271
270
SILBuilderWithScope<2 > Builder (Closure);
@@ -376,9 +375,6 @@ static void rewriteApplyInst(const CallSiteDescriptor &CSDesc,
376
375
Builder.createReleaseValue (Closure->getLoc (), Closure);
377
376
}
378
377
379
- CallGraphEditor Editor (&CG);
380
- Editor.replaceApplyWithNew (AI, NewAI);
381
-
382
378
// Replace all uses of the old apply with the new apply.
383
379
if (isa<ApplyInst>(AI))
384
380
AI.getInstruction ()->replaceAllUsesWith (NewAI.getInstruction ());
@@ -419,7 +415,7 @@ void CallSiteDescriptor::extendArgumentLifetime(SILValue Arg) const {
419
415
}
420
416
}
421
417
422
- static void specializeClosure (CallGraph &CG, ClosureInfo &CInfo,
418
+ static void specializeClosure (ClosureInfo &CInfo,
423
419
CallSiteDescriptor &CallDesc) {
424
420
llvm::SmallString<64 > NewFName;
425
421
CallDesc.createName (NewFName);
@@ -432,16 +428,11 @@ static void specializeClosure(CallGraph &CG, ClosureInfo &CInfo,
432
428
433
429
// If not, create a specialized version of ApplyCallee calling the closure
434
430
// directly.
435
- if (!NewF) {
431
+ if (!NewF)
436
432
NewF = ClosureSpecCloner::cloneFunction (CallDesc, NewFName);
437
433
438
- // Update the call graph with the newly created function.
439
- CallGraphEditor Editor (&CG);
440
- Editor.addNewFunction (NewF);
441
- }
442
-
443
434
// Rewrite the call
444
- rewriteApplyInst (CallDesc, NewF, CG );
435
+ rewriteApplyInst (CallDesc, NewF);
445
436
}
446
437
447
438
static bool isSupportedClosure (const SILInstruction *Closure) {
@@ -687,7 +678,7 @@ class ClosureSpecializer {
687
678
void gatherCallSites (SILFunction *Caller,
688
679
llvm::SmallVectorImpl<ClosureInfo*> &ClosureCandidates,
689
680
llvm::DenseSet<FullApplySite> &MultipleClosureAI);
690
- bool specialize (SILFunction *Caller, CallGraph &CG );
681
+ bool specialize (SILFunction *Caller);
691
682
692
683
ArrayRef<SILInstruction *> getPropagatedClosures () {
693
684
if (IsPropagatedClosuresUniqued)
@@ -812,8 +803,7 @@ void ClosureSpecializer::gatherCallSites(
812
803
}
813
804
}
814
805
815
- bool ClosureSpecializer::specialize (SILFunction *Caller,
816
- CallGraph &CG) {
806
+ bool ClosureSpecializer::specialize (SILFunction *Caller) {
817
807
DEBUG (llvm::dbgs () << " Optimizing callsites that take closure argument in "
818
808
<< Caller->getName () << ' \n ' );
819
809
@@ -831,7 +821,7 @@ bool ClosureSpecializer::specialize(SILFunction *Caller,
831
821
if (MultipleClosureAI.count (CSDesc.getApplyInst ()))
832
822
continue ;
833
823
834
- specializeClosure (CG, *CInfo, CSDesc);
824
+ specializeClosure (*CInfo, CSDesc);
835
825
PropagatedClosures.push_back (CSDesc.getClosure ());
836
826
Changed = true ;
837
827
}
@@ -868,11 +858,11 @@ class SILClosureSpecializerTransform : public SILModuleTransform {
868
858
if (F->isExternalDeclaration ())
869
859
continue ;
870
860
871
- Changed |= C.specialize (F, CG );
861
+ Changed |= C.specialize (F);
872
862
}
873
863
874
- // We maintain the call graph, but delete calls, and introduce new
875
- // calls and branches in the cloned functions .
864
+ // Invalidate everything since we delete calls as well as add new
865
+ // calls and branches.
876
866
if (Changed) {
877
867
invalidateAnalysis (SILAnalysis::PreserveKind::Nothing);
878
868
}
0 commit comments