[PATCH] D34444: Teach codegen to work in incremental processing mode.
Vassil Vassilev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 21 05:18:44 PDT 2017
v.g.vassilev created this revision.
When `isIncrementalProcessingEnabled` is on we might call multiple times `HandleEndOfTranslationUnit`. This would complete the `llvm::Module` CodeGen is writing to.
This patch allows the clients to start a new `llvm::Module`, allowing CodeGen to continue writing.
This should give the necessary facilities to write a unittest for https://reviews.llvm.org/D34059.
Repository:
rL LLVM
https://reviews.llvm.org/D34444
Files:
include/clang/CodeGen/ModuleBuilder.h
lib/CodeGen/ModuleBuilder.cpp
Index: lib/CodeGen/ModuleBuilder.cpp
===================================================================
--- lib/CodeGen/ModuleBuilder.cpp
+++ lib/CodeGen/ModuleBuilder.cpp
@@ -119,6 +119,14 @@
return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition));
}
+ llvm::Module *StartModule(llvm::StringRef ModuleName, llvm::LLVMContext& C,
+ const CodeGenOptions& CGO) {
+ 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 @@
->GetAddrOfGlobal(global, isForDefinition);
}
+llvm::Module *CodeGenerator::StartModule(const std::string& ModuleName,
+ llvm::LLVMContext& C) {
+ return static_cast<CodeGeneratorImpl*>(this)->StartModule(ModuleName, C);
+}
+
CodeGenerator *clang::CreateLLVMCodeGen(
DiagnosticsEngine &Diags, llvm::StringRef ModuleName,
const HeaderSearchOptions &HeaderSearchOpts,
Index: include/clang/CodeGen/ModuleBuilder.h
===================================================================
--- include/clang/CodeGen/ModuleBuilder.h
+++ include/clang/CodeGen/ModuleBuilder.h
@@ -84,6 +84,11 @@
/// 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,
+ const CodeGenOptions& CGO);
};
/// CreateLLVMCodeGen - Create a CodeGenerator instance.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34444.103358.patch
Type: text/x-patch
Size: 1882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170621/ebc3b258/attachment.bin>
More information about the cfe-commits
mailing list