Skip to content

Commit 2c42ae6

Browse files
committed
Remove maintenance of call graph in closure specializer.
1 parent 4b8ccac commit 2c42ae6

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

lib/SILPasses/IPO/ClosureSpecializer.cpp

+10-20
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ SILInstruction *CallSiteDescriptor::getClosure() const {
264264

265265
/// Update the callsite to pass in the correct arguments.
266266
static void rewriteApplyInst(const CallSiteDescriptor &CSDesc,
267-
SILFunction *NewF,
268-
CallGraph &CG) {
267+
SILFunction *NewF) {
269268
FullApplySite AI = CSDesc.getApplyInst();
270269
SILInstruction *Closure = CSDesc.getClosure();
271270
SILBuilderWithScope<2> Builder(Closure);
@@ -376,9 +375,6 @@ static void rewriteApplyInst(const CallSiteDescriptor &CSDesc,
376375
Builder.createReleaseValue(Closure->getLoc(), Closure);
377376
}
378377

379-
CallGraphEditor Editor(&CG);
380-
Editor.replaceApplyWithNew(AI, NewAI);
381-
382378
// Replace all uses of the old apply with the new apply.
383379
if (isa<ApplyInst>(AI))
384380
AI.getInstruction()->replaceAllUsesWith(NewAI.getInstruction());
@@ -419,7 +415,7 @@ void CallSiteDescriptor::extendArgumentLifetime(SILValue Arg) const {
419415
}
420416
}
421417

422-
static void specializeClosure(CallGraph &CG, ClosureInfo &CInfo,
418+
static void specializeClosure(ClosureInfo &CInfo,
423419
CallSiteDescriptor &CallDesc) {
424420
llvm::SmallString<64> NewFName;
425421
CallDesc.createName(NewFName);
@@ -432,16 +428,11 @@ static void specializeClosure(CallGraph &CG, ClosureInfo &CInfo,
432428

433429
// If not, create a specialized version of ApplyCallee calling the closure
434430
// directly.
435-
if (!NewF) {
431+
if (!NewF)
436432
NewF = ClosureSpecCloner::cloneFunction(CallDesc, NewFName);
437433

438-
// Update the call graph with the newly created function.
439-
CallGraphEditor Editor(&CG);
440-
Editor.addNewFunction(NewF);
441-
}
442-
443434
// Rewrite the call
444-
rewriteApplyInst(CallDesc, NewF, CG);
435+
rewriteApplyInst(CallDesc, NewF);
445436
}
446437

447438
static bool isSupportedClosure(const SILInstruction *Closure) {
@@ -687,7 +678,7 @@ class ClosureSpecializer {
687678
void gatherCallSites(SILFunction *Caller,
688679
llvm::SmallVectorImpl<ClosureInfo*> &ClosureCandidates,
689680
llvm::DenseSet<FullApplySite> &MultipleClosureAI);
690-
bool specialize(SILFunction *Caller, CallGraph &CG);
681+
bool specialize(SILFunction *Caller);
691682

692683
ArrayRef<SILInstruction *> getPropagatedClosures() {
693684
if (IsPropagatedClosuresUniqued)
@@ -812,8 +803,7 @@ void ClosureSpecializer::gatherCallSites(
812803
}
813804
}
814805

815-
bool ClosureSpecializer::specialize(SILFunction *Caller,
816-
CallGraph &CG) {
806+
bool ClosureSpecializer::specialize(SILFunction *Caller) {
817807
DEBUG(llvm::dbgs() << "Optimizing callsites that take closure argument in "
818808
<< Caller->getName() << '\n');
819809

@@ -831,7 +821,7 @@ bool ClosureSpecializer::specialize(SILFunction *Caller,
831821
if (MultipleClosureAI.count(CSDesc.getApplyInst()))
832822
continue;
833823

834-
specializeClosure(CG, *CInfo, CSDesc);
824+
specializeClosure(*CInfo, CSDesc);
835825
PropagatedClosures.push_back(CSDesc.getClosure());
836826
Changed = true;
837827
}
@@ -868,11 +858,11 @@ class SILClosureSpecializerTransform : public SILModuleTransform {
868858
if (F->isExternalDeclaration())
869859
continue;
870860

871-
Changed |= C.specialize(F, CG);
861+
Changed |= C.specialize(F);
872862
}
873863

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.
876866
if (Changed) {
877867
invalidateAnalysis(SILAnalysis::PreserveKind::Nothing);
878868
}

0 commit comments

Comments
 (0)