Skip to content

Commit

Permalink
Merge pull request JuliaLang#37252 from JuliaLang/tb/rm_hooks
Browse files Browse the repository at this point in the history
Remove most codegen hooks.
  • Loading branch information
maleadt committed Aug 31, 2020
2 parents 41e603e + e483e81 commit 116a7ef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 101 deletions.
12 changes: 1 addition & 11 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -962,30 +962,20 @@ struct CodegenParams
gnu_pubnames::Cint
debug_info_kind::Cint

module_setup::Any
module_activation::Any
raise_exception::Any
emit_function::Any
emitted_function::Any

lookup::Ptr{Cvoid}

generic_context::Any

function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
prefer_specsig::Bool=false,
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
emit_function=nothing, emitted_function=nothing,
lookup::Ptr{Cvoid}=cglobal(:jl_rettype_inferred),
generic_context = nothing)
return new(
Cint(track_allocations), Cint(code_coverage),
Cint(prefer_specsig),
Cint(gnu_pubnames), debug_info_kind,
module_setup, module_activation, raise_exception,
emit_function, emitted_function, lookup,
generic_context)
lookup, generic_context)
end
end

Expand Down
34 changes: 4 additions & 30 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ static Value *mark_callee_rooted(jl_codectx_t &ctx, Value *V)
#define JL_FEAT_TEST(ctx, feature) ((ctx).params->feature)


// --- hook checks ---

#define JL_HOOK_TEST(params,hook) ((params)->hook != jl_nothing)

#define JL_HOOK_CALL(params,hook,argc,...) \
_hook_call<argc>((params)->hook, {{__VA_ARGS__}});
template<int N>
static inline void _hook_call(jl_value_t *hook, std::array<jl_value_t*,N> args) {
jl_value_t **argv;
JL_GC_PUSHARGS(argv, N+1);
argv[0] = hook;
for (int i = 0; i < N; i++)
argv[i+1] = args[i];
jl_apply(argv, N+1);
JL_GC_POP();
}


