Skip to content

Commit

Permalink
codegen: remove dead code for arrayvar optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Jul 9, 2018
1 parent d1284dd commit 98f1f21
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 86 deletions.
60 changes: 0 additions & 60 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,32 +1637,6 @@ static bool arraytype_constshape(jl_value_t *ty)
jl_is_long(jl_tparam1(ty)) && jl_unbox_long(jl_tparam1(ty)) != 1);
}

static void maybe_alloc_arrayvar(jl_codectx_t &ctx, int s)
{
jl_value_t *jt = ctx.slots[s].value.typ;
if (arraytype_constshape(jt)) {
// TODO: this optimization does not yet work with 1-d arrays, since the
// length and data pointer can change at any time via push!
// we could make it work by reloading the metadata when the array is
// passed to an external function (ideally only impure functions)
int ndims = jl_unbox_long(jl_tparam1(jt));
jl_value_t *jelt = jl_tparam0(jt);
bool isboxed = !jl_array_store_unboxed(jelt);
Type *elt = julia_type_to_llvm(jelt);
if (type_is_ghost(elt))
return;
if (isboxed)
elt = T_prjlvalue;
// CreateAlloca is OK here because maybe_alloc_arrayvar is only called in the prologue setup
jl_arrayvar_t &av = (*ctx.arrayvars)[s];
av.dataptr = ctx.builder.CreateAlloca(PointerType::get(elt, 0));
av.len = ctx.builder.CreateAlloca(T_size);
for (int i = 0; i < ndims - 1; i++)
av.sizes.push_back(ctx.builder.CreateAlloca(T_size));
av.ty = jt;
}
}

static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, Value *dim)
{
Value *t = boxed(ctx, tinfo);
Expand All @@ -1674,20 +1648,6 @@ static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, Value *
tbaa, T_psize);
}

static jl_arrayvar_t *arrayvar_for(jl_codectx_t &ctx, jl_value_t *ex)
{
if (ex == NULL)
return NULL;
if (!jl_is_slot(ex))
return NULL;
int sl = jl_slot_number(ex) - 1;
auto av = ctx.arrayvars->find(sl);
if (av != ctx.arrayvars->end())
return &av->second;
//TODO: ssavalue case
return NULL;
}

