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

View File

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

View File

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

View File

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

View File

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