@@ -1344,7 +1344,7 @@ static MDNode *best_tbaa(jl_tbaacache_t &tbaa_cache, jl_value_t *jt) {
13441344// note that this includes jl_isbits, although codegen should work regardless
13451345static bool jl_is_concrete_immutable (jl_value_t * t)
13461346{
1347- return jl_is_immutable_datatype (t) && ((jl_datatype_t *)t)->isconcretetype ;
1347+ return jl_may_be_immutable_datatype (t) && ((jl_datatype_t *)t)->isconcretetype ;
13481348}
13491349
13501350static bool jl_is_pointerfree (jl_value_t * t)
@@ -6248,9 +6248,9 @@ static Function* gen_cfun_wrapper(
62486248 inputarg = mark_julia_type (ctx, val, false , jargty);
62496249 }
62506250 }
6251- else if (static_at || (!jl_is_typevar (jargty) && ! jl_is_immutable_datatype (jargty))) {
6252- // must be a jl_value_t* (because it's mutable or contains gc roots )
6253- inputarg = mark_julia_type (ctx, maybe_decay_untracked (ctx, emit_bitcast (ctx, val, ctx. types (). T_prjlvalue ) ), true , jargty_proper);
6251+ else if (static_at || (!jl_is_typevar (jargty) && (! jl_is_datatype (jargty) || jl_is_abstracttype (jargty) || jl_is_mutable_datatype (jargty) ))) {
6252+ // must be a jl_value_t* (because it is mutable or abstract )
6253+ inputarg = mark_julia_type (ctx, maybe_decay_untracked (ctx, val), true , jargty_proper);
62546254 }
62556255 else {
62566256 // allocate val into a new box, if it might not be boxed
@@ -6263,32 +6263,36 @@ static Function* gen_cfun_wrapper(
62636263 ctx.builder .CreateConstInBoundsGEP1_32 (ctx.types ().T_prjlvalue , nestPtr, jl_array_len (*closure_types)),
62646264 Align (sizeof (void *)));
62656265 BasicBlock *boxedBB = BasicBlock::Create (ctx.builder .getContext (), " isboxed" , cw);
6266- BasicBlock *loadBB = BasicBlock::Create (ctx.builder .getContext (), " need-load " , cw);
6266+ BasicBlock *notanyBB = BasicBlock::Create (ctx.builder .getContext (), " not-any " , cw);
62676267 BasicBlock *unboxedBB = BasicBlock::Create (ctx.builder .getContext (), " maybe-unboxed" , cw);
62686268 BasicBlock *isanyBB = BasicBlock::Create (ctx.builder .getContext (), " any" , cw);
62696269 BasicBlock *afterBB = BasicBlock::Create (ctx.builder .getContext (), " after" , cw);
6270- Value *isrtboxed = ctx.builder .CreateIsNull (val); // XXX: this is the wrong condition and should be inspecting runtime_dt intead
6271- ctx.builder .CreateCondBr (isrtboxed, boxedBB, loadBB);
6272- ctx.builder .SetInsertPoint (boxedBB);
6273- Value *p1 = ctx.builder .CreateBitCast (val, ctx.types ().T_pjlvalue );
6274- p1 = track_pjlvalue (ctx, p1);
6275- ctx.builder .CreateBr (afterBB);
6276- ctx.builder .SetInsertPoint (loadBB);
62776270 Value *isrtany = ctx.builder .CreateICmpEQ (
6278- literal_pointer_val (ctx, (jl_value_t *)jl_any_type),
6279- ctx.builder .CreateBitCast (val, ctx.types ().T_pjlvalue ));
6280- ctx.builder .CreateCondBr (isrtany, isanyBB, unboxedBB);
6271+ track_pjlvalue (ctx,literal_pointer_val (ctx, (jl_value_t *)jl_any_type)), runtime_dt);
6272+ ctx.builder .CreateCondBr (isrtany, isanyBB, notanyBB);
62816273 ctx.builder .SetInsertPoint (isanyBB);
6282- Value *p2 = ctx.builder .CreateAlignedLoad (ctx.types ().T_prjlvalue , ctx.builder .CreateBitCast (val, ctx.types ().T_pprjlvalue ), Align (sizeof (void *)));
6274+ Value *p1 = ctx.builder .CreateAlignedLoad (ctx.types ().T_prjlvalue , val, Align (sizeof (void *)));
6275+ ctx.builder .CreateBr (afterBB);
6276+ isanyBB = ctx.builder .GetInsertBlock (); // could have changed
6277+ ctx.builder .SetInsertPoint (notanyBB);
6278+ jl_cgval_t runtime_dt_val = mark_julia_type (ctx, runtime_dt, true , jl_any_type);
6279+ Value *isrtboxed = // (!jl_is_datatype(runtime_dt) || !jl_is_concrete_datatype(runtime_dt) || jl_is_mutable_datatype(runtime_dt))
6280+ emit_guarded_test (ctx, emit_exactly_isa (ctx, runtime_dt_val, jl_datatype_type), true , [&] {
6281+ return ctx.builder .CreateOr (ctx.builder .CreateNot (emit_isconcrete (ctx, runtime_dt)), emit_datatype_mutabl (ctx, runtime_dt));
6282+ });
6283+ ctx.builder .CreateCondBr (isrtboxed, boxedBB, unboxedBB);
6284+ ctx.builder .SetInsertPoint (boxedBB);
6285+ Value *p2 = track_pjlvalue (ctx, val);
62836286 ctx.builder .CreateBr (afterBB);
6287+ boxedBB = ctx.builder .GetInsertBlock (); // could have changed
62846288 ctx.builder .SetInsertPoint (unboxedBB);
62856289 Value *p3 = emit_new_bits (ctx, runtime_dt, val);
62866290 unboxedBB = ctx.builder .GetInsertBlock (); // could have changed
62876291 ctx.builder .CreateBr (afterBB);
62886292 ctx.builder .SetInsertPoint (afterBB);
62896293 PHINode *p = ctx.builder .CreatePHI (ctx.types ().T_prjlvalue , 3 );
6290- p->addIncoming (p1, boxedBB );
6291- p->addIncoming (p2, isanyBB );
6294+ p->addIncoming (p1, isanyBB );
6295+ p->addIncoming (p2, boxedBB );
62926296 p->addIncoming (p3, unboxedBB);
62936297 inputarg = mark_julia_type (ctx, p, true , jargty_proper);
62946298 }
@@ -7069,7 +7073,7 @@ static jl_returninfo_t get_specsig_function(jl_codectx_t &ctx, Module *M, Value
70697073 param.addAttribute (Attribute::ReadOnly);
70707074 ty = PointerType::get (ty, AddressSpace::Derived);
70717075 }
7072- else if (isboxed && jl_is_immutable_datatype (jt)) {
7076+ else if (isboxed && jl_may_be_immutable_datatype (jt) && ! jl_is_abstracttype (jt)) {
70737077 param.addAttribute (Attribute::ReadOnly);
70747078 }
70757079 else if (jl_is_primitivetype (jt) && ty->isIntegerTy ()) {
0 commit comments