Only pass output filename and main input file name for debugging into IRGenModule constructor.

This commit is contained in:
David Ungar
2018-02-15 16:39:30 -07:00
parent dec78900cd
commit 026b850d0c
6 changed files with 34 additions and 35 deletions

View File

@@ -26,7 +26,8 @@ class IRGenModule;
/// Create an IRGen module. /// Create an IRGen module.
std::pair<IRGenerator *, IRGenModule *> std::pair<IRGenerator *, IRGenModule *>
createIRGenModule(SILModule *SILMod, const PrimarySpecificPaths &PSPs, createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
llvm::LLVMContext &LLVMContext); llvm::LLVMContext &LLVMContext);
/// Delete the IRGenModule and IRGenerator obtained by the above call. /// Delete the IRGenModule and IRGenerator obtained by the above call.

View File

@@ -666,7 +666,8 @@ static void initLLVMModule(const IRGenModule &IGM) {
std::pair<IRGenerator *, IRGenModule *> std::pair<IRGenerator *, IRGenModule *>
swift::irgen::createIRGenModule(SILModule *SILMod, swift::irgen::createIRGenModule(SILModule *SILMod,
const PrimarySpecificPaths &PSPs, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo,
llvm::LLVMContext &LLVMContext) { llvm::LLVMContext &LLVMContext) {
IRGenOptions Opts; IRGenOptions Opts;
@@ -678,7 +679,7 @@ swift::irgen::createIRGenModule(SILModule *SILMod,
// Create the IR emitter. // Create the IR emitter.
IRGenModule *IGM = IRGenModule *IGM =
new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext, new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext,
"", PSPs); "", OutputFilename, MainInputFilenameForDebugInfo);
initLLVMModule(*IGM); initLLVMModule(*IGM);
@@ -731,8 +732,9 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
if (!targetMachine) return nullptr; if (!targetMachine) return nullptr;
// Create the IR emitter. // Create the IR emitter.
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, IRGenModule IGM(irgen, std::move(targetMachine), nullptr, LLVMContext,
LLVMContext, ModuleName, PSPs); ModuleName, PSPs.OutputFilename,
PSPs.MainInputFilenameForDebugInfo);
initLLVMModule(IGM); initLLVMModule(IGM);
@@ -832,7 +834,7 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
if (performLLVM(Opts, &IGM.Context.Diags, nullptr, IGM.ModuleHash, if (performLLVM(Opts, &IGM.Context.Diags, nullptr, IGM.ModuleHash,
IGM.getModule(), IGM.TargetMachine.get(), IGM.getModule(), IGM.TargetMachine.get(),
IGM.Context.LangOpts.EffectiveLanguageVersion, IGM.Context.LangOpts.EffectiveLanguageVersion,
IGM.PSPs.OutputFilename, IGM.Context.Stats)) IGM.OutputFilename, IGM.Context.Stats))
return nullptr; return nullptr;
} }
@@ -842,17 +844,14 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
static void ThreadEntryPoint(IRGenerator *irgen, static void ThreadEntryPoint(IRGenerator *irgen,
llvm::sys::Mutex *DiagMutex, int ThreadIdx) { llvm::sys::Mutex *DiagMutex, int ThreadIdx) {
while (IRGenModule *IGM = irgen->fetchFromQueue()) { while (IRGenModule *IGM = irgen->fetchFromQueue()) {
DEBUG( DEBUG(DiagMutex->lock(); dbgs() << "thread " << ThreadIdx << ": fetched "
DiagMutex->lock(); << IGM->OutputFilename << "\n";
dbgs() << "thread " << ThreadIdx << ": fetched " << DiagMutex->unlock(););
IGM->PSPs.OutputFilename << "\n";
DiagMutex->unlock();
);
embedBitcode(IGM->getModule(), irgen->Opts); embedBitcode(IGM->getModule(), irgen->Opts);
performLLVM(irgen->Opts, &IGM->Context.Diags, DiagMutex, IGM->ModuleHash, performLLVM(irgen->Opts, &IGM->Context.Diags, DiagMutex, IGM->ModuleHash,
IGM->getModule(), IGM->TargetMachine.get(), IGM->getModule(), IGM->TargetMachine.get(),
IGM->Context.LangOpts.EffectiveLanguageVersion, IGM->Context.LangOpts.EffectiveLanguageVersion,
IGM->PSPs.OutputFilename, IGM->Context.Stats); IGM->OutputFilename, IGM->Context.Stats);
if (IGM->Context.Diags.hadAnyError()) if (IGM->Context.Diags.hadAnyError())
return; return;
} }
@@ -867,7 +866,6 @@ static void ThreadEntryPoint(IRGenerator *irgen,
/// All this is done in multiple threads. /// All this is done in multiple threads.
static void performParallelIRGeneration( static void performParallelIRGeneration(
IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr<SILModule> SILMod, IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr<SILModule> SILMod,
const SupplementaryOutputPaths &supplementaryOutputPathsForFirstInput,
StringRef ModuleName, int numThreads, StringRef ModuleName, int numThreads,
ArrayRef<std::string> outputFilenames) { ArrayRef<std::string> outputFilenames) {
@@ -914,12 +912,9 @@ static void performParallelIRGeneration(
auto Context = new LLVMContext(); auto Context = new LLVMContext();
// Create the IR emitter. // Create the IR emitter.
const bool isFirst = OutputIter == outputFilenames.begin(); IRGenModule *IGM =
IRGenModule *IGM = new IRGenModule( new IRGenModule(irgen, std::move(targetMachine), nextSF, *Context,
irgen, std::move(targetMachine), nextSF, *Context, ModuleName, ModuleName, *OutputIter++, nextSF->getFilename());
PrimarySpecificPaths(*OutputIter++, nextSF->getFilename(),
isFirst ? supplementaryOutputPathsForFirstInput
: SupplementaryOutputPaths()));
IGMcreated = true; IGMcreated = true;
initLLVMModule(*IGM); initLLVMModule(*IGM);
@@ -1088,8 +1083,7 @@ std::unique_ptr<llvm::Module> swift::performIRGeneration(
if (SILMod->getOptions().shouldPerformIRGenerationInParallel() && if (SILMod->getOptions().shouldPerformIRGenerationInParallel() &&
!parallelOutputFilenames.empty()) { !parallelOutputFilenames.empty()) {
auto NumThreads = SILMod->getOptions().NumThreads; auto NumThreads = SILMod->getOptions().NumThreads;
::performParallelIRGeneration(Opts, M, std::move(SILMod), ::performParallelIRGeneration(Opts, M, std::move(SILMod), ModuleName,
PSPs.SupplementaryOutputs, ModuleName,
NumThreads, parallelOutputFilenames); NumThreads, parallelOutputFilenames);
// TODO: Parallel LLVM compilation cannot be used if a (single) module is // TODO: Parallel LLVM compilation cannot be used if a (single) module is
// needed as return value. // needed as return value.
@@ -1127,9 +1121,8 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
auto targetMachine = irgen.createTargetMachine(); auto targetMachine = irgen.createTargetMachine();
if (!targetMachine) return; if (!targetMachine) return;
PrimarySpecificPaths PSPs(OutputPath);
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext, IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext,
OutputPath, PSPs); OutputPath, OutputPath, "");
initLLVMModule(IGM); initLLVMModule(IGM);
auto *Ty = llvm::ArrayType::get(IGM.Int8Ty, Buffer.size()); auto *Ty = llvm::ArrayType::get(IGM.Int8Ty, Buffer.size());
auto *Data = auto *Data =

View File

@@ -125,13 +125,16 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
IRGenModule::IRGenModule(IRGenerator &irgen, IRGenModule::IRGenModule(IRGenerator &irgen,
std::unique_ptr<llvm::TargetMachine> &&target, std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF, llvm::LLVMContext &LLVMContext, SourceFile *SF, llvm::LLVMContext &LLVMContext,
StringRef ModuleName, const PrimarySpecificPaths &PSPs) StringRef ModuleName, StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo)
: IRGen(irgen), Context(irgen.SIL.getASTContext()), : IRGen(irgen), Context(irgen.SIL.getASTContext()),
ClangCodeGen(createClangCodeGenerator(Context, LLVMContext, irgen.Opts, ClangCodeGen(createClangCodeGenerator(Context, LLVMContext, irgen.Opts,
ModuleName)), ModuleName)),
Module(*ClangCodeGen->GetModule()), LLVMContext(Module.getContext()), Module(*ClangCodeGen->GetModule()), LLVMContext(Module.getContext()),
DataLayout(target->createDataLayout()), Triple(irgen.getEffectiveClangTriple()), DataLayout(target->createDataLayout()),
TargetMachine(std::move(target)), silConv(irgen.SIL), PSPs(PSPs), Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
silConv(irgen.SIL), OutputFilename(OutputFilename),
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr), TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr),
ModuleHash(nullptr), ObjCInterop(Context.LangOpts.EnableObjCInterop), ModuleHash(nullptr), ObjCInterop(Context.LangOpts.EnableObjCInterop),
UseDarwinPreStableABIBit(Context.LangOpts.UseDarwinPreStableABIBit), UseDarwinPreStableABIBit(Context.LangOpts.UseDarwinPreStableABIBit),
@@ -413,7 +416,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None) if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None)
DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this, DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this,
Module, PSPs.MainInputFilenameForDebugInfo); Module,
MainInputFilenameForDebugInfo);
initClangTypeConverter(); initClangTypeConverter();

View File

@@ -25,7 +25,6 @@
#include "swift/Basic/ClusteredBitVector.h" #include "swift/Basic/ClusteredBitVector.h"
#include "swift/Basic/LLVM.h" #include "swift/Basic/LLVM.h"
#include "swift/Basic/OptimizationMode.h" #include "swift/Basic/OptimizationMode.h"
#include "swift/Basic/PrimarySpecificPaths.h"
#include "swift/Basic/SuccessorMap.h" #include "swift/Basic/SuccessorMap.h"
#include "swift/IRGen/ValueWitness.h" #include "swift/IRGen/ValueWitness.h"
#include "swift/SIL/SILFunction.h" #include "swift/SIL/SILFunction.h"
@@ -442,7 +441,8 @@ public:
ModuleDecl *ClangImporterModule = nullptr; ModuleDecl *ClangImporterModule = nullptr;
SourceFile *CurSourceFile = nullptr; SourceFile *CurSourceFile = nullptr;
PrimarySpecificPaths PSPs; llvm::SmallString<128> OutputFilename;
llvm::SmallString<128> MainInputFilenameForDebugInfo;
/// Order dependency -- TargetInfo must be initialized after Opts. /// Order dependency -- TargetInfo must be initialized after Opts.
const SwiftTargetInfo TargetInfo; const SwiftTargetInfo TargetInfo;
@@ -1043,7 +1043,8 @@ public:
std::unique_ptr<llvm::TargetMachine> &&target, std::unique_ptr<llvm::TargetMachine> &&target,
SourceFile *SF, llvm::LLVMContext &LLVMContext, SourceFile *SF, llvm::LLVMContext &LLVMContext,
StringRef ModuleName, StringRef ModuleName,
const PrimarySpecificPaths &PSPs); StringRef OutputFilename,
StringRef MainInputFilenameForDebugInfo);
~IRGenModule(); ~IRGenModule();
llvm::LLVMContext &getLLVMContext() const { return LLVMContext; } llvm::LLVMContext &getLLVMContext() const { return LLVMContext; }

