@@ -374,7 +374,7 @@ void swift::executePassPipelinePlan(SILModule *SM,
374
374
375
375
SILPassManager::SILPassManager (SILModule *M, bool isMandatory,
376
376
irgen::IRGenModule *IRMod)
377
- : Mod(M), IRMod(IRMod),
377
+ : Mod(M), IRMod(IRMod), irgen( nullptr ),
378
378
swiftPassInvocation(this ),
379
379
isMandatory(isMandatory), deserializationNotificationHandler(nullptr ) {
380
380
#define SIL_ANALYSIS (NAME ) \
@@ -901,6 +901,27 @@ void SILPassManager::execute() {
901
901
}
902
902
}
903
903
904
+ irgen::IRGenModule *SILPassManager::getIRGenModule () {
905
+ // We need an IRGenModule to get the actual sizes from type lowering.
906
+ // Creating an IRGenModule involves some effort, let's cache it for the
907
+ // whole pass.
908
+ if (IRMod == nullptr ) {
909
+ SILModule *module = getModule ();
910
+
911
+ auto *irgenOpts = module ->getIRGenOptionsOrNull ();
912
+ if (!irgenOpts)
913
+ return nullptr ;
914
+
915
+ if (irgen == nullptr )
916
+ irgen = new irgen::IRGenerator (*irgenOpts, *module );
917
+ auto targetMachine = irgen->createTargetMachine ();
918
+ assert (targetMachine && " failed to create target" );
919
+ IRMod = new irgen::IRGenModule (*irgen, std::move (targetMachine));
920
+ }
921
+
922
+ return IRMod;
923
+ }
924
+
904
925
// / D'tor.
905
926
SILPassManager::~SILPassManager () {
906
927
@@ -940,6 +961,16 @@ SILPassManager::~SILPassManager() {
940
961
" Deleting a locked analysis. Did we forget to unlock ?" );
941
962
delete A;
942
963
}
964
+
965
+ if (irgen) {
966
+ // If irgen is set, we also own the IRGenModule
967
+ if (IRMod) {
968
+ delete IRMod;
969
+ IRMod = nullptr ;
970
+ }
971
+ delete irgen;
972
+ irgen = nullptr ;
973
+ }
943
974
}
944
975
945
976
void SILPassManager::notifyOfNewFunction (SILFunction *F, SILTransform *T) {
@@ -1382,22 +1413,7 @@ void SwiftPassInvocation::finishedInstructionPassRun() {
1382
1413
}
1383
1414
1384
1415
irgen::IRGenModule *SwiftPassInvocation::getIRGenModule () {
1385
- // We need an IRGenModule to get the actual sizes from type lowering.
1386
- // Creating an IRGenModule involves some effort, let's cache it for the
1387
- // whole pass.
1388
- if (irgenModule == nullptr && irgen == nullptr ) {
1389
- SILModule *module = getPassManager ()->getModule ();
1390
-
1391
- auto *irgenOpts = module ->getIRGenOptionsOrNull ();
1392
- if (!irgenOpts)
1393
- return nullptr ;
1394
-
1395
- irgen = new irgen::IRGenerator (*irgenOpts, *module );
1396
- auto targetMachine = irgen->createTargetMachine ();
1397
- assert (targetMachine && " failed to create target" );
1398
- irgenModule = new irgen::IRGenModule (*irgen, std::move (targetMachine));
1399
- }
1400
- return irgenModule;
1416
+ return passManager->getIRGenModule ();
1401
1417
}
1402
1418
1403
1419
void SwiftPassInvocation::endPass () {
@@ -1430,16 +1446,7 @@ void SwiftPassInvocation::endTransformFunction() {
1430
1446
assert (numNodeSetsAllocated == 0 && " Not all NodeSets deallocated" );
1431
1447
}
1432
1448
1433
- SwiftPassInvocation::~SwiftPassInvocation () {
1434
- if (irgenModule) {
1435
- delete irgenModule;
1436
- irgenModule = nullptr ;
1437
- }
1438
- if (irgen) {
1439
- delete irgen;
1440
- irgen = nullptr ;
1441
- }
1442
- }
1449
+ SwiftPassInvocation::~SwiftPassInvocation () {}
1443
1450
1444
1451
// ===----------------------------------------------------------------------===//
1445
1452
// OptimizerBridging
0 commit comments