Permalink
Browse files

progress on cross-module inlining

  • Loading branch information...
JeffBezanson committed Jul 5, 2012
1 parent 2035ff1 commit d434b23ff6160d14427b99754b9d5229d5b4cd05
Showing with 74 additions and 18 deletions.
  1. +0 −4 base/array.jl
  2. +1 −0 base/boot.jl
  3. +1 −0 base/expr.jl
  4. +47 −8 base/inference.jl
  5. +3 −1 base/sysimg.jl
  6. +2 −2 extras/bitarray.jl
  7. +18 −2 src/codegen.cpp
  8. +2 −1 src/julia-syntax.scm
View
@@ -65,10 +65,6 @@ end
## Constructors ##
-_jl_comprehension_zeros{T,n}(oneresult::AbstractArray{T,n}, dims...) = Array(T, dims...)
-_jl_comprehension_zeros{T}(oneresult::T, dims...) = Array(T, dims...)
-_jl_comprehension_zeros(oneresult::(), dims...) = Array(None, dims...)
-
similar(a::Array, T, dims::Dims) = Array(T, dims)
similar{T}(a::Array{T,1}) = Array(T, size(a,1))
similar{T}(a::Array{T,2}) = Array(T, size(a,1), size(a,2))
View
@@ -129,6 +129,7 @@ export ..., ANY, ASCIIString, AbstractArray, AbstractKind, Any, Array,
Symbol, SymbolNode, Task, Top, TopNode, Tuple, Type, TypeConstructor,
TypeName, TypeVar, UTF8String, Uint, Uint8, Uint16, Uint32, Uint64, Uint128,
Undef, UndefRefError, Union, UnionKind, Unsigned, Void, WeakRef,
+ GetfieldNode,
# functions
_setfield, applicable, apply, apply_type, arraylen, arrayref, arrayset,
arraysize, convert_default, convert_tuple, eval, fieldtype, getfield,
View
@@ -47,6 +47,7 @@ expr(hd::Symbol, args::ANY...) = Expr(hd, {args...}, Any)
expr(hd::Symbol, args::Array{Any,1}) = Expr(hd, args, Any)
copy(e::Expr) = Expr(e.head, isempty(e.args) ? e.args : map(copy,e.args), e.typ)
copy(s::SymbolNode) = SymbolNode(s.name, s.typ)
+copy(n::GetfieldNode) = GetfieldNode(n.value, n.name, n.typ)
isequal(x::Expr, y::Expr) = (is(x.head,y.head) && isequal(x.args,y.args))
isequal(x::SymbolNode, y::SymbolNode) = is(x.name,y.name)
View
@@ -1215,12 +1215,10 @@ function type_annotate(ast::Expr, states::Array{Any,1},
end
function sym_replace(e::Expr, from, to)
- head = e.head
- if is(head,:line)
- return e
- end
- for i=1:length(e.args)
- e.args[i] = sym_replace(e.args[i], from, to)
+ if !is(e.head,:line)
+ for i=1:length(e.args)
+ e.args[i] = sym_replace(e.args[i], from, to)
+ end
end
e
end
@@ -1246,6 +1244,42 @@ end
sym_replace(x, from, to) = x
+# see if a symbol resolves the same in two modules
+function resolves_same(sym, from, to)
+ if is(from,to)
+ return true
+ end
+ # todo: better
+ return (isconst(from,sym) && isconst(to,sym) && isbound(from,sym) &&
+ isbound(to,sym) && is(eval(from,sym),eval(to,sym)))
+end
+
+# annotate symbols with their original module for inlining
+function resolve_globals(e::Expr, from, to, env)
+ if !is(e.head,:line)
+ for i=1:length(e.args)
+ e.args[i] = resolve_globals(e.args[i], from, to, env)
+ end
+ end
+ e
+end
+
+function resolve_globals(s::Symbol, from, to, env)
+ if contains_is(env, s)
+ return s
+ end
+ resolves_same(s, from, to) ? s : GetfieldNode(from, s, Any)
+end
+
+function resolve_globals(s::SymbolNode, from, to, env)
+ if contains_is(env, s.name)
+ return s
+ end
+ resolves_same(s.name, from, to) ? s : GetfieldNode(from, s.name, s.typ)
+end
+
+resolve_globals(x, from, to, env) = x
+
# count occurrences up to n+1
function occurs_more(e::Expr, pred, n)
c = 0
@@ -1403,8 +1437,13 @@ function inlineable(f, e::Expr, vars)
end
# ok, substitute argument expressions for argument names in the body
spnames = { sp[i].name for i=1:2:length(sp) }
- return sym_replace(copy(expr), append(args,spnames),
- append(argexprs,spvals))
+ expr = copy(expr)
+ mfrom = meth[3].module; mto = (inference_stack::CallStack).mod
+ srcenv = append(args,spnames)
+ if !is(mfrom, mto)
+ expr = resolve_globals(expr, mfrom, mto, srcenv)
+ end
+ return sym_replace(expr, srcenv, append(argexprs,spvals))
end
_jl_tn(sym::Symbol) =
View
@@ -178,7 +178,9 @@ export
union!,unique_name,unsetenv,unshift,unsigned,uppercase,utf8,values,var,vcat,
vec,wait,wait_nohang,weighted_mean,which,whicht,whos,with_output_to_string,
write,write_to,xcorr,xor!,yield,zero,zeros,zip,
- nextprod, prevprod, base,
+ nextprod, prevprod, base, findfirst, qrp, sdd, require,
+ Factorization, Cholesky, LU, QR, QRP,
+ ref_shape, assign_shape_check, to_index, indices, append_any,
# TODO: used by macros, should be removed (use hygiene instead)
cmd_gen,
# Macros
View
@@ -311,10 +311,10 @@ function bitrand!(B::BitArray)
return B
end
for i = 1 : length(B.chunks) - 1
- B.chunks[i] = _jl_dsfmt_randui64()
+ B.chunks[i] = randi(Uint64)
end
msk = @_msk_end length(B)
- B.chunks[end] = msk & _jl_dsfmt_randui64()
+ B.chunks[end] = msk & randi(Uint64)
return B
end
View
@@ -280,6 +280,9 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool boxed=true,
static Value *emit_unboxed(jl_value_t *e, jl_codectx_t *ctx);
static int is_global(jl_sym_t *s, jl_codectx_t *ctx);
static void make_gcroot(Value *v, jl_codectx_t *ctx);
+static Value *global_binding_pointer(jl_module_t *m, jl_sym_t *s,
+ jl_binding_t **pbnd, bool assign);
+static Value *emit_checked_var(Value *bp, const char *name, jl_codectx_t *ctx);
// --- utilities ---
@@ -426,6 +429,9 @@ static void max_arg_depth(jl_value_t *expr, int32_t *max, int32_t *sp,
else if (jl_is_symbolnode(expr)) {
expr = (jl_value_t*)jl_symbolnode_sym(expr);
}
+ else if (jl_is_getfieldnode(expr)) {
+ if (2 > *max) *max = 2;
+ }
if (jl_is_symbol(expr)) {
char *vname = ((jl_sym_t*)expr)->name;
if (ctx->escapes->find(vname) != ctx->escapes->end()) {
@@ -556,8 +562,19 @@ static Value *emit_getfield(jl_value_t *expr, jl_sym_t *name, jl_codectx_t *ctx)
return fld;
}
}
- ////// todo
+ JL_GC_POP();
+ int argStart = ctx->argDepth;
+ Value *arg1 = emit_expr(expr, ctx);
+ make_gcroot(boxed(arg1), ctx);
+ Value *arg2 = literal_pointer_val(name);
+ make_gcroot(arg2, ctx);
+ Value *myargs = builder.CreateGEP(ctx->argTemp,
+ ConstantInt::get(T_int32, argStart));
+ Value *result = builder.CreateCall3(jlgetfield_func, V_null, myargs,
+ ConstantInt::get(T_int32,2));
+ ctx->argDepth = argStart;
+ return result;
}
static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
@@ -2218,7 +2235,6 @@ extern "C" void jl_init_codegen(void)
InitializeNativeTarget();
jl_Module = new Module("julia", jl_LLVMContext);
-
#if !defined(LLVM_VERSION_MAJOR) || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 0)
jl_ExecutionEngine = EngineBuilder(jl_Module).setEngineKind(EngineKind::JIT).create();
#ifdef DEBUG
View
@@ -1022,7 +1022,8 @@
(block
(= ,oneresult (tuple))
,(evaluate-one ranges)
- (= ,result (call _jl_comprehension_zeros ,oneresult ,@(compute-dims ranges 1) ))
+ (= ,result (call (top Array) (call (top eltype) ,oneresult)
+ ,@(compute-dims ranges 1)))
(= ,ri 1)
,(construct-loops (reverse ranges) (list) 1)
,result ))))

0 comments on commit d434b23

Please sign in to comment.