Skip to content

Commit

Permalink
Split up libcxx and the runtime, enabling lazy compilation of libcxx
Browse files Browse the repository at this point in the history
  • Loading branch information
jthorborg committed Mar 26, 2018
1 parent ab31a8f commit 3897c35
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 6 deletions.
31 changes: 31 additions & 0 deletions compilation perf test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
VANILLA

Cold compilation W rt debug: 4000
Cold compilation W/O rt debug: 2000
Warm compilation W/O rt debug: 1912

Runtime size: 2381kb
Source size: 180kb

Getting first symbol: 1151ms (jitting)

Clang source: 676ms

printing 180kb source: 8ms

parsing source llvm ir: 13 ms
parsing runtime llvm ir: 100 ms

IMPLEMENTING BITCODE

Runtime size: 534kb
Source size: 54kb

printing 54kb source: 11ms

Cold compilation W rt debug: 4174
Cold compilation W/O rt debug: 2000
Warm compilation W/O rt debug: 1800

parsing source llvm ir: N/A
parsing runtime llvm ir: 43 ms
17 changes: 17 additions & 0 deletions make/skeleton/compilers/CppAPE/runtime/libcxx.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#include <cstdarg>
#include <cstddef>

void *operator new(std::size_t am);
void operator delete(void * loc);

extern "C"
{
int vsnprintf(char * s, size_t n, const char * format, va_list arg);
int snprintf(char * s, size_t n, const char * format, ...);

void abort();
};

int printf(const char * fmt, ...);


#include "libcxx-src/string.cpp"
#include "libcxx-src/exception.cpp"
#include "libcxx-src/vector.cpp"
Expand Down
4 changes: 1 addition & 3 deletions make/skeleton/compilers/CppAPE/runtime/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,4 @@ extern "C"
return p ? p->onEvent(event) : Status(Status::Error);
}

};

#include "libcxx.cpp"
};
8 changes: 7 additions & 1 deletion projects/cppape/src/CppAPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void DeleteCompiler(ape::ProtoCompiler * toBeDeleted)

namespace CppAPE
{
std::shared_ptr<CxxJitContext> ScriptCompiler::acquireCxxRuntime()
{
static std::shared_ptr<CxxJitContext> cxxRuntime;
return cxxRuntime;
}


ScriptCompiler::ScriptCompiler() {}
Expand Down Expand Up @@ -171,7 +176,8 @@ namespace CppAPE


state->addTranslationUnit(projectUnit);
state->addTranslationUnit(runtimeUnit);
state->addTranslationUnit(CxxTranslationUnit::loadSaved((dirRoot / "runtime" / "runtime.bc").string(), state.get()));
state->addTranslationUnit(CxxTranslationUnit::loadSaved((dirRoot / "runtime" / "libcxx.bc").string(), state.get()));
}
catch (const std::exception& e)
{
Expand Down
3 changes: 2 additions & 1 deletion projects/cppape/src/CppAPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ namespace CppAPE
/// Mutual (os-wide) exclusion should be provided by the parent caller.
/// </summary>
bool SetupEnvironment();
static std::shared_ptr<CxxJitContext> acquireCxxRuntime();

std::unique_ptr<CxxJitContext> state;
ScriptPlugin plugin;

ScriptInstance * pluginData = nullptr;
PluginGlobalData * globalData = nullptr;

std::shared_ptr<CxxTranslationUnit> cxxRuntime;
};
};

Expand Down
10 changes: 9 additions & 1 deletion projects/cppape/src/EnvironmentSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace CppAPE
{
auto root = fs::path(cpl::Misc::DirectoryPath());

if (fs::exists(root / "runtime" / "runtime.bc"))
if (fs::exists(root / "runtime" / "runtime.bc") && fs::exists(root / "runtime" / "libcxx.bc"))
return true;


Expand Down Expand Up @@ -99,6 +99,14 @@ namespace CppAPE
.fromFile((root / "runtime" / "runtime.cpp").string())
.save((root / "runtime" / "runtime.bc").string());

print("runtime.cpp -> runtime.bc");

builder
.fromFile((root / "runtime" / "libcxx.cpp").string())
.save((root / "runtime" / "libcxx.bc").string());

print("libcxx.cpp -> libcxx.bc");

return true;
}
catch (const CxxTranslationUnit::CompilationException& e)
Expand Down
1 change: 1 addition & 0 deletions projects/cppape/src/libCppJit.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ LIBCPPJIT_EXPORT const char * jit_format_error(jit_error_t error);
LIBCPPJIT_EXPORT jit_error_t jit_create_context(jit_context** result, jit_shared_mcontext* mcontext);
LIBCPPJIT_EXPORT jit_error_t jit_add_translation_unit(jit_context * c, const translation_unit* unit);
LIBCPPJIT_EXPORT jit_error_t jit_set_callback(jit_context * c, void * callback_context, jit_error_callback cb);
LIBCPPJIT_EXPORT jit_error_t jit_link_other_context(jit_context * c, jit_context* other);
LIBCPPJIT_EXPORT jit_error_t jit_delete_context(jit_context * c);
LIBCPPJIT_EXPORT jit_error_t jit_get_symbol(jit_context * c, const char * name, void ** ret);
LIBCPPJIT_EXPORT jit_error_t jit_inject_symbol(jit_context * c, const char * name, void * location);
Expand Down

0 comments on commit 3897c35

Please sign in to comment.