// --- string constants ---
static Value *stringConstPtr(
jl_codegen_params_t &emission_context,
Expand Down Expand Up @@ -1061,13 +1043,7 @@ static void error_unless(jl_codectx_t &ctx, Value *cond, const std::string &msg)
static void raise_exception(jl_codectx_t &ctx, Value *exc,
BasicBlock *contBB=nullptr)
{
if (JL_HOOK_TEST(ctx.params, raise_exception)) {
JL_HOOK_CALL(ctx.params, raise_exception, 2,
jl_box_voidpointer(wrap(ctx.builder.GetInsertBlock())),
jl_box_voidpointer(wrap(exc)));
} else {
ctx.builder.CreateCall(prepare_call(jlthrow_func), { mark_callee_rooted(ctx, exc) });
}
ctx.builder.CreateCall(prepare_call(jlthrow_func), { mark_callee_rooted(ctx, exc) });
ctx.builder.CreateUnreachable();
if (!contBB) {
contBB = BasicBlock::Create(jl_LLVMContext, "after_throw", ctx.f);
Expand Down Expand Up @@ -2965,14 +2941,12 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
{
return
// language features
(a->track_allocations == b->track_allocations) &&
(a->code_coverage == b->code_coverage) &&
(a->prefer_specsig == b->prefer_specsig) &&
// hooks
(a->module_setup == b->module_setup) &&
(a->module_activation == b->module_activation) &&
(a->raise_exception == b->raise_exception) &&
(a->gnu_pubnames == b->gnu_pubnames) &&
(a->debug_info_kind == b->debug_info_kind) &&
(a->lookup == b->lookup) &&
(a->generic_context == b->generic_context);
}
#endif
44 changes: 11 additions & 33 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ extern "C" {
#else
1,
#endif
jl_default_debug_info_kind, NULL, NULL, NULL, NULL, NULL,
jl_default_debug_info_kind,
jl_rettype_inferred, NULL };
}

Expand Down Expand Up @@ -1634,11 +1634,6 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_

static void jl_setup_module(Module *m, const jl_cgparams_t *params = &jl_default_cgparams)
{
if (JL_HOOK_TEST(params, module_setup)) {
JL_HOOK_CALL(params, module_setup, 1, jl_box_voidpointer(wrap(m)));
return;
}

// Some linkers (*cough* OS X) don't understand DWARF v4, so we use v2 in
// imaging mode. The structure of v4 is slightly nicer for debugging JIT
// code.
Expand Down Expand Up @@ -5638,11 +5633,6 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
jl_array_t *stmts = ctx.code;
size_t stmtslen = jl_array_dim0(stmts);

if (JL_HOOK_TEST(ctx.params, emit_function)) {
JL_HOOK_CALL(ctx.params, emit_function, 2, (jl_value_t*)ctx.linfo,
(jl_value_t*)ctx.source);
}

// step 1b. unpack debug information
int coverage_mode = jl_options.code_coverage;
int malloc_log_mode = jl_options.malloc_log;
Expand Down Expand Up @@ -7044,11 +7034,6 @@ static std::pair<std::unique_ptr<Module>, jl_llvm_functions_t>
jl_Module->getFunction(FN)->setLinkage(GlobalVariable::PrivateLinkage);
}

if (JL_HOOK_TEST(ctx.params, emitted_function)) {
JL_HOOK_CALL(ctx.params, emitted_function, 2, (jl_value_t*)ctx.linfo,
(jl_value_t*)ctx.source);
}

JL_GC_POP();
return std::make_pair(std::unique_ptr<Module>(M), declarations);
}
Expand Down Expand Up @@ -7115,18 +7100,16 @@ jl_compile_result_t jl_emit_codeinst(
// Prepare debug info to receive this function
// record that this function name came from this linfo,
// so we can build a reverse mapping for debug-info.
if (!JL_HOOK_TEST(params.params, module_activation)) {
bool toplevel = !jl_is_method(codeinst->def->def.method);
if (!toplevel) {
const DataLayout &DL = m->getDataLayout();
// but don't remember toplevel thunks because
// they may not be rooted in the gc for the life of the program,
// and the runtime doesn't notify us when the code becomes unreachable :(
if (!specf.empty())
jl_add_code_in_flight(specf, codeinst, DL);
if (!f.empty() && f != "jl_fptr_args" && f != "jl_fptr_sparam")
jl_add_code_in_flight(f, codeinst, DL);
}
bool toplevel = !jl_is_method(codeinst->def->def.method);
if (!toplevel) {
const DataLayout &DL = m->getDataLayout();
// but don't remember toplevel thunks because
// they may not be rooted in the gc for the life of the program,
// and the runtime doesn't notify us when the code becomes unreachable :(
if (!specf.empty())
jl_add_code_in_flight(specf, codeinst, DL);
if (!f.empty() && f != "jl_fptr_args" && f != "jl_fptr_sparam")
jl_add_code_in_flight(f, codeinst, DL);
}

if (// don't alter `inferred` when the code is not directly being used
Expand Down Expand Up @@ -7531,11 +7514,6 @@ extern "C" void jl_init_llvm(void)
{
jl_page_size = jl_getpagesize();
imaging_mode = jl_options.image_codegen || (jl_generating_output() && !jl_options.incremental);
jl_default_cgparams.module_setup = jl_nothing;
jl_default_cgparams.module_activation = jl_nothing;
jl_default_cgparams.raise_exception = jl_nothing;
jl_default_cgparams.emit_function = jl_nothing;
jl_default_cgparams.emitted_function = jl_nothing;
jl_default_cgparams.generic_context = jl_nothing;
jl_init_debuginfo();

Expand Down
27 changes: 0 additions & 27 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2047,33 +2047,6 @@ typedef struct {
int debug_info_kind; // Enum for line-table-only, line-directives-only,
// limited, standalone

// hooks

// module setup: prepare a module for code emission (data layout, DWARF version, ...)
// parameters: LLVMModuleRef as Ptr{Cvoid}
// return value: none
jl_value_t *module_setup;

// module activation: registers debug info, adds module to JIT
// parameters: LLVMModuleRef as Ptr{Cvoid}
// return value: none
jl_value_t *module_activation;

// exception raising: emit LLVM instructions to raise an exception
// parameters: LLVMBasicBlockRef as Ptr{Cvoid}, LLVMValueRef as Ptr{Cvoid}
// return value: none
jl_value_t *raise_exception;

// emit function: start emission of a new function
// parameters: MethodInstance, CodeInfo, world age as UInt
// return value: none
jl_value_t *emit_function;

// emitted function: end emission of a new function
// parameters: MethodInstance, CodeInfo, world age as UInt
// return value: none
jl_value_t *emitted_function;

// Cache access. Default: jl_rettype_inferred.
jl_codeinstance_lookup_t lookup;

Expand Down

0 comments on commit 116a7ef

Please sign in to comment.