Skip to content

Commit d4baacf

Browse files
authored
Merge pull request #6289 from mxswd/less-memory
After performIRGeneration but before performLLVM delete the CompilerInstance if possible
2 parents bacda5a + 4497083 commit d4baacf

File tree

3 files changed

+170
-93
lines changed

3 files changed

+170
-93
lines changed

include/swift/Subsystems.h

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@
1919

2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/OptionSet.h"
22+
#include "swift/Basic/Version.h"
2223
#include "llvm/IR/LLVMContext.h"
2324
#include "llvm/ADT/ArrayRef.h"
2425
#include "llvm/ADT/Optional.h"
2526
#include "llvm/ADT/StringRef.h"
27+
#include "llvm/Support/Mutex.h"
2628

2729
#include <memory>
2830

2931
namespace llvm {
32+
class GlobalVariable;
3033
class MemoryBuffer;
3134
class Module;
3235
class TargetOptions;
@@ -258,18 +261,22 @@ namespace swift {
258261

259262
/// Turn the given Swift module into either LLVM IR or native code
260263
/// and return the generated LLVM IR module.
264+
/// If you set an outModuleHash, then you need to call performLLVM.
261265
std::unique_ptr<llvm::Module>
262266
performIRGeneration(IRGenOptions &Opts, ModuleDecl *M,
263267
std::unique_ptr<SILModule> SILMod,
264-
StringRef ModuleName, llvm::LLVMContext &LLVMContext);
268+
StringRef ModuleName, llvm::LLVMContext &LLVMContext,
269+
llvm::GlobalVariable **outModuleHash = nullptr);
265270

266271
/// Turn the given Swift module into either LLVM IR or native code
267272
/// and return the generated LLVM IR module.
273+
/// If you set an outModuleHash, then you need to call performLLVM.
268274
std::unique_ptr<llvm::Module>
269275
performIRGeneration(IRGenOptions &Opts, SourceFile &SF,
270276
std::unique_ptr<SILModule> SILMod,
271277
StringRef ModuleName, llvm::LLVMContext &LLVMContext,
272-
unsigned StartElem = 0);
278+
unsigned StartElem = 0,
279+
llvm::GlobalVariable **outModuleHash = nullptr);
273280

274281
/// Given an already created LLVM module, construct a pass pipeline and run
275282
/// the Swift LLVM Pipeline upon it. This does not cause the module to be
@@ -285,6 +292,29 @@ namespace swift {
285292
bool performLLVM(IRGenOptions &Opts, ASTContext &Ctx,
286293
llvm::Module *Module);
287294

295+
/// Run the LLVM passes. In multi-threaded compilation this will be done for
296+
/// multiple LLVM modules in parallel.
297+
/// \param Diags may be null if LLVM code gen diagnostics are not required.
298+
/// \param DiagMutex may also be null if a mutex around \p Diags is not
299+
/// required.
300+
/// \param HashGlobal used with incremental LLVMCodeGen to know if a module
301+
/// was already compiled, may be null if not desired.
302+
/// \param Module LLVM module to code gen, required.
303+
/// \param TargetMachine target of code gen, required.
304+
/// \param effectiveLanguageVersion version of the language, effectively.
305+
/// \param OutputFilename Filename for output.
306+
bool performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags,
307+
llvm::sys::Mutex *DiagMutex,
308+
llvm::GlobalVariable *HashGlobal,
309+
llvm::Module *Module,
310+
llvm::TargetMachine *TargetMachine,
311+
const version::Version &effectiveLanguageVersion,
312+
StringRef OutputFilename);
313+
314+
/// Creates a TargetMachine from the IRGen opts and AST Context.
315+
std::unique_ptr<llvm::TargetMachine>
316+
createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx);
317+
288318
/// A convenience wrapper for Parser functionality.
289319
class ParserUnit {
290320
public:

0 commit comments

Comments
 (0)