21
21
#include " swift/AST/IRGenRequests.h"
22
22
#include " swift/AST/LinkLibrary.h"
23
23
#include " swift/AST/ProtocolConformance.h"
24
+ #include " swift/AST/SILGenRequests.h"
24
25
#include " swift/Basic/Defer.h"
25
26
#include " swift/Basic/Dwarf.h"
26
27
#include " swift/Basic/Platform.h"
@@ -1311,9 +1312,12 @@ GeneratedModule swift::performIRGeneration(
1311
1312
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
1312
1313
ArrayRef<std::string> parallelOutputFilenames,
1313
1314
llvm::GlobalVariable **outModuleHash) {
1315
+ // Get a pointer to the SILModule to avoid a potential use-after-move.
1316
+ const auto *SILModPtr = SILMod.get ();
1317
+ const auto &SILOpts = SILModPtr->getOptions ();
1314
1318
auto desc = IRGenDescriptor::forWholeModule (
1315
- M, Opts, TBDOpts, std::move (SILMod), ModuleName, PSPs ,
1316
- parallelOutputFilenames, outModuleHash);
1319
+ M, Opts, TBDOpts, SILOpts, SILModPtr-> Types , std::move (SILMod),
1320
+ ModuleName, PSPs, parallelOutputFilenames, outModuleHash);
1317
1321
1318
1322
if (Opts.shouldPerformIRGenerationInParallel () &&
1319
1323
!parallelOutputFilenames.empty ()) {
@@ -1332,9 +1336,12 @@ performIRGeneration(FileUnit *file, const IRGenOptions &Opts,
1332
1336
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
1333
1337
StringRef PrivateDiscriminator,
1334
1338
llvm::GlobalVariable **outModuleHash) {
1335
- auto desc = IRGenDescriptor::forFile (file, Opts, TBDOpts, std::move (SILMod),
1336
- ModuleName, PSPs, PrivateDiscriminator,
1337
- outModuleHash);
1339
+ // Get a pointer to the SILModule to avoid a potential use-after-move.
1340
+ const auto *SILModPtr = SILMod.get ();
1341
+ const auto &SILOpts = SILModPtr->getOptions ();
1342
+ auto desc = IRGenDescriptor::forFile (
1343
+ file, Opts, TBDOpts, SILOpts, SILModPtr->Types , std::move (SILMod),
1344
+ ModuleName, PSPs, PrivateDiscriminator, outModuleHash);
1338
1345
return llvm::cantFail (file->getASTContext ().evaluator (IRGenRequest{desc}));
1339
1346
}
1340
1347
@@ -1409,3 +1416,54 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,
1409
1416
return true ;
1410
1417
return false ;
1411
1418
}
1419
+
1420
+ GeneratedModule OptimizedIRRequest::evaluate (Evaluator &evaluator,
1421
+ IRGenDescriptor desc) const {
1422
+ auto *parentMod = desc.getParentModule ();
1423
+ auto &ctx = parentMod->getASTContext ();
1424
+
1425
+ // Resolve imports for all the source files.
1426
+ for (auto *file : parentMod->getFiles ()) {
1427
+ if (auto *SF = dyn_cast<SourceFile>(file))
1428
+ performImportResolution (*SF);
1429
+ }
1430
+
1431
+ bindExtensions (*parentMod);
1432
+
1433
+ // Type-check the files that need lowering to SIL.
1434
+ auto loweringDesc = ASTLoweringDescriptor{desc.Ctx , desc.Conv , desc.SILOpts };
1435
+ for (auto *file : loweringDesc.getFiles ()) {
1436
+ if (auto *SF = dyn_cast<SourceFile>(file))
1437
+ performTypeChecking (*SF);
1438
+ }
1439
+
1440
+ if (ctx.hadError ())
1441
+ return GeneratedModule::null ();
1442
+
1443
+ auto silMod = llvm::cantFail (evaluator (ASTLoweringRequest{loweringDesc}));
1444
+ silMod->installSILRemarkStreamer ();
1445
+ silMod->setSerializeSILAction ([](){});
1446
+
1447
+ // Run SIL passes.
1448
+ runSILDiagnosticPasses (*silMod);
1449
+ runSILOptimizationPasses (*silMod);
1450
+ silMod->verify ();
1451
+
1452
+ if (ctx.hadError ())
1453
+ return GeneratedModule::null ();
1454
+
1455
+ runSILLoweringPasses (*silMod);
1456
+
1457
+ if (ctx.hadError ())
1458
+ return GeneratedModule::null ();
1459
+
1460
+ // Perform IRGen with the generated SILModule.
1461
+ desc.SILMod = silMod.release ();
1462
+ auto irMod = llvm::cantFail (evaluator (IRGenRequest{desc}));
1463
+ if (!irMod)
1464
+ return irMod;
1465
+
1466
+ performLLVMOptimizations (desc.Opts , irMod.getModule (),
1467
+ irMod.getTargetMachine ());
1468
+ return irMod;
1469
+ }
0 commit comments