View File

@@ -68,9 +68,8 @@ private:
: SILMod(SILModule::createEmptyModule(module, SILOpts)), : SILMod(SILModule::createEmptyModule(module, SILOpts)),
IRGen(IROpts, *SILMod), IRGen(IROpts, *SILMod),
IGM(IRGen, IRGen.createTargetMachine(), /*SourceFile*/ nullptr, IGM(IRGen, IRGen.createTargetMachine(), /*SourceFile*/ nullptr,
LLVMContext, "<fake module name>", LLVMContext, "<fake module name>", "<fake output filename>",
PrimarySpecificPaths("<fake output filename>", "<fake main input filename>") {}
"<fake main input filename>")) {}
public: public:
static std::unique_ptr<IRGenContext> static std::unique_ptr<IRGenContext>

View File

@@ -427,8 +427,9 @@ int main(int argc, char **argv) {
} else { } else {
auto *SILMod = CI.getSILModule(); auto *SILMod = CI.getSILModule();
{ {
const auto PSPs = CI.getPrimarySpecificPathsForAtMostOnePrimary();
auto T = irgen::createIRGenModule( auto T = irgen::createIRGenModule(
SILMod, CI.getPrimarySpecificPathsForAtMostOnePrimary(), SILMod, PSPs.OutputFilename, PSPs.MainInputFilenameForDebugInfo,
getGlobalLLVMContext()); getGlobalLLVMContext());
runCommandLineSelectedPasses(SILMod, T.second); runCommandLineSelectedPasses(SILMod, T.second);
irgen::deleteIRGenModule(T); irgen::deleteIRGenModule(T);