Skip to content

Commit 4ddb7f8

Browse files
committed
Use OptimizedIRRequest in SILLLVMGen
1 parent 485d5e9 commit 4ddb7f8

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

include/swift/AST/IRGenRequests.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ struct IRGenDescriptor {
160160
Lowering::TypeConverter &Conv, std::unique_ptr<SILModule> &&SILMod,
161161
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
162162
StringRef PrivateDiscriminator,
163-
llvm::GlobalVariable **outModuleHash) {
163+
llvm::GlobalVariable **outModuleHash = nullptr) {
164164
return IRGenDescriptor{file,
165165
Opts,
166166
TBDOpts,
@@ -180,8 +180,8 @@ struct IRGenDescriptor {
180180
Lowering::TypeConverter &Conv,
181181
std::unique_ptr<SILModule> &&SILMod, StringRef ModuleName,
182182
const PrimarySpecificPaths &PSPs,
183-
ArrayRef<std::string> parallelOutputFilenames,
184-
llvm::GlobalVariable **outModuleHash) {
183+
ArrayRef<std::string> parallelOutputFilenames = {},
184+
llvm::GlobalVariable **outModuleHash = nullptr) {
185185
return IRGenDescriptor{M,
186186
Opts,
187187
TBDOpts,

tools/sil-llvm-gen/SILLLVMGen.cpp

+31-23
Original file line numberDiff line numberDiff line change
@@ -178,34 +178,42 @@ int main(int argc, char **argv) {
178178
if (CI.setup(Invocation))
179179
return 1;
180180

181-
CI.performSema();
182-
183-
// If parsing produced an error, don't run any passes.
184-
if (CI.getASTContext().hadError())
181+
std::error_code EC;
182+
llvm::raw_fd_ostream outStream(OutputFilename, EC, llvm::sys::fs::F_None);
183+
if (outStream.has_error() || EC) {
184+
CI.getDiags().diagnose(SourceLoc(), diag::error_opening_output,
185+
OutputFilename, EC.message());
186+
outStream.clear_error();
185187
return 1;
188+
}
186189

187190
auto *mod = CI.getMainModule();
188191
assert(mod->getFiles().size() == 1);
189192

190-
std::unique_ptr<SILModule> SILMod;
191-
if (PerformWMO) {
192-
SILMod = performASTLowering(mod, CI.getSILTypes(), CI.getSILOptions());
193-
} else {
194-
SILMod = performASTLowering(*mod->getFiles()[0], CI.getSILTypes(),
195-
CI.getSILOptions());
196-
}
197-
198-
const PrimarySpecificPaths PSPs(OutputFilename, InputFilename);
199-
auto Mod = performIRGeneration(CI.getMainModule(), Opts,
200-
CI.getInvocation().getTBDGenOptions(),
201-
std::move(SILMod),
202-
CI.getMainModule()->getName().str(), PSPs,
203-
ArrayRef<std::string>());
204-
if (!Mod)
193+
auto getDescriptor = [&]() -> IRGenDescriptor {
194+
const auto &TBDOpts = Invocation.getTBDGenOptions();
195+
const auto &SILOpts = Invocation.getSILOptions();
196+
auto &SILTypes = CI.getSILTypes();
197+
auto moduleName = CI.getMainModule()->getName().str();
198+
const PrimarySpecificPaths PSPs(OutputFilename, InputFilename);
199+
200+
if (PerformWMO) {
201+
return IRGenDescriptor::forWholeModule(
202+
mod, Opts, TBDOpts, SILOpts, SILTypes,
203+
/*SILMod*/ nullptr, moduleName, PSPs);
204+
} else {
205+
return IRGenDescriptor::forFile(mod->getFiles()[0], Opts, TBDOpts,
206+
SILOpts, SILTypes, /*SILMod*/ nullptr,
207+
moduleName, PSPs, /*discriminator*/ "");
208+
}
209+
};
210+
211+
auto &eval = CI.getASTContext().evaluator;
212+
auto generatedMod = llvm::cantFail(eval(OptimizedIRRequest{getDescriptor()}));
213+
if (!generatedMod)
205214
return 1;
206215

207-
performLLVM(Opts, CI.getDiags(), /*diagMutex*/ nullptr, /*hash*/ nullptr,
208-
Mod.getModule(), Mod.getTargetMachine(), OutputFilename,
209-
CI.getASTContext().Stats);
210-
return CI.getASTContext().hadError();
216+
return compileAndWriteLLVM(generatedMod.getModule(),
217+
generatedMod.getTargetMachine(), Opts,
218+
CI.getStatsReporter(), CI.getDiags(), outStream);
211219
}

0 commit comments

Comments
 (0)