Skip to content

Commit

Permalink
Move streams to execution engine to guarantee initialization order
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed Apr 19, 2022
1 parent 1e84fb0 commit c936340
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ typedef Instruction TerminatorInst;
#include "processor.h"
#include "julia_assert.h"

jl_locked_stream dump_emitted_mi_name_stream;
extern "C" JL_DLLEXPORT
void jl_dump_emitted_mi_name_impl(void *s)
{
**dump_emitted_mi_name_stream = (JL_STREAM*)s;
**jl_ExecutionEngine->get_dump_emitted_mi_name_stream() = (JL_STREAM*)s;
}

extern "C" {
Expand Down Expand Up @@ -7978,7 +7977,7 @@ jl_llvm_functions_t jl_emit_code(
"functions compiled with custom codegen params must not be cached");
JL_TRY {
decls = emit_function(m, li, src, jlrettype, params);
auto stream = *dump_emitted_mi_name_stream;
auto stream = *jl_ExecutionEngine->get_dump_emitted_mi_name_stream();
if (stream) {
jl_printf(stream, "%s\t", decls.specFunctionObject.c_str());
// NOTE: We print the Type Tuple without surrounding quotes, because the quotes
Expand Down
14 changes: 6 additions & 8 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,15 @@ using namespace llvm;
#define DEBUG_TYPE "jitlayers"

// Snooping on which functions are being compiled, and how long it takes
jl_locked_stream dump_compiles_stream;
extern "C" JL_DLLEXPORT
void jl_dump_compiles_impl(void *s)
{
**dump_compiles_stream = (JL_STREAM*)s;
**jl_ExecutionEngine->get_dump_compiles_stream() = (JL_STREAM*)s;
}
jl_locked_stream dump_llvm_opt_stream;
extern "C" JL_DLLEXPORT
void jl_dump_llvm_opt_impl(void *s)
{
**dump_llvm_opt_stream = (JL_STREAM*)s;
**jl_ExecutionEngine->get_dump_llvm_opt_stream() = (JL_STREAM*)s;
}

static void jl_add_to_ee(orc::ThreadSafeModule &M, StringMap<orc::ThreadSafeModule*> &NewExports);
Expand Down Expand Up @@ -108,7 +106,7 @@ static jl_callptr_t _jl_compile_codeinst(
// caller must hold codegen_lock
// and have disabled finalizers
uint64_t start_time = 0;
bool timed = !!*dump_compiles_stream;
bool timed = !!*jl_ExecutionEngine->get_dump_compiles_stream();
if (timed)
start_time = jl_hrtime();

Expand Down Expand Up @@ -206,7 +204,7 @@ static jl_callptr_t _jl_compile_codeinst(
// then dump the method-instance specialization type to the stream
jl_method_instance_t *mi = codeinst->def;
if (jl_is_method(mi->def.method)) {
auto stream = *dump_compiles_stream;
auto stream = *jl_ExecutionEngine->get_dump_compiles_stream();
if (stream) {
jl_printf(stream, "%" PRIu64 "\t\"", end_time - start_time);
jl_static_show(stream, mi->specTypes);
Expand Down Expand Up @@ -894,7 +892,7 @@ namespace {
TSM.withModuleDo([&](Module &M) {
uint64_t start_time = 0;
{
auto stream = *dump_llvm_opt_stream;
auto stream = *jl_ExecutionEngine->get_dump_llvm_opt_stream();
if (stream) {
// Print LLVM function statistics _before_ optimization
// Print all the information about this invocation as a YAML object
Expand Down Expand Up @@ -923,7 +921,7 @@ namespace {

uint64_t end_time = 0;
{
auto stream = *dump_llvm_opt_stream;
auto stream = *jl_ExecutionEngine->get_dump_llvm_opt_stream();
if (stream) {
end_time = jl_hrtime();
jl_printf(stream, " time_ns: %" PRIu64 "\n", end_time - start_time);
Expand Down
15 changes: 15 additions & 0 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,16 @@ class JuliaOJIT {
JITDebugInfoRegistry &getDebugInfoRegistry() JL_NOTSAFEPOINT {
return DebugRegistry;
}

jl_locked_stream &get_dump_emitted_mi_name_stream() JL_NOTSAFEPOINT {
return dump_emitted_mi_name_stream;
}
jl_locked_stream &get_dump_compiles_stream() JL_NOTSAFEPOINT {
return dump_compiles_stream;
}
jl_locked_stream &get_dump_llvm_opt_stream() JL_NOTSAFEPOINT {
return dump_llvm_opt_stream;
}
private:
std::string getMangledName(StringRef Name);
std::string getMangledName(const GlobalValue *GV);
Expand All @@ -398,6 +408,11 @@ class JuliaOJIT {
int RLST_inc = 0;
DenseMap<void*, std::string> ReverseLocalSymbolTable;

//Compilation streams
jl_locked_stream dump_emitted_mi_name_stream;
jl_locked_stream dump_compiles_stream;
jl_locked_stream dump_llvm_opt_stream;

ResourcePool<orc::ThreadSafeContext> ContextPool;

#ifndef JL_USE_JITLINK
Expand Down

0 comments on commit c936340

Please sign in to comment.