static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, int dim)
{
return emit_arraysize(ctx, tinfo, ConstantInt::get(T_int32, dim));
Expand Down Expand Up @@ -1726,9 +1686,6 @@ static Value *emit_arraylen_prim(jl_codectx_t &ctx, const jl_cgval_t &tinfo)

static Value *emit_arraylen(jl_codectx_t &ctx, const jl_cgval_t &tinfo, jl_value_t *ex)
{
jl_arrayvar_t *av = arrayvar_for(ctx, ex);
if (av != NULL)
return ctx.builder.CreateLoad(av->len);
return emit_arraylen_prim(ctx, tinfo);
}

Expand All @@ -1752,17 +1709,11 @@ static Value *emit_arrayptr(jl_codectx_t &ctx, const jl_cgval_t &tinfo, bool isb

static Value *emit_arrayptr(jl_codectx_t &ctx, const jl_cgval_t &tinfo, jl_value_t *ex, bool isboxed = false)
{
jl_arrayvar_t *av = arrayvar_for(ctx, ex);
if (av!=NULL)
return ctx.builder.CreateLoad(av->dataptr);
return emit_arrayptr(ctx, tinfo, isboxed);
}

static Value *emit_arraysize(jl_codectx_t &ctx, const jl_cgval_t &tinfo, jl_value_t *ex, int dim)
{
jl_arrayvar_t *av = arrayvar_for(ctx, ex);
if (av != NULL && dim <= (int)av->sizes.size())
return ctx.builder.CreateLoad(av->sizes[dim - 1]);
return emit_arraysize(ctx, tinfo, dim);
}

Expand Down Expand Up @@ -1795,17 +1746,6 @@ static Value *emit_arrayelsize(jl_codectx_t &ctx, const jl_cgval_t &tinfo)
return tbaa_decorate(tbaa_const, ctx.builder.CreateLoad(addr));
}

static void assign_arrayvar(jl_codectx_t &ctx, jl_arrayvar_t &av, const jl_cgval_t &ainfo)
{
Value *aptr = emit_bitcast(ctx,
emit_arrayptr(ctx, ainfo),
av.dataptr->getType()->getContainedType(0));
tbaa_decorate(tbaa_arrayptr, ctx.builder.CreateStore(aptr, av.dataptr));
ctx.builder.CreateStore(emit_arraylen_prim(ctx, ainfo), av.len);
for (size_t i = 0; i < av.sizes.size(); i++)
ctx.builder.CreateStore(emit_arraysize(ctx, ainfo, i + 1), av.sizes[i]);
}

// Returns the size of the array represented by `tinfo` for the given dimension `dim` if
// `dim` is a valid dimension, otherwise returns constant one.
static Value *emit_arraysize_for_unsafe_dim(jl_codectx_t &ctx,
Expand Down
26 changes: 0 additions & 26 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,6 @@ struct jl_varinfo_t {
}
};

// aggregate of array metadata
typedef struct {
Value *dataptr;
Value *len;
std::vector<Value*> sizes;
jl_value_t *ty;
} jl_arrayvar_t;

struct jl_returninfo_t {
Function *decl;
enum CallingConv {
Expand Down Expand Up @@ -530,7 +522,6 @@ class jl_codectx_t {
std::vector<jl_cgval_t> SAvalues;
std::vector<std::tuple<jl_cgval_t, BasicBlock *, AllocaInst *, PHINode *, jl_value_t *>> PhiNodes;
std::vector<bool> ssavalue_assigned;
std::map<int, jl_arrayvar_t> *arrayvars = NULL;
jl_module_t *module = NULL;
jl_method_instance_t *linfo = NULL;
jl_code_info_t *source = NULL;
Expand Down Expand Up @@ -3637,15 +3628,6 @@ static void emit_varinfo_assign(jl_codectx_t &ctx, jl_varinfo_t &vi, jl_cgval_t
if (rval_info.typ == jl_bottom_type)
return;

// add info to arrayvar list
if (l && rval_info.isboxed) {
// check isboxed in case rval isn't the right type (for example, on a dead branch),
// so we don't try to assign it to the arrayvar info
jl_arrayvar_t *av = arrayvar_for(ctx, l);
if (av != NULL)
assign_arrayvar(ctx, *av, rval_info);
}

// compute / store tindex info
if (vi.pTIndex) {
Value *tindex;
Expand Down Expand Up @@ -5269,9 +5251,7 @@ static std::unique_ptr<Module> emit_function(

//jl_static_show(JL_STDOUT, (jl_value_t*)ast);
//jl_printf(JL_STDOUT, "\n");
std::map<int, jl_arrayvar_t> arrayvars;
std::map<int, BasicBlock*> labels;
ctx.arrayvars = &arrayvars;
ctx.module = jl_is_method(lam->def.method) ? lam->def.method->module : lam->def.module;
ctx.linfo = lam;
ctx.source = src;
Expand Down Expand Up @@ -5703,7 +5683,6 @@ static std::unique_ptr<Module> emit_function(
continue;
}
allocate_local(varinfo, s);
maybe_alloc_arrayvar(ctx, i);
}

std::map<int, int> upsilon_to_phic;
Expand Down Expand Up @@ -5826,11 +5805,6 @@ static std::unique_ptr<Module> emit_function(
Value *argp = boxed(ctx, theArg);
ctx.builder.CreateStore(argp, vi.boxroot);
}
// get arrayvar data if applicable
if (arrayvars.find(i) != arrayvars.end()) {
jl_arrayvar_t av = arrayvars[i];
assign_arrayvar(ctx, av, theArg);
}
}
}

Expand Down

0 comments on commit 98f1f21

Please sign in to comment.