@@ -247,15 +247,15 @@ static Value *emit_pointer_from_objref(jl_codectx_t &ctx, Value *V)
247
247
248
248
// --- emitting pointers directly into code ---
249
249
250
- static Constant *literal_static_pointer_val (jl_codectx_t &ctx, const void *p, Type *t )
250
+ static Constant *literal_static_pointer_val (jl_codectx_t &ctx, const void *p, Type *T = T_pjlvalue )
251
251
{
252
252
// this function will emit a static pointer into the generated code
253
253
// the generated code will only be valid during the current session,
254
254
// and thus, this should typically be avoided in new API's
255
255
#if defined(_P64)
256
- return ConstantExpr::getPointerBitCastOrAddrSpaceCast ( ConstantExpr:: getIntToPtr (ConstantInt::get (T_int64, (uint64_t )p), T_pjlvalue), t );
256
+ return ConstantExpr::getIntToPtr (ConstantInt::get (T_int64, (uint64_t )p), T );
257
257
#else
258
- return ConstantExpr::getPointerBitCastOrAddrSpaceCast ( ConstantExpr:: getIntToPtr (ConstantInt::get (T_int32, (uint32_t )p), T_pjlvalue), t );
258
+ return ConstantExpr::getIntToPtr (ConstantInt::get (T_int32, (uint32_t )p), T );
259
259
#endif
260
260
}
261
261
@@ -304,47 +304,47 @@ static Value *literal_pointer_val_slot(jl_codectx_t &ctx, jl_value_t *p)
304
304
Module *M = jl_Module;
305
305
GlobalVariable *gv = new GlobalVariable (
306
306
*M, T_pjlvalue, true , GlobalVariable::PrivateLinkage,
307
- literal_static_pointer_val (ctx, p, T_pjlvalue ));
307
+ literal_static_pointer_val (ctx, p));
308
308
gv->setUnnamedAddr (GlobalValue::UnnamedAddr::Global);
309
309
return gv;
310
310
}
311
311
if (GlobalVariable *gv = julia_const_gv (p)) {
312
312
// if this is a known object, use the existing GlobalValue
313
- return maybe_decay_untracked ( prepare_global (gv) );
313
+ return prepare_global (gv);
314
314
}
315
315
if (jl_is_datatype (p)) {
316
316
jl_datatype_t *addr = (jl_datatype_t *)p;
317
317
// DataTypes are prefixed with a +
318
- return maybe_decay_untracked ( julia_pgv (ctx, " +" , addr->name ->name , addr->name ->module , p) );
318
+ return julia_pgv (ctx, " +" , addr->name ->name , addr->name ->module , p);
319
319
}
320
320
if (jl_is_method (p)) {
321
321
jl_method_t *m = (jl_method_t *)p;
322
322
// functions are prefixed with a -
323
- return maybe_decay_untracked ( julia_pgv (ctx, " -" , m->name , m->module , p) );
323
+ return julia_pgv (ctx, " -" , m->name , m->module , p);
324
324
}
325
325
if (jl_is_method_instance (p)) {
326
326
jl_method_instance_t *linfo = (jl_method_instance_t *)p;
327
327
// Type-inferred functions are also prefixed with a -
328
328
if (jl_is_method (linfo->def .method ))
329
- return maybe_decay_untracked ( julia_pgv (ctx, " -" , linfo->def .method ->name , linfo->def .method ->module , p) );
329
+ return julia_pgv (ctx, " -" , linfo->def .method ->name , linfo->def .method ->module , p);
330
330
}
331
331
if (jl_is_symbol (p)) {
332
332
jl_sym_t *addr = (jl_sym_t *)p;
333
333
// Symbols are prefixed with jl_sym#
334
- return maybe_decay_untracked ( julia_pgv (ctx, " jl_sym#" , addr, NULL , p) );
334
+ return julia_pgv (ctx, " jl_sym#" , addr, NULL , p);
335
335
}
336
336
// something else gets just a generic name
337
- return maybe_decay_untracked ( julia_pgv (ctx, " jl_global#" , p) );
337
+ return julia_pgv (ctx, " jl_global#" , p);
338
338
}
339
339
340
340
static Value *literal_pointer_val (jl_codectx_t &ctx, jl_value_t *p)
341
341
{
342
342
if (p == NULL )
343
343
return V_null;
344
344
if (!imaging_mode)
345
- return literal_static_pointer_val (ctx, p, T_prjlvalue );
345
+ return literal_static_pointer_val (ctx, p);
346
346
Value *pgv = literal_pointer_val_slot (ctx, p);
347
- return tbaa_decorate (tbaa_const, ctx.builder .CreateLoad (pgv));
347
+ return tbaa_decorate (tbaa_const, ctx.builder .CreateLoad (T_pjlvalue, pgv));
348
348
}
349
349
350
350
static Value *literal_pointer_val (jl_codectx_t &ctx, jl_binding_t *p)
@@ -353,10 +353,10 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_binding_t *p)
353
353
if (p == NULL )
354
354
return V_null;
355
355
if (!imaging_mode)
356
- return literal_static_pointer_val (ctx, p, T_pjlvalue );
356
+ return literal_static_pointer_val (ctx, p);
357
357
// bindings are prefixed with jl_bnd#
358
358
Value *pgv = julia_pgv (ctx, " jl_bnd#" , p->name , p->owner , p);
359
- return tbaa_decorate (tbaa_const, ctx.builder .CreateLoad (pgv));
359
+ return tbaa_decorate (tbaa_const, ctx.builder .CreateLoad (T_pjlvalue, pgv));
360
360
}
361
361
362
362
// bitcast a value, but preserve its address space when dealing with pointer types
@@ -389,10 +389,10 @@ static Value *julia_binding_gv(jl_codectx_t &ctx, jl_binding_t *b)
389
389
if (imaging_mode)
390
390
bv = emit_bitcast (ctx,
391
391
tbaa_decorate (tbaa_const,
392
- ctx.builder .CreateLoad (julia_pgv (ctx, " *" , b->name , b->owner , b))),
392
+ ctx.builder .CreateLoad (T_pjlvalue, julia_pgv (ctx, " *" , b->name , b->owner , b))),
393
393
T_pprjlvalue);
394
394
else
395
- bv = literal_static_pointer_val (ctx, b, T_pprjlvalue);
395
+ bv = ConstantExpr::getBitCast ( literal_static_pointer_val (ctx, b) , T_pprjlvalue);
396
396
return julia_binding_gv (ctx, bv);
397
397
}
398
398
@@ -659,21 +659,21 @@ static Value *emit_nthptr(jl_codectx_t &ctx, Value *v, ssize_t n, MDNode *tbaa)
659
659
{
660
660
// p = (jl_value_t**)v; p[n]
661
661
Value *vptr = emit_nthptr_addr (ctx, v, n);
662
- return tbaa_decorate (tbaa, ctx.builder .CreateLoad (vptr, false ));
662
+ return tbaa_decorate (tbaa, ctx.builder .CreateLoad (T_prjlvalue, vptr ));
663
663
}
664
664
665
665
static Value *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, Value *idx, MDNode *tbaa, Type *ptype, bool gctracked = true )
666
666
{
667
667
// p = (jl_value_t**)v; *(ptype)&p[n]
668
668
Value *vptr = emit_nthptr_addr (ctx, v, idx, gctracked);
669
- return tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype), false ));
669
+ return tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype)));
670
670
}
671
671
672
672
static Value *emit_nthptr_recast (jl_codectx_t &ctx, Value *v, ssize_t n, MDNode *tbaa, Type *ptype, bool gctracked = true )
673
673
{
674
674
// p = (jl_value_t**)v; *(ptype)&p[n]
675
675
Value *vptr = emit_nthptr_addr (ctx, v, n, gctracked);
676
- return tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype), false ));
676
+ return tbaa_decorate (tbaa, ctx.builder .CreateLoad (emit_bitcast (ctx, vptr, ptype)));
677
677
}
678
678
679
679
static Value *emit_typeptr_addr (jl_codectx_t &ctx, Value *p)
@@ -703,7 +703,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, Value *tt)
703
703
// is fine however, since leaf types are not GCed at the moment. Should
704
704
// that ever change, this may have to go through a special intrinsic.
705
705
Value *addr = emit_bitcast (ctx, emit_typeptr_addr (ctx, tt), T_ppjlvalue);
706
- tt = tbaa_decorate (tbaa_tag, ctx.builder .CreateLoad (addr));
706
+ tt = tbaa_decorate (tbaa_tag, ctx.builder .CreateLoad (T_pjlvalue, addr));
707
707
return maybe_decay_untracked (mask_gc_bits (ctx, tt));
708
708
}
709
709
@@ -725,7 +725,7 @@ static jl_cgval_t emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p)
725
725
p.typ ,
726
726
counter);
727
727
if (allunboxed)
728
- pdatatype = Constant::getNullValue (T_ppjlvalue);
728
+ pdatatype = decay_derived ( Constant::getNullValue (T_ppjlvalue) );
729
729
else {
730
730
// See note above in emit_typeof(Value*), we can't tell the system
731
731
// about this until we've cleared the GC bits.
@@ -736,18 +736,16 @@ static jl_cgval_t emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p)
736
736
[&](unsigned idx, jl_datatype_t *jt) {
737
737
Value *cmp = ctx.builder .CreateICmpEQ (tindex, ConstantInt::get (T_int8, idx));
738
738
pdatatype = ctx.builder .CreateSelect (cmp,
739
- decay_derived (emit_bitcast (ctx, literal_pointer_val_slot (ctx, (jl_value_t *)jt), T_ppjlvalue )),
740
- decay_derived ( pdatatype) );
739
+ decay_derived (literal_pointer_val_slot (ctx, (jl_value_t *)jt)),
740
+ pdatatype);
741
741
},
742
742
p.typ ,
743
743
counter);
744
- Value *datatype;
745
- if (allunboxed) {
746
- datatype = tbaa_decorate (tbaa_const, ctx.builder .CreateLoad (maybe_decay_untracked (pdatatype)));
747
- }
748
- else {
749
- datatype = maybe_decay_untracked (mask_gc_bits (ctx, tbaa_decorate (tbaa_tag, ctx.builder .CreateLoad (pdatatype))));
750
- }
744
+ Value *datatype = tbaa_decorate (allunboxed ? tbaa_const : tbaa_tag,
745
+ ctx.builder .CreateLoad (T_pjlvalue, pdatatype));
746
+ if (!allunboxed)
747
+ datatype = mask_gc_bits (ctx, datatype);
748
+ datatype = maybe_decay_untracked (datatype);
751
749
return mark_julia_type (ctx, datatype, true , jl_datatype_type, /* needsroot*/ false );
752
750
}
753
751
jl_value_t *aty = p.typ ;
@@ -988,7 +986,7 @@ static void emit_type_error(jl_codectx_t &ctx, const jl_cgval_t &x, Value *type,
988
986
Value *msg_val = stringConstPtr (ctx.builder , msg);
989
987
ctx.builder .CreateCall (prepare_call (jltypeerror_func),
990
988
{ fname_val, msg_val,
991
- type, mark_callee_rooted (boxed (ctx, x, false ))});
989
+ maybe_decay_untracked ( type) , mark_callee_rooted (boxed (ctx, x, false ))});
992
990
}
993
991
994
992
static std::pair<Value*, bool > emit_isa (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const std::string *msg)
@@ -1013,7 +1011,7 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
1013
1011
// intersection with Type needs to be handled specially
1014
1012
if (jl_has_intersect_type_not_kind (type)) {
1015
1013
Value *vx = maybe_decay_untracked (boxed (ctx, x));
1016
- Value *vtyp = literal_pointer_val (ctx, type);
1014
+ Value *vtyp = maybe_decay_untracked ( literal_pointer_val (ctx, type) );
1017
1015
if (msg && *msg == " typeassert" ) {
1018
1016
ctx.builder .CreateCall (prepare_call (jltypeassert_func), { vx, vtyp });
1019
1017
return std::make_pair (ConstantInt::get (T_int1, 1 ), true );
@@ -1053,11 +1051,10 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
1053
1051
maybe_decay_untracked (literal_pointer_val (ctx, type))), false );
1054
1052
}
1055
1053
// everything else can be handled via subtype tests
1056
- Value *vxt = maybe_decay_untracked (emit_typeof_boxed (ctx, x));
1057
1054
return std::make_pair (ctx.builder .CreateICmpNE (
1058
1055
ctx.builder .CreateCall (prepare_call (jlsubtype_func),
1059
- { vxt ,
1060
- literal_pointer_val (ctx, type) }),
1056
+ { maybe_decay_untracked ( emit_typeof_boxed (ctx, x)) ,
1057
+ maybe_decay_untracked ( literal_pointer_val (ctx, type) ) }),
1061
1058
ConstantInt::get (T_int32, 0 )), false );
1062
1059
}
1063
1060
@@ -1130,9 +1127,9 @@ static Value *emit_bounds_check(jl_codectx_t &ctx, const jl_cgval_t &ainfo, jl_v
1130
1127
a = tempSpace;
1131
1128
}
1132
1129
ctx.builder .CreateCall (prepare_call (jluboundserror_func), {
1133
- emit_bitcast (ctx, decay_derived (a), T_pint8),
1134
- literal_pointer_val (ctx, ty),
1135
- i });
1130
+ emit_bitcast (ctx, decay_derived (a), T_pint8),
1131
+ literal_pointer_val (ctx, ty),
1132
+ i });
1136
1133
}
1137
1134
ctx.builder .CreateUnreachable ();
1138
1135
ctx.f ->getBasicBlockList ().push_back (passBB);
@@ -1241,7 +1238,7 @@ static void typed_store(jl_codectx_t &ctx,
1241
1238
static Value *julia_bool (jl_codectx_t &ctx, Value *cond)
1242
1239
{
1243
1240
return ctx.builder .CreateSelect (cond, literal_pointer_val (ctx, jl_true),
1244
- literal_pointer_val (ctx, jl_false));
1241
+ literal_pointer_val (ctx, jl_false));
1245
1242
}
1246
1243
1247
1244
// --- accessing the representations of built-in data types ---
@@ -1964,7 +1961,7 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool gcrooted)
1964
1961
// We have an undef value on a (hopefully) dead branch
1965
1962
return UndefValue::get (T_prjlvalue);
1966
1963
if (vinfo.constant )
1967
- return literal_pointer_val (ctx, vinfo.constant );
1964
+ return maybe_decay_untracked ( literal_pointer_val (ctx, vinfo.constant ) );
1968
1965
if (vinfo.isboxed ) {
1969
1966
assert (vinfo.V && " Missing value for box." );
1970
1967
// We're guaranteed here that Load(.gcroot) == .V, because we have determined
@@ -1987,6 +1984,9 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool gcrooted)
1987
1984
box = emit_allocobj (ctx, jl_datatype_size (jt), literal_pointer_val (ctx, (jl_value_t *)jt));
1988
1985
init_bits_cgval (ctx, box, vinfo, jl_is_mutable (jt) ? tbaa_mutab : tbaa_immut);
1989
1986
}
1987
+ else {
1988
+ box = maybe_decay_untracked (box);
1989
+ }
1990
1990
}
1991
1991
if (gcrooted) {
1992
1992
// make a gcroot for the new box
0 commit comments