11
11
// ===----------------------------------------------------------------------===//
12
12
13
13
#define DEBUG_TYPE " sil-dead-function-elimination"
14
- #include " swift/SILAnalysis/CallGraphAnalysis.h"
15
14
#include " swift/SILPasses/Passes.h"
16
15
#include " swift/SILPasses/Transforms.h"
17
16
#include " swift/SIL/PatternMatch.h"
@@ -51,7 +50,6 @@ class FunctionLivenessComputation {
51
50
};
52
51
53
52
SILModule *Module;
54
- CallGraphAnalysis *CGA;
55
53
56
54
llvm::DenseMap<AbstractFunctionDecl *, MethodInfo *> MethodInfos;
57
55
llvm::SpecificBumpPtrAllocator<MethodInfo> MethodInfoAllocator;
@@ -251,8 +249,8 @@ class FunctionLivenessComputation {
251
249
}
252
250
253
251
public:
254
- FunctionLivenessComputation (SILModule *module , CallGraphAnalysis *CGA ) :
255
- Module (module ), CGA(CGA) {}
252
+ FunctionLivenessComputation (SILModule *module ) :
253
+ Module (module ) {}
256
254
257
255
// / The main entry point of the optimization.
258
256
bool findAliveFunctions () {
@@ -373,8 +371,8 @@ class DeadFunctionElimination : FunctionLivenessComputation {
373
371
}
374
372
375
373
public:
376
- DeadFunctionElimination (SILModule *module , CallGraphAnalysis *CGA )
377
- : FunctionLivenessComputation(module , CGA ) {}
374
+ DeadFunctionElimination (SILModule *module )
375
+ : FunctionLivenessComputation(module ) {}
378
376
379
377
// / The main entry point of the optimization.
380
378
void eliminateFunctions (SILModuleTransform *DFEPass) {
@@ -384,13 +382,11 @@ class DeadFunctionElimination : FunctionLivenessComputation {
384
382
385
383
removeDeadEntriesFromTables ();
386
384
387
- CallGraph *CG = CGA->getCallGraphOrNull ();
388
-
389
385
// First drop all references so that we don't get problems with non-zero
390
386
// reference counts of dead functions.
391
387
for (SILFunction &F : *Module)
392
388
if (!isAlive (&F))
393
- CallGraphEditor (CG) .dropAllReferences (&F );
389
+ F .dropAllReferences ();
394
390
395
391
// Next step: delete all dead functions.
396
392
bool NeedUpdate = false ;
@@ -400,11 +396,9 @@ class DeadFunctionElimination : FunctionLivenessComputation {
400
396
if (!isAlive (F)) {
401
397
DEBUG (llvm::dbgs () << " erase dead function " << F->getName () << " \n " );
402
398
NumDeadFunc++;
403
- CallGraphEditor (CG). eraseFunction (F);
399
+ Module-> eraseFunction (F);
404
400
NeedUpdate = true ;
405
- CGA->lockInvalidation ();
406
401
DFEPass->invalidateAnalysis (F, SILAnalysis::InvalidationKind::Everything);
407
- CGA->unlockInvalidation ();
408
402
}
409
403
}
410
404
}
@@ -475,22 +469,21 @@ class ExternalFunctionDefinitionsElimination : FunctionLivenessComputation {
475
469
476
470
DEBUG (llvm::dbgs () << " removed external function " << F->getName ()
477
471
<< " \n " );
478
- CallGraph *CG = CGA->getCallGraphOrNull ();
479
- CallGraphEditor (CG).dropAllReferences (F);
472
+ F->dropAllReferences ();
480
473
auto &Blocks = F->getBlocks ();
481
474
Blocks.clear ();
482
475
assert (F->isExternalDeclaration () &&
483
476
" Function should be an external declaration" );
484
477
if (F->getRefCount () == 0 )
485
- CallGraphEditor (CG ).eraseFunction (F);
478
+ F-> getModule ( ).eraseFunction (F);
486
479
487
480
NumEliminatedExternalDefs++;
488
481
return true ;
489
482
}
490
483
491
484
public:
492
- ExternalFunctionDefinitionsElimination (SILModule *module , CallGraphAnalysis *CGA )
493
- : FunctionLivenessComputation(module , CGA ) {}
485
+ ExternalFunctionDefinitionsElimination (SILModule *module )
486
+ : FunctionLivenessComputation(module ) {}
494
487
495
488
// / Eliminate bodies of external functions which are not alive.
496
489
// /
@@ -509,10 +502,8 @@ class ExternalFunctionDefinitionsElimination : FunctionLivenessComputation {
509
502
if (!isAlive (F)) {
510
503
if (tryToConvertExternalDefinitionIntoDeclaration (F)) {
511
504
NeedUpdate = true ;
512
- CGA->lockInvalidation ();
513
505
DFEPass->invalidateAnalysis (F,
514
506
SILAnalysis::InvalidationKind::Everything);
515
- CGA->unlockInvalidation ();
516
507
}
517
508
}
518
509
}
@@ -529,8 +520,6 @@ namespace {
529
520
530
521
class SILDeadFuncElimination : public SILModuleTransform {
531
522
void run () override {
532
- auto *CGA = getAnalysis<CallGraphAnalysis>();
533
-
534
523
DEBUG (llvm::dbgs () << " Running DeadFuncElimination\n " );
535
524
536
525
// The deserializer caches functions that it deserializes so that if it is
@@ -540,7 +529,7 @@ class SILDeadFuncElimination : public SILModuleTransform {
540
529
// can eliminate such functions.
541
530
getModule ()->invalidateSILLoaderCaches ();
542
531
543
- DeadFunctionElimination deadFunctionElimination (getModule (), CGA );
532
+ DeadFunctionElimination deadFunctionElimination (getModule ());
544
533
deadFunctionElimination.eliminateFunctions (this );
545
534
}
546
535
@@ -549,8 +538,6 @@ class SILDeadFuncElimination : public SILModuleTransform {
549
538
550
539
class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
551
540
void run () override {
552
- auto *CGA = getAnalysis<CallGraphAnalysis>();
553
-
554
541
DEBUG (llvm::dbgs () << " Running ExternalFunctionDefinitionsElimination\n " );
555
542
556
543
// The deserializer caches functions that it deserializes so that if it is
@@ -560,7 +547,7 @@ class SILExternalFuncDefinitionsElimination : public SILModuleTransform {
560
547
// can eliminate the definitions of such functions.
561
548
getModule ()->invalidateSILLoaderCaches ();
562
549
563
- ExternalFunctionDefinitionsElimination EFDFE (getModule (), CGA );
550
+ ExternalFunctionDefinitionsElimination EFDFE (getModule ());
564
551
EFDFE.eliminateFunctions (this );
565
552
}
566
553
0 commit comments