Skip to content

Commit

Permalink
use a more specific type for arrayvar data pointers
Browse files Browse the repository at this point in the history
after optimizations this sometimes makes no difference, but I figure it can only help.
  • Loading branch information
JeffBezanson committed Jan 18, 2014
1 parent b3576f2 commit b2eec2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,11 @@ static Value *typed_load(Value *ptr, Value *idx_0based, jl_value_t *jltype,
assert(elty != NULL);
bool isbool=false;
if (elty==T_int1) { elty = T_int8; isbool=true; }
Value *data = builder.CreateBitCast(ptr, PointerType::get(elty, 0));
Value *data;
if (ptr->getType()->getContainedType(0) != elty)
data = builder.CreateBitCast(ptr, PointerType::get(elty, 0));
else
data = ptr;
Value *elt = builder.CreateLoad(builder.CreateGEP(data, idx_0based), false);
if (elty == jl_pvalue_llvmt) {
null_pointer_check(elt, ctx);
Expand All @@ -841,7 +845,11 @@ static Value *typed_store(Value *ptr, Value *idx_0based, Value *rhs,
rhs = emit_unbox(elty, rhs, jltype);
else
rhs = boxed(rhs,ctx);
Value *data = builder.CreateBitCast(ptr, PointerType::get(elty, 0));
Value *data;
if (ptr->getType()->getContainedType(0) != elty)
data = builder.CreateBitCast(ptr, PointerType::get(elty, 0));
else
data = ptr;
return builder.CreateStore(rhs, builder.CreateGEP(data, idx_0based));
}

Expand Down Expand Up @@ -1256,7 +1264,8 @@ static Value *emit_arraysize(Value *t, jl_value_t *ex, int dim, jl_codectx_t *ct

static void assign_arrayvar(jl_arrayvar_t &av, Value *ar)
{
builder.CreateStore(builder.CreateBitCast(emit_arrayptr(ar),T_pint8),
builder.CreateStore(builder.CreateBitCast(emit_arrayptr(ar),
av.dataptr->getType()->getContainedType(0)),
av.dataptr);
builder.CreateStore(emit_arraylen_prim(ar, av.ty), av.len);
for(size_t i=0; i < av.sizes.size(); i++)
Expand Down
3 changes: 2 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2670,7 +2670,8 @@ static void maybe_alloc_arrayvar(jl_sym_t *s, jl_codectx_t *ctx)
// passed to an external function (ideally only impure functions)
jl_arrayvar_t av;
int ndims = jl_unbox_long(jl_tparam1(jt));
av.dataptr = builder.CreateAlloca(T_pint8);
av.dataptr =
builder.CreateAlloca(PointerType::get(julia_type_to_llvm(jl_tparam0(jt)),0));
av.len = builder.CreateAlloca(T_size);
for(int i=0; i < ndims-1; i++)
av.sizes.push_back(builder.CreateAlloca(T_size));
Expand Down

0 comments on commit b2eec2a

Please sign in to comment.