Skip to content

Commit ccf472d

Browse files
committed
[NFC] Clean up performLLVM a bit
The only non-trivial bit is making the DiagnosticEngine parameter to swift::performLLVM required. No callers were taking advantage of this parameter allowing NULL.
1 parent 535bb9b commit ccf472d

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

include/swift/Subsystems.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ namespace swift {
6161
class SILModule;
6262
class SILParserTUState;
6363
class SourceFile;
64+
enum class SourceFileKind;
6465
class SourceManager;
6566
class SyntaxParseActions;
6667
class SyntaxParsingCache;
@@ -70,7 +71,6 @@ namespace swift {
7071
class TypeCheckerOptions;
7172
struct TypeLoc;
7273
class UnifiedStatsReporter;
73-
enum class SourceFileKind;
7474

7575
namespace Lowering {
7676
class TypeConverter;
@@ -286,29 +286,31 @@ namespace swift {
286286
StringRef OutputPath);
287287

288288
/// Turn the given LLVM module into native code and return true on error.
289-
bool performLLVM(const IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module,
290-
StringRef OutputFilename,
291-
UnifiedStatsReporter *Stats=nullptr);
289+
bool performLLVM(const IRGenOptions &Opts,
290+
ASTContext &Ctx,
291+
llvm::Module *Module,
292+
StringRef OutputFilename);
292293

293294
/// Run the LLVM passes. In multi-threaded compilation this will be done for
294295
/// multiple LLVM modules in parallel.
295-
/// \param Diags may be null if LLVM code gen diagnostics are not required.
296-
/// \param DiagMutex may also be null if a mutex around \p Diags is not
297-
/// required.
296+
/// \param Diags The Diagnostic Engine.
297+
/// \param DiagMutex in contexts that require parallel codegen, a mutex that the
298+
/// diagnostic engine uses to synchronize emission.
298299
/// \param HashGlobal used with incremental LLVMCodeGen to know if a module
299300
/// was already compiled, may be null if not desired.
300301
/// \param Module LLVM module to code gen, required.
301302
/// \param TargetMachine target of code gen, required.
302303
/// \param effectiveLanguageVersion version of the language, effectively.
303304
/// \param OutputFilename Filename for output.
304-
bool performLLVM(const IRGenOptions &Opts, DiagnosticEngine *Diags,
305+
bool performLLVM(const IRGenOptions &Opts,
306+
DiagnosticEngine &Diags,
305307
llvm::sys::Mutex *DiagMutex,
306308
llvm::GlobalVariable *HashGlobal,
307309
llvm::Module *Module,
308310
llvm::TargetMachine *TargetMachine,
309311
const version::Version &effectiveLanguageVersion,
310312
StringRef OutputFilename,
311-
UnifiedStatsReporter *Stats=nullptr);
313+
UnifiedStatsReporter *Stats);
312314

313315
/// Dump YAML describing all fixed-size types imported from the given module.
314316
bool performDumpTypeInfo(const IRGenOptions &Opts,

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,12 @@ llvm::BumpPtrAllocator &ASTContext::getAllocator(AllocationArena arena) const {
617617

618618
/// Set a new stats reporter.
619619
void ASTContext::setStatsReporter(UnifiedStatsReporter *stats) {
620-
Stats = stats;
621-
evaluator.setStatsReporter(stats);
622-
623620
if (stats) {
624621
stats->getFrontendCounters().NumASTBytesAllocated =
625622
getAllocator().getBytesAllocated();
626623
}
624+
evaluator.setStatsReporter(stats);
625+
Stats = stats;
627626
}
628627

629628
RC<syntax::SyntaxArena> ASTContext::getSyntaxArena() const {

lib/IRGen/IRGen.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -454,23 +454,22 @@ static void countStatsPostIRGen(UnifiedStatsReporter &Stats,
454454

455455
template<typename ...ArgTypes>
456456
void
457-
diagnoseSync(DiagnosticEngine *Diags, llvm::sys::Mutex *DiagMutex,
457+
diagnoseSync(DiagnosticEngine &Diags, llvm::sys::Mutex *DiagMutex,
458458
SourceLoc Loc, Diag<ArgTypes...> ID,
459459
typename swift::detail::PassArgument<ArgTypes>::type... Args) {
460-
if (!Diags)
461-
return;
462460
if (DiagMutex)
463461
DiagMutex->lock();
464462

465-
Diags->diagnose(Loc, ID, std::move(Args)...);
463+
Diags.diagnose(Loc, ID, std::move(Args)...);
466464

467465
if (DiagMutex)
468466
DiagMutex->unlock();
469467
}
470468

471469
/// Run the LLVM passes. In multi-threaded compilation this will be done for
472470
/// multiple LLVM modules in parallel.
473-
bool swift::performLLVM(const IRGenOptions &Opts, DiagnosticEngine *Diags,
471+
bool swift::performLLVM(const IRGenOptions &Opts,
472+
DiagnosticEngine &Diags,
474473
llvm::sys::Mutex *DiagMutex,
475474
llvm::GlobalVariable *HashGlobal,
476475
llvm::Module *Module,
@@ -975,7 +974,7 @@ performIRGeneration(const IRGenOptions &Opts, ModuleDecl *M,
975974
FrontendStatsTracer tracer(Ctx.Stats, "LLVM pipeline");
976975

977976
// Since no out module hash was set, we need to performLLVM.
978-
if (performLLVM(Opts, &IGM.Context.Diags, nullptr, IGM.ModuleHash,
977+
if (performLLVM(Opts, IGM.Context.Diags, nullptr, IGM.ModuleHash,
979978
IGM.getModule(), IGM.TargetMachine.get(),
980979
IGM.Context.LangOpts.EffectiveLanguageVersion,
981980
IGM.OutputFilename, IGM.Context.Stats))
@@ -1010,7 +1009,7 @@ struct LLVMCodeGenThreads {
10101009
<< IGM->OutputFilename << "\n";
10111010
diagMutex->unlock(););
10121011
embedBitcode(IGM->getModule(), parent.irgen->Opts);
1013-
performLLVM(parent.irgen->Opts, &IGM->Context.Diags, diagMutex,
1012+
performLLVM(parent.irgen->Opts, IGM->Context.Diags, diagMutex,
10141013
IGM->ModuleHash, IGM->getModule(), IGM->TargetMachine.get(),
10151014
IGM->Context.LangOpts.EffectiveLanguageVersion,
10161015
IGM->OutputFilename, IGM->Context.Stats);
@@ -1363,15 +1362,14 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
13631362
}
13641363
ASTSym->setSection(Section);
13651364
ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT));
1366-
::performLLVM(Opts, &Ctx.Diags, nullptr, nullptr, IGM.getModule(),
1365+
::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, IGM.getModule(),
13671366
IGM.TargetMachine.get(),
13681367
Ctx.LangOpts.EffectiveLanguageVersion,
1369-
OutputPath);
1368+
OutputPath, Ctx.Stats);
13701369
}
13711370

13721371
bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,
1373-
llvm::Module *Module, StringRef OutputFilename,
1374-
UnifiedStatsReporter *Stats) {
1372+
llvm::Module *Module, StringRef OutputFilename) {
13751373
// Build TargetMachine.
13761374
auto TargetMachine = createTargetMachine(Opts, Ctx);
13771375
if (!TargetMachine)
@@ -1382,10 +1380,10 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,
13821380
Module->setDataLayout(Clang->getTargetInfo().getDataLayout());
13831381

13841382
embedBitcode(Module, Opts);
1385-
if (::performLLVM(Opts, &Ctx.Diags, nullptr, nullptr, Module,
1383+
if (::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, Module,
13861384
TargetMachine.get(),
13871385
Ctx.LangOpts.EffectiveLanguageVersion,
1388-
OutputFilename, Stats))
1386+
OutputFilename, Ctx.Stats))
13891387
return true;
13901388
return false;
13911389
}

0 commit comments

Comments
 (0)