From 2c3ef2a515595c76aa7746b80f050b2d90344e2a Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 18 Jul 2018 14:00:02 -0400 Subject: [PATCH] update llvmcall for new IR. fixes #27694 --- base/compiler/ssair/inlining.jl | 1 - base/compiler/tfuncs.jl | 4 +--- base/compiler/validation.jl | 2 +- src/ccall.cpp | 21 ++++++++++++++++++--- src/julia-syntax.scm | 4 ---- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/base/compiler/ssair/inlining.jl b/base/compiler/ssair/inlining.jl index a0ee80ff4c6f2..50c0f370ce556 100644 --- a/base/compiler/ssair/inlining.jl +++ b/base/compiler/ssair/inlining.jl @@ -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 diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index ae67100538b94..ed51a6cd8692d 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -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) diff --git a/base/compiler/validation.jl b/base/compiler/validation.jl index b66832747dc59..1ae691e20ee95 100644 --- a/base/compiler/validation.jl +++ b/base/compiler/validation.jl @@ -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 diff --git a/src/ccall.cpp b/src/ccall.cpp index 4e45a9a0ff54b..33ec24fcfe47d 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -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) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 67ee14ab8b9fa..427c31c60c2a0 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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)))