Skip to content

Commit

Permalink
optimizing more cases of arrayref/arrayset
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 16, 2011
1 parent 03867a8 commit 89f842e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/todo
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ issues 1/24/11
f(x; kws...)
- modules
* saving system image
- make optimized arrayset, arrayref work on all Arrays
* make optimized arrayset, arrayref work on all Arrays
- parallel
. make sure process group setup works
* function reflection and serialization
Expand Down
8 changes: 7 additions & 1 deletion j/inference.j
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ t_func[ccall] =
t_func[is] = (2, 2, cmp_tfunc)
t_func[subtype] = (2, 2, cmp_tfunc)
t_func[isa] = (2, 2, cmp_tfunc)
t_func[Union] = (0, Inf,
(args...)->(if allp(isType,args)
Type{Union(map(t->t.parameters[1],args)...)}
else
Type
end))
t_func[method_exists] = (2, 2, cmp_tfunc)
t_func[applicable] = (1, Inf, (f, args...)->Bool)
#t_func[new_generic_function] = (1, 1, s->(Any-->Any))
Expand Down Expand Up @@ -142,7 +148,7 @@ function (T, dims...)
# Array(T, (m, n))
nd = length(dt)
end
else #if subtype(Tuple, dt)
elseif !subtype(dt,Int)
# Array(T, ??)
nd = Array.parameters[2]
end
Expand Down
33 changes: 27 additions & 6 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,9 +725,14 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
jl_value_t *aty = expr_type(args[1]); rt1 = aty;
jl_value_t *ity = expr_type(args[2]); rt2 = ity;
if (jl_is_array_type(aty) && ity == (jl_value_t*)jl_int32_type) {
if (jl_is_bits_type(jl_tparam0(aty))) {
jl_value_t *ety = jl_tparam0(aty);
//if (jl_is_bits_type(ety)) {
if (!jl_is_typevar(ety)) {
if (!jl_is_bits_type(ety)) {
ety = (jl_value_t*)jl_any_type;
}
Value *ary = emit_expr(args[1], ctx, true);
const Type *elty = julia_type_to_llvm(jl_tparam0(aty));
const Type *elty = julia_type_to_llvm(ety);
bool isbool=false;
if (elty==T_int1) { elty = T_int8; isbool=true; }
Value *data =
Expand All @@ -741,10 +746,16 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
"arrayref: index out of range", ctx);
Value *elt=builder.CreateLoad(builder.CreateGEP(data, im1),
false);
if (ety == (jl_value_t*)jl_any_type) {
// NULL pointer check
error_unless(builder.CreateICmpNE(elt, V_null),
"arrayref: uninitialized reference error",
ctx);
}
JL_GC_POP();
if (isbool)
return builder.CreateTrunc(elt, T_int1);
return mark_julia_type(elt, jl_tparam0(aty));
return mark_julia_type(elt, ety);
}
}
}
Expand All @@ -755,7 +766,11 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
if (jl_is_array_type(aty) &&
ity == (jl_value_t*)jl_int32_type) {
jl_value_t *ety = jl_tparam0(aty);
if (jl_is_bits_type(ety) && jl_subtype(vty, ety, 0)) {
//if (jl_is_bits_type(ety) && jl_subtype(vty, ety, 0)) {
if (!jl_is_typevar(ety) && jl_subtype(vty, ety, 0)) {
if (!jl_is_bits_type(ety)) {
ety = (jl_value_t*)jl_any_type;
}
Value *ary = emit_expr(args[1], ctx, true);
const Type *elty = julia_type_to_llvm(ety);
if (elty==T_int1) { elty = T_int8; }
Expand All @@ -765,8 +780,14 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
Value *alen = emit_arraylen(ary);
Value *idx = emit_unbox(T_int32, T_pint32,
emit_unboxed(args[2], ctx));
Value *rhs = emit_unbox(elty, PointerType::get(elty,0),
emit_unboxed(args[3], ctx));
Value *rhs;
if (jl_is_bits_type(ety)) {
rhs = emit_unbox(elty, PointerType::get(elty,0),
emit_unboxed(args[3], ctx));
}
else {
rhs = boxed(emit_expr(args[3], ctx, true));
}
Value *im1 =
emit_bounds_check(idx, alen,
"arrayset: index out of range", ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ static Value *NoOpCast(Value *v)

static Value *mark_julia_type(Value *v, jl_value_t *jt)
{
if (jt == (jl_value_t*)jl_any_type)
return v;
if (has_julia_type(v) && julia_type_of(v) == jt)
return v;
if (julia_type_of_without_metadata(v) == jt)
Expand Down

0 comments on commit 89f842e

Please sign in to comment.