Skip to content

Commit

Permalink
update llvmcall for new IR. fixes JuliaLang#27694
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 19, 2018
1 parent c6a949a commit 2c3ef2a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
1 change: 0 additions & 1 deletion base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,6 @@ function assemble_inline_todo!(ir::IRCode, linetable::Vector{LineInfoNode}, sv::
ft = argextype(arg1, ir, sv.sp)
has_free_typevars(ft) && continue
f = singleton_type(ft)
# TODO: llvmcall can contain other calls as arguments, so this code doesn't work on it
f === Core.Intrinsics.llvmcall && continue
f === Core.Intrinsics.cglobal && continue

Expand Down
4 changes: 1 addition & 3 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ add_tfunc(checked_smul_int, 2, 2, chk_tfunc, 10)
add_tfunc(checked_umul_int, 2, 2, chk_tfunc, 10)
## other, misc intrinsics ##
add_tfunc(Core.Intrinsics.llvmcall, 3, INT_INF,
# TODO: Lower this inlining cost. We currently need to prevent inlining llvmcall
# to avoid issues with its IR.
(@nospecialize(fptr), @nospecialize(rt), @nospecialize(at), a...) -> instanceof_tfunc(rt)[1], 1000)
(@nospecialize(fptr), @nospecialize(rt), @nospecialize(at), a...) -> instanceof_tfunc(rt)[1], 10)
cglobal_tfunc(@nospecialize(fptr)) = Ptr{Cvoid}
cglobal_tfunc(@nospecialize(fptr), @nospecialize(t)) = (isType(t) ? Ptr{t.parameters[1]} : Ptr)
cglobal_tfunc(@nospecialize(fptr), t::Const) = (isa(t.val, Type) ? Ptr{t.val} : Ptr)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/validation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function validate_code!(errors::Vector{>:InvalidCodeError}, c::CodeInfo, is_top_
if isa(x, Expr)
if x.head === :call || x.head === :invoke
f = x.args[1]
if f isa GlobalRef && (f.name === :llvmcall || f.name === :cglobal) && x.head === :call
if f isa GlobalRef && (f.name === :cglobal) && x.head === :call
# TODO: these are not yet linearized
else
for arg in x.args
Expand Down
21 changes: 18 additions & 3 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,10 +960,25 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
{
JL_NARGSV(llvmcall, 3);
jl_value_t *rt = NULL, *at = NULL, *ir = NULL, *decl = NULL;
jl_value_t *ir_arg = args[1];
JL_GC_PUSH4(&ir, &rt, &at, &decl);
at = try_eval(ctx, args[3], "error statically evaluating llvmcall argument tuple");
rt = try_eval(ctx, args[2], "error statically evaluating llvmcall return type");
ir = try_eval(ctx, args[1], "error statically evaluating llvm IR argument");
if (jl_is_ssavalue(ir_arg))
ir_arg = jl_arrayref((jl_array_t*)ctx.source->code, ((jl_ssavalue_t*)ir_arg)->id - 1);
ir = try_eval(ctx, ir_arg, "error statically evaluating llvm IR argument");
if (jl_is_ssavalue(args[2])) {
jl_value_t *rtt = jl_arrayref((jl_array_t*)ctx.source->ssavaluetypes, ((jl_ssavalue_t*)args[2])->id - 1);
if (jl_is_type_type(rtt))
rt = jl_tparam0(rtt);
}
if (rt == NULL)
rt = try_eval(ctx, args[2], "error statically evaluating llvmcall return type");
if (jl_is_ssavalue(args[3])) {
jl_value_t *att = jl_arrayref((jl_array_t*)ctx.source->ssavaluetypes, ((jl_ssavalue_t*)args[3])->id - 1);
if (jl_is_type_type(att))
at = jl_tparam0(att);
}
if (at == NULL)
at = try_eval(ctx, args[3], "error statically evaluating llvmcall argument tuple");
int i = 1;
if (jl_is_tuple(ir)) {
// if the IR is a tuple, we expect (declarations, ir)
Expand Down
4 changes: 0 additions & 4 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3623,10 +3623,6 @@ f(x) = yt(x)
(equal? (cadr e) '(outerref cglobal))))
(list* (cadr e) (caddr e)
(compile-args (cdddr e) break-labels linearize-args)))
((and (length> e 2)
(or (eq? (cadr e) 'llvmcall)
(equal? (cadr e) '(outerref llvmcall))))
(cdr e))
(else
(compile-args (cdr e) break-labels linearize-args))))
(callex (cons (car e) args)))
Expand Down

0 comments on commit 2c3ef2a

Please sign in to comment.