D34444: Teach codegen to work in incremental processing mode.

When isIncrementalProcessingEnabled is on we might want to produce multiple
llvm::Modules. This patch allows the clients to start a new llvm::Module,
allowing CodeGen to continue working after a HandleEndOfTranslationUnit call.

This should give the necessary facilities to write a unittest for D34059.

As discussed in the review this is meant to give us a way to proceed forward
in our efforts to upstream our interpreter-related patches. The design of this
will likely change soon.

llvm-svn: 311843
This commit is contained in:
Vassil Vassilev 2017-08-27 10:58:03 +00:00
parent 34ca7168ae
commit 4d54e543ab
2 changed files with 17 additions and 0 deletions

View File

@ -84,6 +84,10 @@ public:
/// code generator will schedule the entity for emission if a
/// definition has been registered with this code generator.
llvm::Constant *GetAddrOfGlobal(GlobalDecl decl, bool isForDefinition);
/// Create a new \c llvm::Module after calling HandleTranslationUnit. This
/// enable codegen in interactive processing environments.
llvm::Module* StartModule(llvm::StringRef ModuleName, llvm::LLVMContext &C);
};
/// CreateLLVMCodeGen - Create a CodeGenerator instance.

View File

@ -119,6 +119,14 @@ namespace {
return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
}
llvm::Module *StartModule(llvm::StringRef ModuleName,
llvm::LLVMContext &C) {
assert(!M && "Replacing existing Module?");
M.reset(new llvm::Module(ModuleName, C));
Initialize(*Ctx);
return M.get();
}
void Initialize(ASTContext &Context) override {
Ctx = &Context;
@ -317,6 +325,11 @@ llvm::Constant *CodeGenerator::GetAddrOfGlobal(GlobalDecl global,
->GetAddrOfGlobal(global, isForDefinition);
}
llvm::Module *CodeGenerator::StartModule(llvm::StringRef ModuleName,
llvm::LLVMContext &C) {
return static_cast<CodeGeneratorImpl*>(this)->StartModule(ModuleName, C);
}
CodeGenerator *clang::CreateLLVMCodeGen(
DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
const HeaderSearchOptions &HeaderSearchOpts,