From 98f1f219e86f4646fab920eca3bfce6db3a7f5ca Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 5 Jul 2018 11:15:13 -0400 Subject: [PATCH] codegen: remove dead code for arrayvar optimization --- src/cgutils.cpp | 60 ------------------------------------------------- src/codegen.cpp | 26 --------------------- 2 files changed, 86 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index d69dc53590e7f..670619029d908 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -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); @@ -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)); @@ -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); } @@ -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); } @@ -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, diff --git a/src/codegen.cpp b/src/codegen.cpp index 496acdc815586..af98933bc71ca 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -494,14 +494,6 @@ struct jl_varinfo_t { } }; -// aggregate of array metadata -typedef struct { - Value *dataptr; - Value *len; - std::vector sizes; - jl_value_t *ty; -} jl_arrayvar_t; - struct jl_returninfo_t { Function *decl; enum CallingConv { @@ -530,7 +522,6 @@ class jl_codectx_t { std::vector SAvalues; std::vector> PhiNodes; std::vector ssavalue_assigned; - std::map *arrayvars = NULL; jl_module_t *module = NULL; jl_method_instance_t *linfo = NULL; jl_code_info_t *source = NULL; @@ -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; @@ -5269,9 +5251,7 @@ static std::unique_ptr emit_function( //jl_static_show(JL_STDOUT, (jl_value_t*)ast); //jl_printf(JL_STDOUT, "\n"); - std::map arrayvars; std::map 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; @@ -5703,7 +5683,6 @@ static std::unique_ptr emit_function( continue; } allocate_local(varinfo, s); - maybe_alloc_arrayvar(ctx, i); } std::map upsilon_to_phic; @@ -5826,11 +5805,6 @@ static std::unique_ptr 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); - } } }