Skip to content

Commit 40a89cb

Browse files
committed
Remove call graph maintenance in dead function elimination.
1 parent 7b5e2fd commit 40a89cb

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

lib/SILPasses/IPO/DeadFunctionElimination.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#define DEBUG_TYPE "sil-dead-function-elimination"
14-
#include "swift/SILAnalysis/CallGraphAnalysis.h"
1514
#include "swift/SILPasses/Passes.h"
1615
#include "swift/SILPasses/Transforms.h"
1716
#include "swift/SIL/PatternMatch.h"
@@ -51,7 +50,6 @@ class FunctionLivenessComputation {
5150
};
5251

5352
SILModule *Module;
54-
CallGraphAnalysis *CGA;
5553

5654
llvm::DenseMap<AbstractFunctionDecl *, MethodInfo *> MethodInfos;
5755
llvm::SpecificBumpPtrAllocator<MethodInfo> MethodInfoAllocator;
@@ -251,8 +249,8 @@ class FunctionLivenessComputation {
251249
}
252250

253251
public:
254-
FunctionLivenessComputation(SILModule *module, CallGraphAnalysis *CGA) :
255-
Module(module), CGA(CGA) {}
252+
FunctionLivenessComputation(SILModule *module) :
253+
Module(module) {}
256254

257255
/// The main entry point of the optimization.
258256
bool findAliveFunctions() {
@@ -373,8 +371,8 @@ class DeadFunctionElimination : FunctionLivenessComputation {
373371
}
374372

375373
public:
376-
DeadFunctionElimination(SILModule *module, CallGraphAnalysis *CGA)
377-
: FunctionLivenessComputation(module, CGA) {}
374+
DeadFunctionElimination(SILModule *module)
375+
: FunctionLivenessComputation(module) {}
378376

379377
/// The main entry point of the optimization.
380378
void eliminateFunctions(SILModuleTransform *DFEPass) {
@@ -384,13 +382,11 @@ class DeadFunctionElimination : FunctionLivenessComputation {
384382

385383
removeDeadEntriesFromTables();
386384

387-
CallGraph *CG = CGA->getCallGraphOrNull();
388-
389385
// First drop all references so that we don't get problems with non-zero
390386
// reference counts of dead functions.
391387
for (SILFunction &F : *Module)
392388
if (!isAlive(&F))
393-
CallGraphEditor(CG).dropAllReferences(&F);
389+
F.dropAllReferences();
394390

395391
// Next step: delete all dead functions.
396392
bool NeedUpdate = false;
@@ -400,11 +396,9 @@ class DeadFunctionElimination : FunctionLivenessComputation {
400396
if (!isAlive(F)) {
401397
DEBUG(llvm::dbgs() << " erase dead function " << F->getName() << "\n");
402398
NumDeadFunc++;
403-
CallGraphEditor(CG).eraseFunction(F);
399+
Module->eraseFunction(F);
404400
NeedUpdate = true;
405-
CGA->lockInvalidation();
406401
DFEPass->invalidateAnalysis(F, SILAnalysis::InvalidationKind::Everything);
407-
CGA->unlockInvalidation();
408402
}
409403
}
410404
}
@@ -475,22 +469,21 @@ class ExternalFunctionDefinitionsElimination : FunctionLivenessComputation {
475469

476470
DEBUG(llvm::dbgs() << " removed external function " << F->getName()
477471
<< "\n");
478-
CallGraph *CG = CGA->getCallGraphOrNull();
479-
CallGraphEditor(CG).dropAllReferences(F);
472+
F->dropAllReferences();
480473
auto &Blocks = F->getBlocks();
481474
Blocks.clear();
482475
assert(F->isExternalDeclaration() &&
483476
"Function should be an external declaration");
484477
if (F->getRefCount() == 0)
485-
CallGraphEditor(CG).eraseFunction(F);
478+
F->getModule().eraseFunction(F);
486479

487480
NumEliminatedExternalDefs++;
488481
return true;
489482
}
490483

491484
public:
492-
ExternalFunctionDefinitionsElimination(SILModule *module, CallGraphAnalysis *CGA)
493-
: FunctionLivenessComputation(module, CGA) {}
485+
ExternalFunctionDefinitionsElimination(SILModule *module)
486+
: FunctionLivenessComputation(module) {}
494487

495488
/// Eliminate bodies of external functions which are not alive.
496489
///
@@ -509,10 +502,8 @@ class ExternalFunctionDefinitionsElimination : FunctionLivenessComputation {
509502
if (!isAlive(F)) {
510503
if (tryToConvertExternalDefinitionIntoDeclaration(F)) {
511504
NeedUpdate = true;
512-
CGA->lockInvalidation();
513505
DFEPass->invalidateAnalysis(F,
514506
SILAnalysis::InvalidationKind::Everything);
515-
CGA->unlockInvalidation();
516507
}
517508
}
518509
}
@@ -529,8 +520,6 @@ namespace {
529520

530521
class SILDeadFuncElimination : public SILModuleTransform {
531522
void run() override {
532-
auto *CGA = getAnalysis<CallGraphAnalysis>();
533-
534523
DEBUG(llvm::dbgs() << "Running DeadFuncElimination\n");
535524

536525
// The deserializer caches functions that it deserializes so that if it is
@@ -540,7 +529,7 @@ class SILDeadFuncElimination : public SILModuleTransform {
540529
// can eliminate such functions.
541530
getModule()->invalidateSILLoaderCaches();
542531

543-
DeadFunctionElimination deadFunctionElimination(getModule(), CGA);
532+
DeadFunctionElimination deadFunctionElimination(getModule());
544533
deadFunctionElimination.eliminateFunctions(this);
545534
}
546535

@@ -549,8 +538,6 @@ class SILDeadFuncElimination : public SILModuleTransform {
549538

550539
class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
551540
void run() override {
552-
auto *CGA = getAnalysis<CallGraphAnalysis>();
553-
554541
DEBUG(llvm::dbgs() << "Running ExternalFunctionDefinitionsElimination\n");
555542

556543
// The deserializer caches functions that it deserializes so that if it is
@@ -560,7 +547,7 @@ class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
560547
// can eliminate the definitions of such functions.
561548
getModule()->invalidateSILLoaderCaches();
562549

563-
ExternalFunctionDefinitionsElimination EFDFE(getModule(), CGA);
550+
ExternalFunctionDefinitionsElimination EFDFE(getModule());
564551
EFDFE.eliminateFunctions(this);
565552
}
566553

0 commit comments

Comments
 (0)