Skip to content

Commit d51f704

Browse files
committed
Add codegen hooks for start and end of emit_function.
1 parent 4e3902d commit d51f704

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

base/reflection.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,15 +819,19 @@ struct CodegenParams
819819
module_setup::Any
820820
module_activation::Any
821821
raise_exception::Any
822+
emit_function::Any
823+
emitted_function::Any
822824

823825
CodegenParams(;cached::Bool=true,
824826
track_allocations::Bool=true, code_coverage::Bool=true,
825827
static_alloc::Bool=true, prefer_specsig::Bool=false,
826-
module_setup=nothing, module_activation=nothing, raise_exception=nothing) =
828+
module_setup=nothing, module_activation=nothing, raise_exception=nothing,
829+
emit_function=nothing, emitted_function=nothing) =
827830
new(Cint(cached),
828831
Cint(track_allocations), Cint(code_coverage),
829832
Cint(static_alloc), Cint(prefer_specsig),
830-
module_setup, module_activation, raise_exception)
833+
module_setup, module_activation, raise_exception,
834+
emit_function, emitted_function)
831835
end
832836

833837
# give a decent error message if we try to instantiate a staged function on non-leaf types

src/codegen.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5326,6 +5326,11 @@ static std::unique_ptr<Module> emit_function(
53265326
jl_array_t *stmts = ctx.code;
53275327
size_t stmtslen = jl_array_dim0(stmts);
53285328

5329+
if (JL_HOOK_TEST(ctx.params, emit_function)) {
5330+
JL_HOOK_CALL(ctx.params, emit_function, 3, (jl_value_t*)ctx.linfo,
5331+
(jl_value_t*)ctx.source, jl_box_ulong(world));
5332+
}
5333+
53295334
// step 1b. unpack debug information
53305335
int coverage_mode = jl_options.code_coverage;
53315336
int malloc_log_mode = jl_options.malloc_log;
@@ -6661,6 +6666,11 @@ static std::unique_ptr<Module> emit_function(
66616666
JL_UNLOCK(&m->writelock);
66626667
}
66636668

6669+
if (JL_HOOK_TEST(ctx.params, emitted_function)) {
6670+
JL_HOOK_CALL(ctx.params, emitted_function, 3, (jl_value_t*)ctx.linfo,
6671+
(jl_value_t*)ctx.source, jl_box_ulong(world));
6672+
}
6673+
66646674
JL_GC_POP();
66656675
return std::unique_ptr<Module>(M);
66666676
}

src/jltypes.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ jl_datatype_t *jl_boundserror_type;
133133
jl_value_t *jl_memory_exception;
134134
jl_value_t *jl_readonlymemory_exception;
135135

136-
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 0, NULL, NULL, NULL};
136+
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 0, NULL, NULL, NULL, NULL, NULL};
137137

138138
// --- type properties and predicates ---
139139

@@ -1657,6 +1657,8 @@ void jl_init_types(void)
16571657
jl_default_cgparams.module_setup = jl_nothing;
16581658
jl_default_cgparams.module_activation = jl_nothing;
16591659
jl_default_cgparams.raise_exception = jl_nothing;
1660+
jl_default_cgparams.emit_function = jl_nothing;
1661+
jl_default_cgparams.emitted_function = jl_nothing;
16601662

16611663
jl_emptysvec = (jl_svec_t*)jl_gc_permobj(sizeof(void*), jl_simplevector_type);
16621664
jl_svec_set_len_unsafe(jl_emptysvec, 0);

src/julia.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,6 +1933,16 @@ typedef struct {
19331933
// parameters: LLVMBasicBlockRef as Ptr{Cvoid}, LLVMValueRef as Ptr{Cvoid}
19341934
// return value: none
19351935
jl_value_t *raise_exception;
1936+
1937+
// emit function: start emission of a new function
1938+
// parameters: MethodInstance, CodeInfo, world age as UInt
1939+
// return value: none
1940+
jl_value_t *emit_function;
1941+
1942+
// emitted function: end emission of a new function
1943+
// parameters: MethodInstance, CodeInfo, world age as UInt
1944+
// return value: none
1945+
jl_value_t *emitted_function;
19361946
} jl_cgparams_t;
19371947
extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;
19381948

0 commit comments

Comments
 (0)