Skip to content

Commit

Permalink
more accurate specsig tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Apr 13, 2018
1 parent 06b534e commit 50be707
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, jl_expr_t *ex)
// optimization: emit the correct name immediately, if we know it
// TODO: use `emitted` map here too to try to consolidate names?
if (li->specptr.fptr) {
if (specsig ? 1/*TODO*/ : li->invoke == jl_fptr_args) {
if (specsig ? li->isspecsig : li->invoke == jl_fptr_args) {
protoname = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)li->specptr.fptr, li);
need_to_emit = false;
}
Expand Down Expand Up @@ -3810,7 +3810,7 @@ static Function* gen_cfun_wrapper(
callptr = (void*)lam->inferred_const;
calltype = 2;
}
else if (lam->invoke != jl_fptr_sparam) {
else if (lam->isspecsig) {
callptr = lam->specptr.fptr;
calltype = 3;
}
Expand Down Expand Up @@ -6412,7 +6412,7 @@ void jl_compile_workqueue(
else if (li->invoke == &jl_fptr_args) {
preal_decl = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)li->specptr.fptr, li);
}
else if (li->invoke != &jl_fptr_sparam) {
else if (li->isspecsig) {
preal_decl = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)li->specptr.fptr, li);
preal_specsig = true;
}
Expand Down
7 changes: 0 additions & 7 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ class JuliaJITEventListener: public JITEventListener
#endif // defined(_OS_X86_64_)
#endif // defined(_OS_WINDOWS_)

