Sink linker directive computation into IRGen

With an inverted pipeline, IRGen needs to be able
to compute the linker directives itself, so sink
it down such that it can be computed by the
`IRGenDescriptor`.

(cherry picked from commit c0a2ea7d0e)
This commit is contained in:
Hamish Knight
2020-07-13 20:42:54 -07:00
committed by Jonas Devlieghere
parent 31c1cc26ea
commit 4daeb4fa3a
10 changed files with 78 additions and 77 deletions

View File

@@ -1500,24 +1500,21 @@ static bool serializeSIB(SILModule *SM, const PrimarySpecificPaths &PSPs,
}
static GeneratedModule
generateIR(const IRGenOptions &IRGenOpts,
generateIR(const IRGenOptions &IRGenOpts, const TBDGenOptions &TBDOpts,
std::unique_ptr<SILModule> SM,
const PrimarySpecificPaths &PSPs,
StringRef OutputFilename, ModuleOrSourceFile MSF,
llvm::GlobalVariable *&HashGlobal,
ArrayRef<std::string> parallelOutputFilenames,
llvm::StringSet<> &LinkerDirectives) {
ArrayRef<std::string> parallelOutputFilenames) {
if (auto *SF = MSF.dyn_cast<SourceFile *>()) {
return performIRGeneration(IRGenOpts, *SF,
return performIRGeneration(*SF, IRGenOpts, TBDOpts,
std::move(SM), OutputFilename, PSPs,
SF->getPrivateDiscriminator().str(),
&HashGlobal,
&LinkerDirectives);
&HashGlobal);
} else {
return performIRGeneration(IRGenOpts, MSF.get<ModuleDecl *>(),
return performIRGeneration(MSF.get<ModuleDecl *>(), IRGenOpts, TBDOpts,
std::move(SM), OutputFilename, PSPs,
parallelOutputFilenames,
&HashGlobal, &LinkerDirectives);
parallelOutputFilenames, &HashGlobal);
}
}
@@ -1662,19 +1659,6 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
OutputFilename, Instance.getStatsReporter());
}
static llvm::StringSet<>
collectLinkerDirectives(const CompilerInvocation &Invocation,
ModuleOrSourceFile MSF) {
auto tbdOpts = Invocation.getTBDGenOptions();
tbdOpts.LinkerDirectivesOnly = true;
if (auto *SF = MSF.dyn_cast<SourceFile *>()) {
return getPublicSymbols(TBDGenDescriptor::forFile(SF, tbdOpts));
} else {
return getPublicSymbols(
TBDGenDescriptor::forModule(MSF.get<ModuleDecl *>(), tbdOpts));
}
}
static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
std::unique_ptr<SILModule> SM,
ModuleOrSourceFile MSF,
@@ -1782,18 +1766,13 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
return processCommandLineAndRunImmediately(
Instance, std::move(SM), MSF, observer, ReturnValue);
llvm::StringSet<> LinkerDirectives;
collectLinkerDirectives(Invocation, MSF, LinkerDirectives);
// Don't proceed to IRGen if collecting linker directives failed.
if (Context.hadError())
return true;
StringRef OutputFilename = PSPs.OutputFilename;
std::vector<std::string> ParallelOutputFilenames =
opts.InputsAndOutputs.copyOutputFilenames();
llvm::GlobalVariable *HashGlobal;
auto IRModule = generateIR(
IRGenOpts, std::move(SM), PSPs, OutputFilename, MSF, HashGlobal,
ParallelOutputFilenames, LinkerDirectives);
IRGenOpts, Invocation.getTBDGenOptions(), std::move(SM), PSPs,
OutputFilename, MSF, HashGlobal, ParallelOutputFilenames);
// Just because we had an AST error it doesn't mean we can't performLLVM.
bool HadError = Instance.getASTContext().hadError();