Skip to content

Commit 026b850

Browse files
committed
Only pass output filename and main input file name for debugging into IRGenModule constructor.
1 parent dec7890 commit 026b850

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

include/swift/IRGen/IRGenPublic.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class IRGenModule;
2626

2727
/// Create an IRGen module.
2828
std::pair<IRGenerator *, IRGenModule *>
29-
createIRGenModule(SILModule *SILMod, const PrimarySpecificPaths &PSPs,
29+
createIRGenModule(SILModule *SILMod, StringRef OutputFilename,
30+
StringRef MainInputFilenameForDebugInfo,
3031
llvm::LLVMContext &LLVMContext);
3132

3233
/// Delete the IRGenModule and IRGenerator obtained by the above call.

lib/IRGen/IRGen.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ static void initLLVMModule(const IRGenModule &IGM) {
666666

667667
std::pair<IRGenerator *, IRGenModule *>
668668
swift::irgen::createIRGenModule(SILModule *SILMod,
669-
const PrimarySpecificPaths &PSPs,
669+
StringRef OutputFilename,
670+
StringRef MainInputFilenameForDebugInfo,
670671
llvm::LLVMContext &LLVMContext) {
671672

672673
IRGenOptions Opts;
@@ -678,7 +679,7 @@ swift::irgen::createIRGenModule(SILModule *SILMod,
678679
// Create the IR emitter.
679680
IRGenModule *IGM =
680681
new IRGenModule(*irgen, std::move(targetMachine), nullptr, LLVMContext,
681-
"", PSPs);
682+
"", OutputFilename, MainInputFilenameForDebugInfo);
682683

683684
initLLVMModule(*IGM);
684685

@@ -731,8 +732,9 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
731732
if (!targetMachine) return nullptr;
732733

733734
// Create the IR emitter.
734-
IRGenModule IGM(irgen, std::move(targetMachine), nullptr,
735-
LLVMContext, ModuleName, PSPs);
735+
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, LLVMContext,
736+
ModuleName, PSPs.OutputFilename,
737+
PSPs.MainInputFilenameForDebugInfo);
736738

737739
initLLVMModule(IGM);
738740

@@ -832,7 +834,7 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
832834
if (performLLVM(Opts, &IGM.Context.Diags, nullptr, IGM.ModuleHash,
833835
IGM.getModule(), IGM.TargetMachine.get(),
834836
IGM.Context.LangOpts.EffectiveLanguageVersion,
835-
IGM.PSPs.OutputFilename, IGM.Context.Stats))
837+
IGM.OutputFilename, IGM.Context.Stats))
836838
return nullptr;
837839
}
838840

@@ -842,17 +844,14 @@ static std::unique_ptr<llvm::Module> performIRGeneration(IRGenOptions &Opts,
842844
static void ThreadEntryPoint(IRGenerator *irgen,
843845
llvm::sys::Mutex *DiagMutex, int ThreadIdx) {
844846
while (IRGenModule *IGM = irgen->fetchFromQueue()) {
845-
DEBUG(
846-
DiagMutex->lock();
847-
dbgs() << "thread " << ThreadIdx << ": fetched " <<
848-
IGM->PSPs.OutputFilename << "\n";
849-
DiagMutex->unlock();
850-
);
847+
DEBUG(DiagMutex->lock(); dbgs() << "thread " << ThreadIdx << ": fetched "
848+
<< IGM->OutputFilename << "\n";
849+
DiagMutex->unlock(););
851850
embedBitcode(IGM->getModule(), irgen->Opts);
852851
performLLVM(irgen->Opts, &IGM->Context.Diags, DiagMutex, IGM->ModuleHash,
853852
IGM->getModule(), IGM->TargetMachine.get(),
854853
IGM->Context.LangOpts.EffectiveLanguageVersion,
855-
IGM->PSPs.OutputFilename, IGM->Context.Stats);
854+
IGM->OutputFilename, IGM->Context.Stats);
856855
if (IGM->Context.Diags.hadAnyError())
857856
return;
858857
}
@@ -867,7 +866,6 @@ static void ThreadEntryPoint(IRGenerator *irgen,
867866
/// All this is done in multiple threads.
868867
static void performParallelIRGeneration(
869868
IRGenOptions &Opts, swift::ModuleDecl *M, std::unique_ptr<SILModule> SILMod,
870-
const SupplementaryOutputPaths &supplementaryOutputPathsForFirstInput,
871869
StringRef ModuleName, int numThreads,
872870
ArrayRef<std::string> outputFilenames) {
873871

@@ -914,12 +912,9 @@ static void performParallelIRGeneration(
914912
auto Context = new LLVMContext();
915913

916914
// Create the IR emitter.
917-
const bool isFirst = OutputIter == outputFilenames.begin();
918-
IRGenModule *IGM = new IRGenModule(
919-
irgen, std::move(targetMachine), nextSF, *Context, ModuleName,
920-
PrimarySpecificPaths(*OutputIter++, nextSF->getFilename(),
921-
isFirst ? supplementaryOutputPathsForFirstInput
922-
: SupplementaryOutputPaths()));
915+
IRGenModule *IGM =
916+
new IRGenModule(irgen, std::move(targetMachine), nextSF, *Context,
917+
ModuleName, *OutputIter++, nextSF->getFilename());
923918
IGMcreated = true;
924919

925920
initLLVMModule(*IGM);
@@ -1088,8 +1083,7 @@ std::unique_ptr<llvm::Module> swift::performIRGeneration(
10881083
if (SILMod->getOptions().shouldPerformIRGenerationInParallel() &&
10891084
!parallelOutputFilenames.empty()) {
10901085
auto NumThreads = SILMod->getOptions().NumThreads;
1091-
::performParallelIRGeneration(Opts, M, std::move(SILMod),
1092-
PSPs.SupplementaryOutputs, ModuleName,
1086+
::performParallelIRGeneration(Opts, M, std::move(SILMod), ModuleName,
10931087
NumThreads, parallelOutputFilenames);
10941088
// TODO: Parallel LLVM compilation cannot be used if a (single) module is
10951089
// needed as return value.
@@ -1127,9 +1121,8 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
11271121
auto targetMachine = irgen.createTargetMachine();
11281122
if (!targetMachine) return;
11291123

1130-
PrimarySpecificPaths PSPs(OutputPath);
11311124
IRGenModule IGM(irgen, std::move(targetMachine), nullptr, VMContext,
1132-
OutputPath, PSPs);
1125+
OutputPath, OutputPath, "");
11331126
initLLVMModule(IGM);
11341127
auto *Ty = llvm::ArrayType::get(IGM.Int8Ty, Buffer.size());
11351128
auto *Data =

lib/IRGen/IRGenModule.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,16 @@ static clang::CodeGenerator *createClangCodeGenerator(ASTContext &Context,
125125
IRGenModule::IRGenModule(IRGenerator &irgen,
126126
std::unique_ptr<llvm::TargetMachine> &&target,
127127
SourceFile *SF, llvm::LLVMContext &LLVMContext,
128-
StringRef ModuleName, const PrimarySpecificPaths &PSPs)
128+
StringRef ModuleName, StringRef OutputFilename,
129+
StringRef MainInputFilenameForDebugInfo)
129130
: IRGen(irgen), Context(irgen.SIL.getASTContext()),
130131
ClangCodeGen(createClangCodeGenerator(Context, LLVMContext, irgen.Opts,
131132
ModuleName)),
132133
Module(*ClangCodeGen->GetModule()), LLVMContext(Module.getContext()),
133-
DataLayout(target->createDataLayout()), Triple(irgen.getEffectiveClangTriple()),
134-
TargetMachine(std::move(target)), silConv(irgen.SIL), PSPs(PSPs),
134+
DataLayout(target->createDataLayout()),
135+
Triple(irgen.getEffectiveClangTriple()), TargetMachine(std::move(target)),
136+
silConv(irgen.SIL), OutputFilename(OutputFilename),
137+
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo),
135138
TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr),
136139
ModuleHash(nullptr), ObjCInterop(Context.LangOpts.EnableObjCInterop),
137140
UseDarwinPreStableABIBit(Context.LangOpts.UseDarwinPreStableABIBit),
@@ -413,7 +416,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
413416

414417
if (IRGen.Opts.DebugInfoKind > IRGenDebugInfoKind::None)
415418
DebugInfo = IRGenDebugInfo::createIRGenDebugInfo(IRGen.Opts, *CI, *this,
416-
Module, PSPs.MainInputFilenameForDebugInfo);
419+
Module,
420+
MainInputFilenameForDebugInfo);
417421

418422
initClangTypeConverter();
419423

lib/IRGen/IRGenModule.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/Basic/ClusteredBitVector.h"
2626
#include "swift/Basic/LLVM.h"
2727
#include "swift/Basic/OptimizationMode.h"
28-
#include "swift/Basic/PrimarySpecificPaths.h"
2928
#include "swift/Basic/SuccessorMap.h"
3029
#include "swift/IRGen/ValueWitness.h"
3130
#include "swift/SIL/SILFunction.h"
@@ -442,7 +441,8 @@ class IRGenModule {
442441
ModuleDecl *ClangImporterModule = nullptr;
443442
SourceFile *CurSourceFile = nullptr;
444443

445-
PrimarySpecificPaths PSPs;
444+
llvm::SmallString<128> OutputFilename;
445+
llvm::SmallString<128> MainInputFilenameForDebugInfo;
446446

447447
/// Order dependency -- TargetInfo must be initialized after Opts.
448448
const SwiftTargetInfo TargetInfo;
@@ -1043,7 +1043,8 @@ private: \
10431043
std::unique_ptr<llvm::TargetMachine> &&target,
10441044
SourceFile *SF, llvm::LLVMContext &LLVMContext,
10451045
StringRef ModuleName,
1046-
const PrimarySpecificPaths &PSPs);
1046+
StringRef OutputFilename,
1047+
StringRef MainInputFilenameForDebugInfo);
10471048
~IRGenModule();
10481049

10491050
llvm::LLVMContext &getLLVMContext() const { return LLVMContext; }

lib/RemoteAST/RemoteAST.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ struct IRGenContext {
6868
: SILMod(SILModule::createEmptyModule(module, SILOpts)),
6969
IRGen(IROpts, *SILMod),
7070
IGM(IRGen, IRGen.createTargetMachine(), /*SourceFile*/ nullptr,
71-
LLVMContext, "<fake module name>",
72-
PrimarySpecificPaths("<fake output filename>",
73-
"<fake main input filename>")) {}
71+
LLVMContext, "<fake module name>", "<fake output filename>",
72+
"<fake main input filename>") {}
7473

7574
public:
7675
static std::unique_ptr<IRGenContext>

tools/sil-opt/SILOpt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,9 @@ int main(int argc, char **argv) {
427427
} else {
428428
auto *SILMod = CI.getSILModule();
429429
{
430+
const auto PSPs = CI.getPrimarySpecificPathsForAtMostOnePrimary();
430431
auto T = irgen::createIRGenModule(
431-
SILMod, CI.getPrimarySpecificPathsForAtMostOnePrimary(),
432+
SILMod, PSPs.OutputFilename, PSPs.MainInputFilenameForDebugInfo,
432433
getGlobalLLVMContext());
433434
runCommandLineSelectedPasses(SILMod, T.second);
434435
irgen::deleteIRGenModule(T);

0 commit comments

Comments
 (0)