std::vector<std::pair<jl_method_instance_t*, uintptr_t>> def_spec;
std::vector<std::pair<jl_method_instance_t*, uintptr_t>> def_invoke;
auto symbols = object::computeSymbolSizes(debugObj);
bool first = true;
for (const auto &sym_size : symbols) {
Expand Down Expand Up @@ -384,11 +382,6 @@ class JuliaJITEventListener: public JITEventListener
objectmap[SectionLoadAddr] = tmp;
first = false;
}
// now process these in order, so we ensure the closure values are updated before removing the trampoline
for (auto &def : def_spec)
def.first->specptr.fptr = (void*)def.second;
for (auto &def : def_invoke)
def.first->invoke = (jl_callptr_t)def.second;
}
uv_rwlock_wrunlock(&threadsafe);
jl_gc_safe_leave(ptls, gc_state);
Expand Down
1 change: 1 addition & 0 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ static jl_value_t *jl_deserialize_value_method_instance(jl_serializer_state *s,
abort();
}
li->inInference = 0;
li->isspecsig = 0;
li->specptr.fptr = NULL;
if (read_int8(s->s) == 2)
li->invoke = jl_fptr_const_return;
Expand Down
5 changes: 4 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,8 @@ JL_DLLEXPORT jl_method_instance_t* jl_set_method_inferred(
// changing rettype changes the llvm signature,
// so clear all of the llvm state at the same time
li->invoke = jl_fptr_trampoline;
li->isspecsig = 0;
li->specptr.fptr = NULL;
li->rettype = rettype;
jl_gc_wb(li, rettype);
li->inferred = inferred;
Expand All @@ -431,7 +433,6 @@ JL_DLLEXPORT jl_method_instance_t* jl_set_method_inferred(
assert(const_flags & 2);
li->invoke = jl_fptr_const_return;
}
li->specptr.fptr = NULL;
JL_GC_POP();
return li;
}
Expand Down Expand Up @@ -1773,6 +1774,7 @@ jl_callptr_t jl_compile_method_internal(jl_method_instance_t **pli, size_t world
if (jl_is_method(def) && def->unspecialized) {
jl_method_instance_t *unspec = def->unspecialized;
if (unspec->invoke != jl_fptr_trampoline) {
li->isspecsig = 0;
li->specptr = unspec->specptr;
li->inferred = unspec->inferred;
if (li->inferred)
Expand Down Expand Up @@ -1817,6 +1819,7 @@ JL_DLLEXPORT jl_value_t *jl_fptr_trampoline(jl_method_instance_t *m, jl_value_t
(void)jl_generate_fptr_for_unspecialized(unspec);
if (unspec->invoke) {
// use unspec pointers
m->isspecsig = 0;
m->specptr = unspec->specptr;
m->inferred = unspec->inferred;
if (m->inferred)
Expand Down
19 changes: 13 additions & 6 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,26 @@ static jl_callptr_t _jl_compile_linfo(
jl_llvm_functions_t decls = std::get<1>(def.second);
jl_value_t *rettype = std::get<2>(def.second);
jl_callptr_t addr;
if (decls.functionObject == "jl_fptr_args")
bool isspecsig = false;
if (decls.functionObject == "jl_fptr_args") {
addr = &jl_fptr_args;
else if (decls.functionObject == "jl_fptr_sparam")
}
else if (decls.functionObject == "jl_fptr_sparam") {
addr = &jl_fptr_sparam;
else
}
else {
addr = (jl_callptr_t)getAddressForFunction(decls.functionObject);
isspecsig = jl_egal(rettype, this_li->rettype);
}
if (this_li->compile_traced)
triggered_linfos.push_back(this_li);
if (this_li->invoke == jl_fptr_trampoline) {
// once set, don't change invoke-ptr, as that leads to race conditions
// with the (not) simultaneous updates to invoke and specptr
if (!decls.specFunctionObject.empty() && jl_egal(rettype, this_li->rettype))
if (!decls.specFunctionObject.empty()) {
this_li->specptr.fptr = (void*)getAddressForFunction(decls.specFunctionObject);
this_li->isspecsig = isspecsig;
}
this_li->invoke = addr;
}
else if (this_li->invoke == jl_fptr_const_return && !decls.specFunctionObject.empty()) {
Expand Down Expand Up @@ -725,15 +732,15 @@ StringRef JuliaOJIT::getFunctionAtAddress(uint64_t Addr, jl_method_instance_t *l
std::stringstream stream_fname;
// try to pick an appropriate name that describes it
if (Addr == (uintptr_t)li->invoke) {
stream_fname << "jlsysw_";
stream_fname << "jsysw_";
}
else if (li->invoke == &jl_fptr_args) {
stream_fname << "jsys1_";
}
else if (li->invoke == &jl_fptr_sparam) {
stream_fname << "jsys3_";
}
else if (li->invoke == &jl_fptr_sparam) {
else {
stream_fname << "jlsys_";
}
const char* unadorned_name = jl_symbol_name(li->def.method->name);
Expand Down
8 changes: 5 additions & 3 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ void jl_init_types(void)
jl_method_instance_type =
jl_new_datatype(jl_symbol("MethodInstance"), core,
jl_any_type, jl_emptysvec,
jl_perm_symsvec(13,
jl_perm_symsvec(14,
"def",
"specTypes",
"rettype",
Expand All @@ -2100,9 +2100,10 @@ void jl_init_types(void)
"max_world",
"inInference",
"",
"specsig",
"invoke",
"specptr"),
jl_svec(13,
jl_svec(14,
jl_new_struct(jl_uniontype_type, jl_method_type, jl_module_type),
jl_any_type,
jl_any_type,
Expand All @@ -2114,6 +2115,7 @@ void jl_init_types(void)
jl_long_type,
jl_bool_type,
jl_bool_type,
jl_bool_type,
jl_any_type, // fptr
jl_any_type), // fptr
0, 1, 4);
Expand Down Expand Up @@ -2194,8 +2196,8 @@ void jl_init_types(void)
#endif
jl_svecset(jl_methtable_type->types, 8, jl_int32_type); // uint32_t
jl_svecset(jl_method_type->types, 10, jl_method_instance_type);
jl_svecset(jl_method_instance_type->types, 11, jl_voidpointer_type);
jl_svecset(jl_method_instance_type->types, 12, jl_voidpointer_type);
jl_svecset(jl_method_instance_type->types, 13, jl_voidpointer_type);

jl_compute_field_offsets(jl_datatype_type);
jl_compute_field_offsets(jl_typename_type);
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ typedef struct _jl_method_instance_t {
size_t max_world;
uint8_t inInference; // flags to tell if inference is running on this function
uint8_t compile_traced; // if set will notify callback if this linfo is compiled
uint8_t isspecsig; // if specptr is specsig for specTypes->rettype
jl_callptr_t invoke; // jlcall entry point
jl_generic_specptr_t specptr;
} jl_method_instance_t;
Expand Down
1 change: 1 addition & 0 deletions src/method.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ JL_DLLEXPORT jl_method_instance_t *jl_new_method_instance_uninit(void)
li->sparam_vals = jl_emptysvec;
li->backedges = NULL;
li->invoke = jl_fptr_trampoline;
li->isspecsig = 0;
li->specptr.fptr = NULL;
li->compile_traced = 0;
li->specTypes = NULL;
Expand Down
8 changes: 6 additions & 2 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ static void jl_write_values(jl_serializer_state *s)
jl_method_instance_t *newm = (jl_method_instance_t*)&s->s->buf[reloc_offset];

newm->invoke = NULL;
newm->isspecsig = 0;
newm->specptr.fptr = NULL;
int8_t fptr_id = JL_API_TRAMPOLINE;
int8_t builtin_id = 0;
Expand Down Expand Up @@ -1004,10 +1005,13 @@ static void jl_update_all_fptrs(jl_serializer_state *s)
break;
}
void *fptr = (void*)(base + offset);
if (specfunc)
if (specfunc) {
li->specptr.fptr = fptr;
else
li->isspecsig = 1; // TODO: set only if actually true
}
else {
li->invoke = (jl_callptr_t)fptr;
}
jl_fptr_to_llvm(fptr, li, specfunc);
}
}
Expand Down

0 comments on commit 50be707

Please sign in to comment.