Skip to content

Commit

Permalink
Add a codegen param for preferring specsig.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Sep 4, 2017
1 parent 488febc commit 47986fa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -745,19 +745,20 @@ struct CodegenParams
code_coverage::Cint
static_alloc::Cint
dynamic_alloc::Cint
prefer_specsig::Cint

hooks::CodegenHooks

CodegenParams(;cached::Bool=true,
runtime::Bool=true, exceptions::Bool=true,
track_allocations::Bool=true, code_coverage::Bool=true,
static_alloc::Bool=true, dynamic_alloc::Bool=true,
hooks::CodegenHooks=CodegenHooks()) =
prefer_specsig::Bool=false, hooks::CodegenHooks=CodegenHooks()) =
new(Cint(cached),
Cint(runtime), Cint(exceptions),
Cint(track_allocations), Cint(code_coverage),
Cint(static_alloc), Cint(dynamic_alloc),
hooks)
Cint(prefer_specsig), hooks)
end

# Printing code representations in IR and assembly
Expand Down
1 change: 1 addition & 0 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2355,6 +2355,7 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
(a->code_coverage == b->code_coverage) &&
(a->static_alloc == b->static_alloc) &&
(a->dynamic_alloc == b->dynamic_alloc) &&
(a->prefer_specsig == b->prefer_specsig) &&
// hooks
(a->hooks.module_setup == b->hooks.module_setup) &&
(a->hooks.module_activation == b->hooks.module_activation) &&
Expand Down
6 changes: 4 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,7 @@ static Function *gen_jlcall_wrapper(jl_method_instance_t *lam, const jl_returnin
return w;
}

static bool uses_specsig(jl_value_t *sig, jl_value_t *rettype, bool needsparam, bool va, jl_code_info_t *src)
static bool uses_specsig(jl_value_t *sig, jl_value_t *rettype, bool needsparam, bool va, jl_code_info_t *src, bool prefer_specsig)
{
if (va || needsparam)
return false;
Expand All @@ -4609,6 +4609,8 @@ static bool uses_specsig(jl_value_t *sig, jl_value_t *rettype, bool needsparam,
if (jl_nparams(sig) == 0)
return false;
// not invalid, consider if specialized signature is worthwhile
if (prefer_specsig)
return true;
if (isbits_spec(rettype, false))
return true;
if (jl_is_uniontype(rettype)) {
Expand Down Expand Up @@ -4862,7 +4864,7 @@ static std::unique_ptr<Module> emit_function(
}

jl_value_t *jlrettype = lam->rettype;
bool specsig = uses_specsig(lam->specTypes, jlrettype, needsparams, va, src);
bool specsig = uses_specsig(lam->specTypes, jlrettype, needsparams, va, src, params->prefer_specsig);
if (!specsig)
ctx.nReqArgs--; // function not part of argArray in jlcall

Expand Down
2 changes: 1 addition & 1 deletion src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jl_value_t *jl_memory_exception;
jl_value_t *jl_readonlymemory_exception;
union jl_typemap_t jl_cfunction_list;

jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 1, 1, 1, {NULL, NULL, NULL}};
jl_cgparams_t jl_default_cgparams = {1, 1, 1, 1, 1, 1, 1, 0, {NULL, NULL, NULL}};

// --- type properties and predicates ---

Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,7 @@ typedef struct {
int code_coverage; // can we measure coverage (don't if disallowed)?
int static_alloc; // is the compiler allowed to allocate statically?
int dynamic_alloc; // is the compiler allowed to allocate dynamically (requires runtime)?
int prefer_specsig; // are specialized function signatures preferred?

jl_cghooks_t hooks;
} jl_cgparams_t;
Expand Down

0 comments on commit 47986fa

Please sign in to comment.