Skip to content

Commit

Permalink
Merge pull request swiftlang#6289 from mxswd/less-memory
Browse files Browse the repository at this point in the history
After performIRGeneration but before performLLVM delete the CompilerInstance if possible
  • Loading branch information
jrose-apple authored Dec 15, 2016
2 parents bacda5a + 4497083 commit d4baacf
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 93 deletions.
34 changes: 32 additions & 2 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

#include "swift/Basic/LLVM.h"
#include "swift/Basic/OptionSet.h"
#include "swift/Basic/Version.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Mutex.h"

#include <memory>

namespace llvm {
class GlobalVariable;
class MemoryBuffer;
class Module;
class TargetOptions;
Expand Down Expand Up @@ -258,18 +261,22 @@ namespace swift {

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

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

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

/// Run the LLVM passes. In multi-threaded compilation this will be done for
/// multiple LLVM modules in parallel.
/// \param Diags may be null if LLVM code gen diagnostics are not required.
/// \param DiagMutex may also be null if a mutex around \p Diags is not
/// required.
/// \param HashGlobal used with incremental LLVMCodeGen to know if a module
/// was already compiled, may be null if not desired.
/// \param Module LLVM module to code gen, required.
/// \param TargetMachine target of code gen, required.
/// \param effectiveLanguageVersion version of the language, effectively.
/// \param OutputFilename Filename for output.
bool performLLVM(IRGenOptions &Opts, DiagnosticEngine *Diags,
llvm::sys::Mutex *DiagMutex,
llvm::GlobalVariable *HashGlobal,
llvm::Module *Module,
llvm::TargetMachine *TargetMachine,
const version::Version &effectiveLanguageVersion,
StringRef OutputFilename);

/// Creates a TargetMachine from the IRGen opts and AST Context.
std::unique_ptr<llvm::TargetMachine>
createTargetMachine(IRGenOptions &Opts, ASTContext &Ctx);

/// A convenience wrapper for Parser functionality.
class ParserUnit {
public:
Expand Down
Loading

0 comments on commit d4baacf

Please sign in to comment.