Skip to content

Commit e249a71

Browse files
committed
Update SIL tooling
Have the tools call into `performSILGeneration` in order to retrieve the SILModule rather than getting it from the CompilerInstance.
1 parent d92374c commit e249a71

File tree

4 files changed

+74
-78
lines changed

4 files changed

+74
-78
lines changed

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,16 @@ int main(int argc, char **argv) {
272272
if (CI.getASTContext().hadError())
273273
return 1;
274274

275-
// Load the SIL if we have a module. We have to do this after SILParse
276-
// creating the unfortunate double if statement.
277-
if (Invocation.hasSerializedAST()) {
278-
assert(!CI.hasSILModule() &&
279-
"performSema() should not create a SILModule.");
280-
CI.createSILModule();
281-
std::unique_ptr<SerializedSILLoader> SL = SerializedSILLoader::create(
282-
CI.getASTContext(), CI.getSILModule(), nullptr);
283-
284-
if (extendedInfo.isSIB() || DisableSILLinking)
275+
auto SILMod = performSILGeneration(CI.getMainModule(), CI.getSILTypes(),
276+
CI.getSILOptions());
277+
278+
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
279+
// us.
280+
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
281+
auto SL = SerializedSILLoader::create(
282+
CI.getASTContext(), SILMod.get(), nullptr);
283+
284+
if (DisableSILLinking)
285285
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
286286
else
287287
SL->getAll();
@@ -329,7 +329,7 @@ int main(int argc, char **argv) {
329329
llvm::errs() << " " << str << '\n';
330330
}));
331331

332-
removeUnwantedFunctions(CI.getSILModule(), MangledNames, DemangledNames);
332+
removeUnwantedFunctions(SILMod.get(), MangledNames, DemangledNames);
333333

