Skip to content

Commit 56b50cb

Browse files
author
David Ungar
authored
Merge pull request #14349 from davidungar/PR-18-4b-refactor-performCompile
[Batch Mode] NFC: Carve up performCompile & performCompileStepsPostSILGen. (2)
2 parents 6829ff6 + 15011fb commit 56b50cb

File tree

11 files changed

+628
-493
lines changed

11 files changed

+628
-493
lines changed

include/swift/Frontend/Frontend.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,10 @@ class CompilerInstance {
521521
Optional<unsigned> BufferID);
522522

523523
public:
524-
/// Frees up the ASTContext and SILModule objects that this instance is
525-
/// holding on.
526-
void freeContextAndSIL();
524+
void freeASTContext();
525+
526+
/// Frees up the SILModule that this instance is holding on to.
527+
void freeSILModule();
527528

528529
private:
529530
/// Load stdlib & return true if should continue, i.e. no error

include/swift/Frontend/FrontendInputsAndOutputs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ class FrontendInputsAndOutputs {
104104

105105
bool hasPrimaryInputs() const { return primaryInputCount() > 0; }
106106

107+
bool hasMultiplePrimaryInputs() const { return primaryInputCount() > 1; }
108+
107109
/// Fails an assertion if there is more than one primary input.
108110
/// Used in situations where only one primary input can be handled
109111
/// and where batch mode has not been implemented yet.

include/swift/Frontend/FrontendOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ class FrontendOptions {
282282
/// Indicates whether the action will immediately run code.
283283
static bool isActionImmediate(ActionType);
284284

285+
/// \return true if action only parses without doing other compilation steps.
286+
static bool shouldActionOnlyParse(ActionType);
287+
285288
/// Return a hash code of any components from these options that should
286289
/// contribute to a Swift Bridging PCH hash.
287290
llvm::hash_code getPCHHashComponents() const {

include/swift/Migrator/Migrator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ class CompilerInstance;
2525

2626
namespace migrator {
2727

28-
/// Run the migrator on the compiler invocation's input file and emit a
29-
/// "replacement map" describing the requested changes to the source file.
30-
bool updateCodeAndEmitRemap(CompilerInstance *Instance,
31-
const CompilerInvocation &Invocation);
28+
/// If needed, run the migrator on the compiler invocation's input file and emit
29+
/// a "replacement map" describing the requested changes to the source file.
30+
/// \return true on error.
31+
bool updateCodeAndEmitRemapIfNeeded(CompilerInstance *Instance,
32+
const CompilerInvocation &Invocation);
3233

3334
struct Migrator {
3435
CompilerInstance *StartInstance;

include/swift/SILOptimizer/PassManager/Passes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ namespace swift {
6565
/// \brief Convert SIL to a lowered form suitable for IRGen.
6666
void runSILLoweringPasses(SILModule &M);
6767

68-
/// \brief Perform SIL Inst Count on M.
69-
void performSILInstCount(SILModule *M);
68+
/// \brief Perform SIL Inst Count on M if needed.
69+
void performSILInstCountIfNeeded(SILModule *M);
7070

7171
/// \brief Identifiers for all passes. Used to procedurally create passes from
7272
/// lists of passes.

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,12 @@ void CompilerInstance::performParseOnly(bool EvaluateConditionals) {
813813
"Loaded a module during parse-only");
814814
}
815815

816-
void CompilerInstance::freeContextAndSIL() {
816+
void CompilerInstance::freeASTContext() {
817817
Context.reset();
818-
TheSILModule.reset();
819818
MainModule = nullptr;
820819
SML = nullptr;
821820
PrimaryBufferIDs.clear();
822821
PrimarySourceFiles.clear();
823822
}
824823

824+
void CompilerInstance::freeSILModule() { TheSILModule.reset(); }

lib/Frontend/FrontendInputsAndOutputs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void FrontendInputsAndOutputs::forEachPrimaryInput(
100100
}
101101

102102
void FrontendInputsAndOutputs::assertMustNotBeMoreThanOnePrimaryInput() const {
103-
assert(primaryInputCount() < 2 &&
103+
assert(!hasMultiplePrimaryInputs() &&
104104
"have not implemented >1 primary input yet");
105105
}
106106

lib/Frontend/FrontendOptions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ bool FrontendOptions::isActionImmediate(ActionType action) {
9494
llvm_unreachable("Unknown ActionType");
9595
}
9696

97+
bool FrontendOptions::shouldActionOnlyParse(ActionType action) {
98+
switch (action) {
99+
case FrontendOptions::ActionType::Parse:
100+
case FrontendOptions::ActionType::DumpParse:
101+
case FrontendOptions::ActionType::EmitSyntax:
102+
case FrontendOptions::ActionType::DumpInterfaceHash:
103+
case FrontendOptions::ActionType::EmitImportedModules:
104+
return true;
105+
default:
106+
return false;
107+
}
108+
}
109+
97110
void FrontendOptions::forAllOutputPaths(
98111
const InputFile &input, std::function<void(const std::string &)> fn) const {
99112
if (RequestedAction != FrontendOptions::ActionType::EmitModuleOnly &&

0 commit comments

Comments
 (0)