Commit 8ae669b6 authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

CPU: Allow the use of precompiled headers when compiling generated code

This reduces compilation time by ~10x
parent 2bd9e144
......@@ -67,6 +67,7 @@ static std::string GetExecutablePath(const char* Argv0)
execution_state::execution_state()
: m_execution_engine{nullptr}
, pch_enabled(false)
{
}
......@@ -151,8 +152,17 @@ std::unique_ptr<llvm::Module> execution_state::compile(const string& source, con
// CodeGen options
auto& CGO = Clang->getInvocation().getCodeGenOpts();
// TODO: Debuginfo inclusion should be predicated
CGO.setDebugInfo(codegenoptions::FullDebugInfo);
if (pch_enabled)
{
// Preprocessor options
auto& PPO = Clang->getInvocation().getPreprocessorOpts();
PPO.ImplicitPCHInclude = "ngcpu.pch";
PPO.DisablePCHValidation = 1;
}
// Map code filename to a memoryBuffer
StringRef source_ref(source);
unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref);
......
......@@ -44,6 +44,9 @@ public:
execution_state();
~execution_state();
void enable_pch() { pch_enabled = true; }
void disable_pch() { pch_enabled = false; }
std::unique_ptr<llvm::Module> compile(const std::string& source, const std::string& name = "");
bool add_module(std::unique_ptr<llvm::Module>&);
......@@ -61,6 +64,7 @@ public:
private:
llvm::ExecutionEngine* m_execution_engine;
std::string jit_error;
bool pch_enabled;
template <typename signature>
std::function<signature> f_cast(void* f)
......
......@@ -59,6 +59,10 @@
#include "ngraph/runtime/cpu/external_function.hpp"
#include "ngraph/runtime/utils.hpp"
// TODO: Decide if we want to ship this or
// just enable it for developer build-test cycles
#define NGCPU_PCH
using namespace std;
using namespace ngraph::runtime::cpu;
......@@ -176,7 +180,7 @@ using namespace ngraph::element;
using namespace ngraph::runtime;
using namespace ngraph::runtime::cpu::eigen;
extern "C" void __entrypoint(ngraph::runtime::cpu::CallFrame* call_frame,
extern "C" void __entrypoint(ngraph::runtime::cpu::CallFrame* call_frame,
ngraph::runtime::TensorViewPtrs& tensor_views)
{
)";
......@@ -215,6 +219,11 @@ extern "C" void __entrypoint(ngraph::runtime::cpu::CallFrame* call_frame,
out.close();
ngraph::codegen::execution_state estate;
#if defined(NGCPU_PCH)
estate.enable_pch();
#endif
auto llvm_module = estate.compile(TU, "__ngcpu_codegen.cpp");
assert(llvm_module);
estate.add_module(llvm_module);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment