Commit 24a21089 authored by Robert Kimball's avatar Robert Kimball

wip

parent 3f215a06
......@@ -89,14 +89,10 @@ static std::string GetExecutablePath(const char* Argv0)
}
StaticCompiler::StaticCompiler()
: m_precompiled_headers_enabled(false)
: m_precompiled_header_valid(false)
, m_debuginfo_enabled(false)
, m_source_name("code.cpp")
{
#if NGCPU_PCH
m_precompiled_headers_enabled = true;
#endif
#if NGCPU_DEBUGINFO
m_debuginfo_enabled = true;
#endif
......@@ -215,17 +211,6 @@ StaticCompiler::StaticCompiler()
CGO.setDebugInfo(codegenoptions::FullDebugInfo);
}
// if (!m_precompiled_header_valid)
// {
// }
if (m_precompiled_header_valid)
{
// Preprocessor options
auto& PPO = m_compiler->getInvocation().getPreprocessorOpts();
PPO.ImplicitPCHInclude = "ngcpu.pch";
PPO.DisablePCHValidation = 1;
}
// Enable various target features
// Most of these are for Eigen
auto& TO = m_compiler->getInvocation().getTargetOpts();
......@@ -317,7 +302,19 @@ void StaticCompiler::use_cached_files()
std::unique_ptr<llvm::Module> StaticCompiler::compile(const string& source)
{
generate_pch(source);
if (!m_precompiled_header_valid && m_precomiled_header_source.empty() == false)
{
NGRAPH_INFO << m_precomiled_header_source;
generate_pch(m_precomiled_header_source);
}
if (m_precompiled_header_valid)
{
NGRAPH_INFO;
// Preprocessor options
auto& PPO = m_compiler->getInvocation().getPreprocessorOpts();
PPO.ImplicitPCHInclude = m_pch_path;
PPO.DisablePCHValidation = 1;
}
// Map code filename to a memoryBuffer
StringRef source_ref(source);
......@@ -342,8 +339,8 @@ std::unique_ptr<llvm::Module> StaticCompiler::compile(const string& source)
void StaticCompiler::generate_pch(const string& source)
{
NGRAPH_INFO;
string pch_path = file_util::path_join(file_util::get_temp_directory(), "ngraph.pch");
m_compiler->getFrontendOpts().OutputFile = pch_path;
m_pch_path = file_util::path_join(file_util::get_temp_directory(), "ngraph.pch");
m_compiler->getFrontendOpts().OutputFile = m_pch_path;
// Map code filename to a memoryBuffer
StringRef source_ref(source);
......@@ -355,6 +352,7 @@ void StaticCompiler::generate_pch(const string& source)
if (m_compiler->ExecuteAction(*compilerAction) == true)
{
NGRAPH_INFO;
m_precompiled_header_valid = true;
}
buffer.release();
......
......@@ -62,20 +62,24 @@ public:
StaticCompiler();
~StaticCompiler();
void set_precompiled_headers_enabled(bool state) { m_precompiled_headers_enabled = state; }
bool is_precompiled_headers_enabled() { return m_precompiled_headers_enabled; }
void set_debuginfo_enabled(bool state) { m_debuginfo_enabled = state; }
bool is_debuginfo_enabled() { return m_debuginfo_enabled; }
void set_precomiled_header_source(const std::string& source)
{
m_precomiled_header_source = source;
}
void add_header_search_path(const std::string& path);
std::unique_ptr<llvm::Module> compile(const std::string& source);
void generate_pch(const std::string& source);
private:
std::unique_ptr<clang::CompilerInstance> m_compiler;
bool m_precompiled_headers_enabled;
bool m_precompiled_header_valid;
bool m_debuginfo_enabled;
std::string m_source_name;
std::vector<std::string> m_extra_search_path_list;
std::string m_pch_path;
std::string m_precomiled_header_source;
bool is_version_number(const std::string& path);
void use_cached_files();
......
......@@ -197,6 +197,7 @@ void ExternalFunction::compile()
using namespace ngraph::runtime::cpu::eigen;
)";
string pch_header_source = TU.get_code();
TU << "// Declare all functions\n";
for (shared_ptr<Function> f : pass_manager.get_state().get_functions())
......@@ -318,6 +319,8 @@ using namespace ngraph::runtime::cpu::eigen;
codegen::Compiler compiler;
codegen::ExecutionEngine execution_engine;
compiler.set_precomiled_header_source(pch_header_source);
auto llvm_module = compiler.compile(code);
if (llvm_module == nullptr)
{
......
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