Skip to content

Commit e7ba87f

Browse files
author
David Ungar
authored
Merge pull request swiftlang#14230 from davidungar/PR-18-5-lldb-interface
[Batch Mode] Pass PrimarySpecificPaths through compiler. (4)
2 parents 15e8441 + 026b850 commit e7ba87f

24 files changed

+297
-148
lines changed

include/swift/AST/IRGenOptions.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ enum class IRGenEmbedMode : unsigned {
6464
/// The set of options supported by IR generation.
6565
class IRGenOptions {
6666
public:
67-
/// The name of the first input file, used by the debug info.
68-
std::string MainInputFilename;
69-
std::vector<std::string> OutputFilenames;
7067
std::string ModuleName;
7168

7269
/// The compilation directory for the debug info.
@@ -188,19 +185,6 @@ class IRGenOptions {
188185
UseSwiftCall(false), GenerateProfile(false), CmdArgs(),
189186
SanitizeCoverage(llvm::SanitizerCoverageOptions()) {}
190187

191-
/// Gets the name of the specified output filename.
192-
/// If multiple files are specified, the last one is returned.
193-
/// This function is used by (at least)
194-
/// lldb/source/Symbol/SwiftASTContext.cpp:4603
195-
/// FIXME: This function should go away in favor of
196-
/// Instance.getFrontendOptions().InputsAndOutputs.getSingleOutputFilename
197-
/// when batch mode handles all contingencies.
198-
StringRef getSingleOutputFilename() const {
199-
if (OutputFilenames.size() >= 1)
200-
return OutputFilenames.back();
201-
return StringRef();
202-
}
203-
204188
// Get a hash of all options which influence the llvm compilation but are not
205189
// reflected in the llvm module itself.
206190
unsigned getLLVMCodeGenOptionsHash() {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===--- PrimarySpecificPaths.h ---------------------------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_BASIC_PRIMARYSPECIFICPATHS_H
14+
#define SWIFT_BASIC_PRIMARYSPECIFICPATHS_H
15+
16+
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/SupplementaryOutputPaths.h"
18+
19+
#include <string>
20+
21+
namespace swift {
22+
class PrimarySpecificPaths {
23+
public:
24+
std::string OutputFilename;
25+
SupplementaryOutputPaths SupplementaryOutputs;
26+
27+
/// The name of the "main" input file, used by the debug info.
28+
std::string MainInputFilenameForDebugInfo;
29+
30+
PrimarySpecificPaths(
31+
std::string OutputFilename = std::string(),
32+
std::string MainInputFilenameForDebugInfo = std::string(),
33+
SupplementaryOutputPaths SupplementaryOutputs =
34+
SupplementaryOutputPaths())
35+
: OutputFilename(OutputFilename),
36+
SupplementaryOutputs(SupplementaryOutputs),
37+
MainInputFilenameForDebugInfo(MainInputFilenameForDebugInfo) {}
38+
};
39+
} // namespace swift
40+
41+
#endif /* SWIFT_BASIC_PRIMARYSPECIFICPATHS_H */

include/swift/Frontend/SupplementaryOutputPaths.h renamed to include/swift/Basic/SupplementaryOutputPaths.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ struct SupplementaryOutputPaths {
4747

4848
SupplementaryOutputPaths() = default;
4949
SupplementaryOutputPaths(const SupplementaryOutputPaths &) = default;
50+
51+
bool empty() const {
52+
return ObjCHeaderOutputPath.empty() && ModuleOutputPath.empty() &&
53+
ModuleDocOutputPath.empty() && DependenciesFilePath.empty() &&
54+
ReferenceDependenciesFilePath.empty() &&
55+
SerializedDiagnosticsPath.empty() && LoadedModuleTracePath.empty() &&
56+
TBDPath.empty();
57+
}
5058
};
5159
} // namespace swift
5260

include/swift/Frontend/ArgsToFrontendOutputsConverter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include "swift/AST/DiagnosticConsumer.h"
1717
#include "swift/AST/DiagnosticEngine.h"
1818
#include "swift/Basic/LLVM.h"
19+
#include "swift/Basic/SupplementaryOutputPaths.h"
1920
#include "swift/Frontend/FrontendOptions.h"
20-
#include "swift/Frontend/SupplementaryOutputPaths.h"
2121
#include "swift/Option/Options.h"
2222
#include "llvm/Option/ArgList.h"
2323

include/swift/Frontend/Frontend.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ class CompilerInvocation {
301301
bool hasSerializedAST() {
302302
return FrontendOpts.InputKind == InputFileKind::IFK_Swift_Library;
303303
}
304+
305+
PrimarySpecificPaths getPrimarySpecificPathsForAtMostOnePrimary();
306+
PrimarySpecificPaths getPrimarySpecificPathsForPrimary(StringRef filename);
304307
};
305308

306309
/// A class which manages the state and execution of the compiler.
@@ -578,6 +581,11 @@ class CompilerInstance {
578581
OptionSet<TypeCheckingFlags> TypeCheckOptions);
579582

580583
void finishTypeChecking(OptionSet<TypeCheckingFlags> TypeCheckOptions);
584+
585+
public:
586+
PrimarySpecificPaths getPrimarySpecificPathsForWholeModuleOptimizationMode();
587+
PrimarySpecificPaths getPrimarySpecificPathsForPrimary(StringRef filename);
588+
PrimarySpecificPaths getPrimarySpecificPathsForAtMostOnePrimary();
581589
};
582590

583591
} // namespace swift

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
#define SWIFT_FRONTEND_FRONTENDINPUTS_H
1515

1616
#include "swift/AST/Module.h"
17+
#include "swift/Basic/PrimarySpecificPaths.h"
18+
#include "swift/Basic/SupplementaryOutputPaths.h"
1719
#include "swift/Frontend/InputFile.h"
18-
#include "swift/Frontend/SupplementaryOutputPaths.h"
1920
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/ADT/MapVector.h"
2122

@@ -57,6 +58,12 @@ class FrontendInputsAndOutputs {
5758
return SupplementaryOutputs;
5859
}
5960

61+
/// When performing a compilation for zero or one primary input file,
62+
/// this will hold the PrimarySpecificPaths.
63+
/// In a future PR, each InputFile will hold its own PrimarySpecificPaths and
64+
/// this will go away.
65+
PrimarySpecificPaths PrimarySpecificPathsForAtMostOnePrimary;
66+
6067
FrontendInputsAndOutputs() = default;
6168
FrontendInputsAndOutputs(const FrontendInputsAndOutputs &other);
6269
FrontendInputsAndOutputs &operator=(const FrontendInputsAndOutputs &other);
@@ -181,6 +188,10 @@ class FrontendInputsAndOutputs {
181188
public:
182189
unsigned countOfInputsProducingMainOutputs() const;
183190

191+
bool hasInputsProducingMainOutputs() const {
192+
return countOfInputsProducingMainOutputs() != 0;
193+
}
194+
184195
const InputFile &firstInputProducingOutput() const;
185196
const InputFile &lastInputProducingOutput() const;
186197

@@ -210,6 +221,17 @@ class FrontendInputsAndOutputs {
210221
void forEachInputProducingSupplementaryOutput(
211222
llvm::function_ref<void(const InputFile &)> fn) const;
212223

224+
/// Assumes there is not more than one primary input file, if any.
225+
/// Otherwise, you would need to call getPrimarySpecificPathsForPrimary
226+
/// to tell it which primary input you wanted the outputs for.
227+
///
228+
/// Must not be constructed on-the-fly because some parts of the compiler
229+
/// receive StringRefs to its components, so it must live as long as the
230+
/// compiler.
231+
PrimarySpecificPaths &getPrimarySpecificPathsForAtMostOnePrimary();
232+
233+
PrimarySpecificPaths &getPrimarySpecificPathsForPrimary(StringRef filename);
234+
213235
bool hasDependenciesPath() const;
214236
bool hasReferenceDependenciesPath() const;
215237
bool hasObjCHeaderOutputPath() const;

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ class FrontendOptions {
275275
InputsAndOutputs.hasSingleInput();
276276
}
277277

278+
PrimarySpecificPaths getPrimarySpecificPathsForAtMostOnePrimary();
279+
PrimarySpecificPaths getPrimarySpecificPathsForPrimary(StringRef);
280+
278281
private:
279282
static bool canActionEmitDependencies(ActionType);
280283
static bool canActionEmitObjCHeader(ActionType);

include/swift/IRGen/IRGenPublic.h

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

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

3133
/// Delete the IRGenModule and IRGenerator obtained by the above call.
3234
void deleteIRGenModule(std::pair<IRGenerator *, IRGenModule *> &Module);

include/swift/Subsystems.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/OptionSet.h"
22+
#include "swift/Basic/PrimarySpecificPaths.h"
2223
#include "swift/Basic/Version.h"
2324
#include "llvm/IR/LLVMContext.h"
2425
#include "llvm/ADT/ArrayRef.h"
@@ -259,7 +260,9 @@ namespace swift {
259260
std::unique_ptr<llvm::Module>
260261
performIRGeneration(IRGenOptions &Opts, ModuleDecl *M,
261262
std::unique_ptr<SILModule> SILMod,
262-
StringRef ModuleName, llvm::LLVMContext &LLVMContext,
263+
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
264+
llvm::LLVMContext &LLVMContext,
265+
ArrayRef<std::string> parallelOutputFilenames,
263266
llvm::GlobalVariable **outModuleHash = nullptr);
264267

265268
/// Turn the given Swift module into either LLVM IR or native code
@@ -268,7 +271,8 @@ namespace swift {
268271
std::unique_ptr<llvm::Module>
269272
performIRGeneration(IRGenOptions &Opts, SourceFile &SF,
270273
std::unique_ptr<SILModule> SILMod,
271-
StringRef ModuleName, llvm::LLVMContext &LLVMContext,
274+
StringRef ModuleName, const PrimarySpecificPaths &PSPs,
275+
llvm::LLVMContext &LLVMContext,
272276
unsigned StartElem = 0,
273277
llvm::GlobalVariable **outModuleHash = nullptr);
274278

@@ -283,8 +287,8 @@ namespace swift {
283287
StringRef OutputPath);
284288

285289
/// Turn the given LLVM module into native code and return true on error.
286-
bool performLLVM(IRGenOptions &Opts, ASTContext &Ctx,
287-
llvm::Module *Module,
290+
bool performLLVM(IRGenOptions &Opts, ASTContext &Ctx, llvm::Module *Module,
291+
StringRef OutputFilename,
288292
UnifiedStatsReporter *Stats=nullptr);
289293

290294
/// Run the LLVM passes. In multi-threaded compilation this will be done for

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -829,18 +829,6 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
829829
if (Args.hasArg(OPT_autolink_force_load))
830830
Opts.ForceLoadSymbolName = Args.getLastArgValue(OPT_module_link_name);
831831

832-
// TODO: investigate whether these should be removed, in favor of definitions
833-
// in other classes.
834-
if (!SILOpts.SILOutputFileNameForDebugging.empty()) {
835-
Opts.MainInputFilename = SILOpts.SILOutputFileNameForDebugging;
836-
} else if (const InputFile *input =
837-
FrontendOpts.InputsAndOutputs.getUniquePrimaryInput()) {
838-
Opts.MainInputFilename = input->file();
839-
} else if (FrontendOpts.InputsAndOutputs.hasSingleInput()) {
840-
Opts.MainInputFilename =
841-
FrontendOpts.InputsAndOutputs.getFilenameOfFirstInput();
842-
}
843-
Opts.OutputFilenames = FrontendOpts.InputsAndOutputs.copyOutputFilenames();
844832
Opts.ModuleName = FrontendOpts.ModuleName;
845833

846834
if (Args.hasArg(OPT_use_jit))

0 commit comments

Comments
 (0)