Skip to content

Commit f9d7066

Browse files
committed
[IRGen] Hash compiler version instead of lang version
The LLVM passes we apply don't depend on the language version, only the compiler version.
1 parent 45f11c8 commit f9d7066

File tree

4 files changed

+13
-24
lines changed

4 files changed

+13
-24
lines changed

include/swift/Subsystems.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,13 @@ namespace swift {
251251
/// was already compiled, may be null if not desired.
252252
/// \param Module LLVM module to code gen, required.
253253
/// \param TargetMachine target of code gen, required.
254-
/// \param effectiveLanguageVersion version of the language, effectively.
255254
/// \param OutputFilename Filename for output.
256255
bool performLLVM(const IRGenOptions &Opts,
257256
DiagnosticEngine &Diags,
258257
llvm::sys::Mutex *DiagMutex,
259258
llvm::GlobalVariable *HashGlobal,
260259
llvm::Module *Module,
261260
llvm::TargetMachine *TargetMachine,
262-
const version::Version &effectiveLanguageVersion,
263261
StringRef OutputFilename,
264262
UnifiedStatsReporter *Stats);
265263

lib/Basic/Version.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ std::string getSwiftFullVersion(Version effectiveVersion) {
405405
OS << "-dev";
406406
#endif
407407

408-
if (!(effectiveVersion == Version::getCurrentLanguageVersion())) {
408+
if (effectiveVersion != Version::getCurrentLanguageVersion()) {
409409
OS << " effective-" << effectiveVersion;
410410
}
411411

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,16 +1648,14 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
16481648
const auto &opts = Instance.getInvocation().getIRGenOptions();
16491649
std::unique_ptr<llvm::TargetMachine> TargetMachine =
16501650
createTargetMachine(opts, Instance.getASTContext());
1651-
version::Version EffectiveLanguageVersion =
1652-
Instance.getASTContext().LangOpts.EffectiveLanguageVersion;
16531651

16541652
// Free up some compiler resources now that we have an IRModule.
16551653
freeASTContextIfPossible(Instance);
16561654

16571655
// Now that we have a single IR Module, hand it over to performLLVM.
16581656
return performLLVM(opts, Instance.getDiags(), nullptr, HashGlobal, IRModule,
1659-
TargetMachine.get(), EffectiveLanguageVersion,
1660-
OutputFilename, Instance.getStatsReporter());
1657+
TargetMachine.get(), OutputFilename,
1658+
Instance.getStatsReporter());
16611659
}
16621660

16631661
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,

lib/IRGen/IRGen.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -356,23 +356,23 @@ class MD5Stream : public llvm::raw_ostream {
356356

357357
/// Computes the MD5 hash of the llvm \p Module including the compiler version
358358
/// and options which influence the compilation.
359-
static void getHashOfModule(MD5::MD5Result &Result, const IRGenOptions &Opts,
360-
const llvm::Module *Module,
361-
llvm::TargetMachine *TargetMachine,
362-
version::Version const& effectiveLanguageVersion) {
359+
static MD5::MD5Result getHashOfModule(const IRGenOptions &Opts,
360+
const llvm::Module *Module) {
363361
// Calculate the hash of the whole llvm module.
364362
MD5Stream HashStream;
365363
llvm::WriteBitcodeToFile(*Module, HashStream);
366364

367365
// Update the hash with the compiler version. We want to recompile if the
368366
// llvm pipeline of the compiler changed.
369-
HashStream << version::getSwiftFullVersion(effectiveLanguageVersion);
367+
HashStream << version::getSwiftFullVersion();
370368

371369
// Add all options which influence the llvm compilation but are not yet
372370
// reflected in the llvm module itself.
373371
Opts.writeLLVMCodeGenOptionsTo(HashStream);
374372

375-
HashStream.final(Result);
373+
MD5::MD5Result result;
374+
HashStream.final(result);
375+
return result;
376376
}
377377

378378
/// Returns false if the hash of the current module \p HashData matches the
@@ -477,27 +477,24 @@ bool swift::performLLVM(const IRGenOptions &Opts,
477477
llvm::GlobalVariable *HashGlobal,
478478
llvm::Module *Module,
479479
llvm::TargetMachine *TargetMachine,
480-
const version::Version &effectiveLanguageVersion,
481480
StringRef OutputFilename,
482481
UnifiedStatsReporter *Stats) {
483482

484483
if (Opts.UseIncrementalLLVMCodeGen && HashGlobal) {
485484
// Check if we can skip the llvm part of the compilation if we have an
486485
// existing object file which was generated from the same llvm IR.
487-
MD5::MD5Result Result;
488-
getHashOfModule(Result, Opts, Module, TargetMachine,
489-
effectiveLanguageVersion);
486+
auto hash = getHashOfModule(Opts, Module);
490487

491488
LLVM_DEBUG(
492489
if (DiagMutex) DiagMutex->lock();
493490
SmallString<32> ResultStr;
494-
MD5::stringifyResult(Result, ResultStr);
491+
MD5::stringifyResult(hash, ResultStr);
495492
llvm::dbgs() << OutputFilename << ": MD5=" << ResultStr << '\n';
496493
if (DiagMutex) DiagMutex->unlock();
497494
);
498495

499-
ArrayRef<uint8_t> HashData(reinterpret_cast<uint8_t *>(&Result),
500-
sizeof(Result));
496+
ArrayRef<uint8_t> HashData(reinterpret_cast<uint8_t *>(&hash),
497+
sizeof(hash));
501498
if (Opts.OutputKind == IRGenOutputKind::ObjectFile &&
502499
!Opts.PrintInlineTree &&
503500
!needsRecompile(OutputFilename, HashData, HashGlobal, DiagMutex)) {
@@ -1003,7 +1000,6 @@ GeneratedModule IRGenRequest::evaluate(Evaluator &evaluator,
10031000
// Since no out module hash was set, we need to performLLVM.
10041001
if (performLLVM(Opts, IGM.Context.Diags, nullptr, IGM.ModuleHash,
10051002
IGM.getModule(), IGM.TargetMachine.get(),
1006-
IGM.Context.LangOpts.EffectiveLanguageVersion,
10071003
IGM.OutputFilename, IGM.Context.Stats))
10081004
return GeneratedModule::null();
10091005
}
@@ -1038,7 +1034,6 @@ struct LLVMCodeGenThreads {
10381034
embedBitcode(IGM->getModule(), parent.irgen->Opts);
10391035
performLLVM(parent.irgen->Opts, IGM->Context.Diags, diagMutex,
10401036
IGM->ModuleHash, IGM->getModule(), IGM->TargetMachine.get(),
1041-
IGM->Context.LangOpts.EffectiveLanguageVersion,
10421037
IGM->OutputFilename, IGM->Context.Stats);
10431038
if (IGM->Context.Diags.hadAnyError())
10441039
return;
@@ -1389,7 +1384,6 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
13891384
ASTSym->setAlignment(llvm::MaybeAlign(serialization::SWIFTMODULE_ALIGNMENT));
13901385
::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, IGM.getModule(),
13911386
IGM.TargetMachine.get(),
1392-
Ctx.LangOpts.EffectiveLanguageVersion,
13931387
OutputPath, Ctx.Stats);
13941388
}
13951389

@@ -1407,7 +1401,6 @@ bool swift::performLLVM(const IRGenOptions &Opts, ASTContext &Ctx,
14071401
embedBitcode(Module, Opts);
14081402
if (::performLLVM(Opts, Ctx.Diags, nullptr, nullptr, Module,
14091403
TargetMachine.get(),
1410-
Ctx.LangOpts.EffectiveLanguageVersion,
14111404
OutputFilename, Ctx.Stats))
14121405
return true;
14131406
return false;

0 commit comments

Comments
 (0)