@@ -238,20 +238,28 @@ static DIType *julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxe
238
238
return (llvm::DIType*)jdt->ditype ;
239
239
}
240
240
241
- static Value *emit_pointer_from_objref (jl_codectx_t &ctx, Value *V)
241
+ static Value *emit_pointer_from_objref_internal (jl_codectx_t &ctx, Value *V)
242
242
{
243
- unsigned AS = cast<PointerType>(V->getType ())->getAddressSpace ();
244
- if (AS != AddressSpace::Tracked && AS != AddressSpace::Derived)
245
- return ctx.builder .CreatePtrToInt (V, T_size);
246
- V = ctx.builder .CreateBitCast (decay_derived (V),
247
- PointerType::get (T_jlvalue, AddressSpace::Derived));
248
243
CallInst *Call = ctx.builder .CreateCall (prepare_call (pointer_from_objref_func), V);
249
244
#if JL_LLVM_VERSION >= 50000
250
245
Call->addAttribute (AttributeList::FunctionIndex, Attribute::ReadNone);
251
246
#else
252
247
Call->addAttribute (AttributeSet::FunctionIndex, Attribute::ReadNone);
253
248
#endif
254
- return ctx.builder .CreatePtrToInt (Call, T_size);
249
+ return Call;
250
+ }
251
+
252
+ static Value *emit_pointer_from_objref (jl_codectx_t &ctx, Value *V)
253
+ {
254
+ unsigned AS = cast<PointerType>(V->getType ())->getAddressSpace ();
255
+ if (AS != AddressSpace::Tracked && AS != AddressSpace::Derived)
256
+ return ctx.builder .CreatePtrToInt (V, T_size);
257
+ V = ctx.builder .CreateBitCast (decay_derived (V),
258
+ PointerType::get (T_jlvalue, AddressSpace::Derived));
259
+
260
+ return ctx.builder .CreatePtrToInt (
261
+ emit_pointer_from_objref_internal (ctx, V),
262
+ T_size);
255
263
}
256
264
257
265
// --- emitting pointers directly into code ---
@@ -1705,24 +1713,44 @@ static Value *emit_arraylen(jl_codectx_t &ctx, const jl_cgval_t &tinfo)
1705
1713
return emit_arraylen_prim (ctx, tinfo);
1706
1714
}
1707
1715
1708
- static Value *emit_arrayptr (jl_codectx_t &ctx, const jl_cgval_t &tinfo, bool isboxed = false )
1716
+ static Value *emit_arrayptr_internal (jl_codectx_t &ctx, const jl_cgval_t &tinfo, Value *t, unsigned AS, bool isboxed )
1709
1717
{
1710
- Value *t = boxed (ctx, tinfo);
1711
- Value *addr = ctx.builder .CreateStructGEP (jl_array_llvmt,
1712
- emit_bitcast (ctx, decay_derived (t), jl_parray_llvmt),
1713
- 0 ); // index (not offset) of data field in jl_parray_llvmt
1714
-
1718
+ Value *addr =
1719
+ ctx.builder .CreateStructGEP (jl_array_llvmt,
1720
+ emit_bitcast (ctx, t, jl_parray_llvmt),
1721
+ 0 ); // index (not offset) of data field in jl_parray_llvmt
1715
1722
MDNode *tbaa = arraytype_constshape (tinfo.typ ) ? tbaa_const : tbaa_arrayptr;
1723
+ PointerType *PT = cast<PointerType>(addr->getType ());
1724
+ PointerType *PPT = cast<PointerType>(PT->getElementType ());
1716
1725
if (isboxed) {
1717
1726
addr = ctx.builder .CreateBitCast (addr,
1718
- PointerType::get (T_pprjlvalue, cast<PointerType>(addr->getType ())->getAddressSpace ()));
1727
+ PointerType::get (PointerType::get (T_prjlvalue, AS),
1728
+ PT->getAddressSpace ()));
1729
+ } else if (AS != PPT->getAddressSpace ()) {
1730
+ addr = ctx.builder .CreateBitCast (addr,
1731
+ PointerType::get (
1732
+ PointerType::get (PPT->getElementType (), AS),
1733
+ PT->getAddressSpace ()));
1719
1734
}
1720
1735
auto LI = ctx.builder .CreateLoad (addr);
1721
1736
LI->setMetadata (LLVMContext::MD_nonnull, MDNode::get (jl_LLVMContext, None));
1722
1737
tbaa_decorate (tbaa, LI);
1723
1738
return LI;
1724
1739
}
1725
1740
1741
+ static Value *emit_arrayptr (jl_codectx_t &ctx, const jl_cgval_t &tinfo, bool isboxed = false )
1742
+ {
1743
+ Value *t = boxed (ctx, tinfo);
1744
+ return emit_arrayptr_internal (ctx, tinfo, decay_derived (t), AddressSpace::Loaded, isboxed);
1745
+ }
1746
+
1747
+ static Value *emit_unsafe_arrayptr (jl_codectx_t &ctx, const jl_cgval_t &tinfo, bool isboxed = false )
1748
+ {
1749
+ Value *t = boxed (ctx, tinfo);
1750
+ t = emit_pointer_from_objref_internal (ctx, decay_derived (t));
1751
+ return emit_arrayptr_internal (ctx, tinfo, t, 0 , isboxed);
1752
+ }
1753
+
1726
1754
static Value *emit_arrayptr (jl_codectx_t &ctx, const jl_cgval_t &tinfo, jl_value_t *ex, bool isboxed = false )
1727
1755
{
1728
1756
return emit_arrayptr (ctx, tinfo, isboxed);
0 commit comments