334334
if (EmitSIB) {
335335
llvm::SmallString<128> OutputFile;
@@ -350,7 +350,7 @@ int main(int argc, char **argv) {
350350
serializationOpts.SerializeAllSIL = true;
351351
serializationOpts.IsSIB = true;
352352

353-
serialize(CI.getMainModule(), serializationOpts, CI.getSILModule());
353+
serialize(CI.getMainModule(), serializationOpts, SILMod.get());
354354
} else {
355355
const StringRef OutputFile =
356356
OutputFilename.size() ? StringRef(OutputFilename) : "-";
@@ -360,8 +360,7 @@ int main(int argc, char **argv) {
360360
SILOpts.EmitSortedSIL = EnableSILSortOutput;
361361

362362
if (OutputFile == "-") {
363-
CI.getSILModule()->print(llvm::outs(), CI.getMainModule(), SILOpts,
364-
!DisableASTDump);
363+
SILMod->print(llvm::outs(), CI.getMainModule(), SILOpts, !DisableASTDump);
365364
} else {
366365
std::error_code EC;
367366
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
@@ -370,8 +369,7 @@ int main(int argc, char **argv) {
370369
<< '\n';
371370
return 1;
372371
}
373-
CI.getSILModule()->print(OS, CI.getMainModule(), SILOpts,
374-
!DisableASTDump);
372+
SILMod->print(OS, CI.getMainModule(), SILOpts, !DisableASTDump);
375373
}
376374
}
377375
}

tools/sil-llvm-gen/SILLLVMGen.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,28 @@ int main(int argc, char **argv) {
184184
if (CI.getASTContext().hadError())
185185
return 1;
186186

187-
// Load the SIL if we have a module. We have to do this after SILParse
188-
// creating the unfortunate double if statement.
189-
if (Invocation.hasSerializedAST()) {
190-
assert(!CI.hasSILModule() &&
191-
"performSema() should not create a SILModule.");
192-
CI.createSILModule();
193-
std::unique_ptr<SerializedSILLoader> SL = SerializedSILLoader::create(
194-
CI.getASTContext(), CI.getSILModule(), nullptr);
195-
196-
if (extendedInfo.isSIB())
197-
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
198-
else
199-
SL->getAll();
187+
auto *mod = CI.getMainModule();
188+
assert(mod->getFiles().size() == 1);
189+
190+
std::unique_ptr<SILModule> SILMod;
191+
if (PerformWMO) {
192+
SILMod = performSILGeneration(mod, CI.getSILTypes(), CI.getSILOptions());
193+
} else {
194+
SILMod = performSILGeneration(*mod->getFiles()[0], CI.getSILTypes(),
195+
CI.getSILOptions());
196+
}
197+
198+
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
199+
// us.
200+
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
201+
auto SL = SerializedSILLoader::create(
202+
CI.getASTContext(), SILMod.get(), nullptr);
203+
SL->getAll();
200204
}
201205

202206
const PrimarySpecificPaths PSPs(OutputFilename, InputFilename);
203-
auto Mod =
204-
performIRGeneration(Opts, CI.getMainModule(), CI.takeSILModule(),
205-
CI.getMainModule()->getName().str(),
206-
PSPs,
207-
ArrayRef<std::string>());
207+
auto Mod = performIRGeneration(Opts, CI.getMainModule(), std::move(SILMod),
208+
CI.getMainModule()->getName().str(), PSPs,
209+
ArrayRef<std::string>());
208210
return CI.getASTContext().hadError();
209211
}

tools/sil-nm/SILNM.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,22 +186,18 @@ int main(int argc, char **argv) {
186186
if (CI.getASTContext().hadError())
187187
return 1;
188188

189-
// Load the SIL if we have a module. We have to do this after SILParse
190-
// creating the unfortunate double if statement.
191-
if (Invocation.hasSerializedAST()) {
192-
assert(!CI.hasSILModule() &&
193-
"performSema() should not create a SILModule.");
194-
CI.createSILModule();
195-
std::unique_ptr<SerializedSILLoader> SL = SerializedSILLoader::create(
196-
CI.getASTContext(), CI.getSILModule(), nullptr);
197-
198-
if (extendedInfo.isSIB())
199-
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
200-
else
201-
SL->getAll();
189+
auto SILMod = performSILGeneration(CI.getMainModule(), CI.getSILTypes(),
190+
CI.getSILOptions());
191+
192+
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
193+
// us.
194+
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
195+
auto SL = SerializedSILLoader::create(
196+
CI.getASTContext(), SILMod.get(), nullptr);
197+
SL->getAll();
202198
}
203199

204-
nmModule(CI.getSILModule());
200+
nmModule(SILMod.get());
205201

206202
return CI.getASTContext().hadError();
207203
}

tools/sil-opt/SILOpt.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -443,24 +443,29 @@ int main(int argc, char **argv) {
443443
if (HadError)
444444
return finishDiagProcessing(1);
445445

446-
// Load the SIL if we have a module. We have to do this after SILParse
447-
// creating the unfortunate double if statement.
448-
if (Invocation.hasSerializedAST()) {
449-
assert(!CI.hasSILModule() &&
450-
"performSema() should not create a SILModule.");
451-
CI.createSILModule();
452-
std::unique_ptr<SerializedSILLoader> SL = SerializedSILLoader::create(
453-
CI.getASTContext(), CI.getSILModule(), nullptr);
454-
455-
if (extendedInfo.isSIB() || DisableSILLinking)
446+
auto *mod = CI.getMainModule();
447+
assert(mod->getFiles().size() == 1);
448+
449+
std::unique_ptr<SILModule> SILMod;
450+
if (PerformWMO) {
451+
SILMod = performSILGeneration(mod, CI.getSILTypes(), CI.getSILOptions());
452+
} else {
453+
SILMod = performSILGeneration(*mod->getFiles()[0], CI.getSILTypes(),
454+
CI.getSILOptions());
455+
}
456+
SILMod->setSerializeSILAction([]{});
457+
458+
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
459+
// us.
460+
if (Invocation.hasSerializedAST() && !extendedInfo.isSIB()) {
461+
auto SL = SerializedSILLoader::create(
462+
CI.getASTContext(), SILMod.get(), nullptr);
463+
if (DisableSILLinking)
456464
SL->getAllForModule(CI.getMainModule()->getName(), nullptr);
457465
else
458466
SL->getAll();
459467
}
460468

461-
if (CI.getSILModule())
462-
CI.getSILModule()->setSerializeSILAction([]{});
463-
464469
if (!RemarksFilename.empty()) {
465470
llvm::Expected<llvm::remarks::Format> formatOrErr =
466471
llvm::remarks::parseFormat(RemarksFormat);
@@ -474,24 +479,21 @@ int main(int argc, char **argv) {
474479
SILOpts.OptRecordFormat = *formatOrErr;
475480
}
476481

477-
CI.getSILModule()->installSILRemarkStreamer();
482+
SILMod->installSILRemarkStreamer();
478483
}
479484

480485
if (OptimizationGroup == OptGroup::Diagnostics) {
481-
runSILDiagnosticPasses(*CI.getSILModule());
486+
runSILDiagnosticPasses(*SILMod.get());
482487
} else if (OptimizationGroup == OptGroup::Performance) {
483-
runSILOptimizationPasses(*CI.getSILModule());
488+
runSILOptimizationPasses(*SILMod.get());
484489
} else if (OptimizationGroup == OptGroup::Lowering) {
485-
runSILLoweringPasses(*CI.getSILModule());
490+
runSILLoweringPasses(*SILMod.get());
486491
} else {
487-
auto *SILMod = CI.getSILModule();
488-
{
489-
auto T = irgen::createIRGenModule(
490-
SILMod, Invocation.getOutputFilenameForAtMostOnePrimary(),
491-
Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary(), "");
492-
runCommandLineSelectedPasses(SILMod, T.second);
493-
irgen::deleteIRGenModule(T);
494-
}
492+
auto T = irgen::createIRGenModule(
493+
SILMod.get(), Invocation.getOutputFilenameForAtMostOnePrimary(),
494+
Invocation.getMainInputFilenameForDebugInfoForAtMostOnePrimary(), "");
495+
runCommandLineSelectedPasses(SILMod.get(), T.second);
496+
irgen::deleteIRGenModule(T);
495497
}
496498

497499
if (EmitSIB) {
@@ -513,16 +515,15 @@ int main(int argc, char **argv) {
513515
serializationOpts.SerializeAllSIL = true;
514516
serializationOpts.IsSIB = true;
515517

516-
serialize(CI.getMainModule(), serializationOpts, CI.getSILModule());
518+
serialize(CI.getMainModule(), serializationOpts, SILMod.get());
517519
} else {
518520
const StringRef OutputFile = OutputFilename.size() ?
519521
StringRef(OutputFilename) : "-";
520522
auto SILOpts = SILOptions();
521523
SILOpts.EmitVerboseSIL = EmitVerboseSIL;
522524
SILOpts.EmitSortedSIL = EnableSILSortOutput;
523525
if (OutputFile == "-") {
524-
CI.getSILModule()->print(llvm::outs(), CI.getMainModule(),
525-
SILOpts, !DisableASTDump);
526+
SILMod->print(llvm::outs(), CI.getMainModule(), SILOpts, !DisableASTDump);
526527
} else {
527528
std::error_code EC;
528529
llvm::raw_fd_ostream OS(OutputFile, EC, llvm::sys::fs::F_None);
@@ -531,8 +532,7 @@ int main(int argc, char **argv) {
531532
<< EC.message() << '\n';
532533
return finishDiagProcessing(1);
533534
}
534-
CI.getSILModule()->print(OS, CI.getMainModule(), SILOpts,
535-
!DisableASTDump);
535+
SILMod->print(OS, CI.getMainModule(), SILOpts, !DisableASTDump);
536536
}
537537
}
538538

0 commit comments

Comments
 (0)