@@ -182,7 +182,7 @@ static Value *runtime_sym_lookup(
182
182
PHINode *p = irbuilder.CreatePHI (T_pvoidfunc, 2 );
183
183
p->addIncoming (llvmf_orig, enter_bb);
184
184
p->addIncoming (llvmf, dlsym_lookup);
185
- return irbuilder.CreatePointerCast (p, funcptype);
185
+ return irbuilder.CreateBitCast (p, funcptype);
186
186
}
187
187
188
188
static Value *runtime_sym_lookup (
@@ -534,7 +534,7 @@ static Value *julia_to_address(
534
534
{
535
535
assert (jl_is_datatype (jlto) && julia_struct_has_layout ((jl_datatype_t *)jlto, jlto_env));
536
536
537
- if (!jl_is_cpointer_type (jlto) || !to-> isPointerTy () ) {
537
+ if (!jl_is_cpointer_type (jlto) || to != T_size ) {
538
538
emit_error (ctx, " ccall: & on argument was not matched by Ptr{T} argument type" );
539
539
return UndefValue::get (to);
540
540
}
@@ -547,19 +547,18 @@ static Value *julia_to_address(
547
547
ety = jl_tparam0 (jlto);
548
548
typeassert_input (ctx, jvinfo, ety, jlto_env, argn, true );
549
549
}
550
- assert (to->isPointerTy ());
551
550
552
551
if (jvinfo.isboxed ) {
553
552
if (!jl_is_abstracttype (ety)) {
554
553
if (jl_is_mutable_datatype (ety)) {
555
554
// no copy, just reference the data field
556
- return data_pointer (ctx, jvinfo, to);
555
+ return ctx. builder . CreateBitCast ( emit_pointer_from_objref (ctx, data_pointer (ctx, jvinfo)) , to);
557
556
}
558
- else if (jl_is_immutable_datatype (ety) && jlto != (jl_value_t *)jl_voidpointer_type) {
557
+ else if (jl_is_immutable_datatype (ety) && jlto != (jl_value_t *)jl_voidpointer_type) { // anything declared `struct`, except Ptr{Void}
559
558
// yes copy
560
559
Value *nbytes;
561
560
AllocaInst *ai;
562
- if (jl_is_leaf_type (ety) || jl_is_primitivetype ( ety)) {
561
+ if ((( jl_datatype_t *) ety)-> layout ) {
563
562
int nb = jl_datatype_size (ety);
564
563
nbytes = ConstantInt::get (T_int32, nb);
565
564
ai = emit_static_alloca (ctx, T_int8, nb);
@@ -571,7 +570,7 @@ static Value *julia_to_address(
571
570
}
572
571
ai->setAlignment (16 );
573
572
ctx.builder .CreateMemCpy (ai, data_pointer (ctx, jvinfo, T_pint8), nbytes, sizeof (void *)); // minimum gc-alignment in julia is pointer size
574
- return emit_bitcast ( ctx, ai, to);
573
+ return ctx. builder . CreatePtrToInt ( ai, to);
575
574
}
576
575
}
577
576
// emit maybe copy
@@ -583,14 +582,14 @@ static Value *julia_to_address(
583
582
Value *ismutable = emit_datatype_mutabl (ctx, jvt);
584
583
ctx.builder .CreateCondBr (ismutable, mutableBB, immutableBB);
585
584
ctx.builder .SetInsertPoint (mutableBB);
586
- Value *p1 = data_pointer (ctx, jvinfo, to);
585
+ Value *p1 = ctx. builder . CreateBitCast ( emit_pointer_from_objref (ctx, data_pointer (ctx, jvinfo)) , to);
587
586
ctx.builder .CreateBr (afterBB);
588
587
ctx.builder .SetInsertPoint (immutableBB);
589
588
Value *nbytes = emit_datatype_size (ctx, jvt);
590
589
AllocaInst *ai = ctx.builder .CreateAlloca (T_int8, nbytes);
591
590
ai->setAlignment (16 );
592
591
ctx.builder .CreateMemCpy (ai, data_pointer (ctx, jvinfo, T_pint8), nbytes, sizeof (void *)); // minimum gc-alignment in julia is pointer size
593
- Value *p2 = emit_bitcast ( ctx, ai, to);
592
+ Value *p2 = ctx. builder . CreatePtrToInt ( ai, to);
594
593
ctx.builder .CreateBr (afterBB);
595
594
ctx.builder .SetInsertPoint (afterBB);
596
595
PHINode *p = ctx.builder .CreatePHI (to, 2 );
@@ -612,9 +611,7 @@ static Value *julia_to_address(
612
611
(uint64_t )jl_datatype_size (ety),
613
612
(uint64_t )jl_datatype_align (ety));
614
613
}
615
- if (slot->getType () != to)
616
- slot = emit_bitcast (ctx, slot, to);
617
- return slot;
614
+ return ctx.builder .CreatePtrToInt (slot, to);
618
615
}
619
616
620
617
@@ -781,22 +778,21 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
781
778
rt = (jl_value_t *)jl_voidpointer_type;
782
779
}
783
780
Type *lrt = julia_type_to_llvm (rt);
784
- if (lrt == NULL )
785
- lrt = T_pint8;
786
781
787
782
interpret_symbol_arg (ctx, sym, args[1 ], " cglobal" , false );
788
783
789
784
if (sym.jl_ptr != NULL ) {
790
- res = ctx.builder .CreateIntToPtr (sym.jl_ptr , lrt);
785
+ res = ctx.builder .CreateBitCast (sym.jl_ptr , lrt);
791
786
}
792
787
else if (sym.fptr != NULL ) {
793
- res = literal_static_pointer_val (ctx , (void *)( uintptr_t ) sym.fptr , lrt );
788
+ res = ConstantInt::get (lrt , (uint64_t ) sym.fptr );
794
789
if (imaging_mode)
795
790
jl_printf (JL_STDERR," WARNING: literal address used in cglobal for %s; code cannot be statically compiled\n " , sym.f_name );
796
791
}
797
792
else {
798
793
if (imaging_mode) {
799
- res = runtime_sym_lookup (ctx, (PointerType*)lrt, sym.f_lib , sym.f_name , ctx.f );
794
+ res = runtime_sym_lookup (ctx, cast<PointerType>(T_pint8), sym.f_lib , sym.f_name , ctx.f );
795
+ res = ctx.builder .CreatePtrToInt (res, lrt);
800
796
}
801
797
else {
802
798
void *symaddr = jl_dlsym_e (jl_get_library (sym.f_lib ), sym.f_name );
@@ -815,7 +811,7 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
815
811
}
816
812
// since we aren't saving this code, there's no sense in
817
813
// putting anything complicated here: just JIT the address of the cglobal
818
- res = literal_static_pointer_val (ctx, symaddr, lrt );
814
+ res = ConstantInt::get (lrt, ( uint64_t ) symaddr);
819
815
}
820
816
}
821
817
@@ -1590,17 +1586,17 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1590
1586
1591
1587
// some special functions
1592
1588
if (is_libjulia_func (jl_array_ptr)) {
1593
- assert (lrt-> isPointerTy () );
1589
+ assert (lrt == T_size );
1594
1590
assert (!isVa && !llvmcall && nargt == 1 );
1595
1591
assert (!addressOf.at (0 ));
1596
1592
const jl_cgval_t &ary = argv[0 ];
1597
1593
jl_value_t *aryex = ccallarg (0 );
1598
1594
JL_GC_POP ();
1599
- return mark_or_box_ccall_result (ctx, emit_bitcast ( ctx, emit_arrayptr (ctx, ary, aryex), lrt),
1595
+ return mark_or_box_ccall_result (ctx, ctx. builder . CreatePtrToInt ( emit_arrayptr (ctx, ary, aryex), lrt),
1600
1596
retboxed, rt, unionall, static_rt);
1601
1597
}
1602
1598
else if (is_libjulia_func (jl_value_ptr)) {
1603
- assert (lrt-> isPointerTy () );
1599
+ assert (retboxed ? lrt == T_prjlvalue : lrt == T_size );
1604
1600
assert (!isVa && !llvmcall && nargt == 1 );
1605
1601
jl_value_t *tti = jl_svecref (at, 0 );
1606
1602
Value *ary;
@@ -1612,7 +1608,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1612
1608
}
1613
1609
else if (jl_is_abstract_ref_type (tti)) {
1614
1610
tti = (jl_value_t *)jl_voidpointer_type;
1615
- largty = T_pint8 ;
1611
+ largty = T_size ;
1616
1612
isboxed = false ;
1617
1613
}
1618
1614
else {
@@ -1628,13 +1624,16 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1628
1624
if (!retboxed) {
1629
1625
return mark_or_box_ccall_result (
1630
1626
ctx,
1631
- emit_bitcast (ctx, emit_pointer_from_objref (ctx,
1632
- emit_bitcast (ctx, ary, T_prjlvalue)), lrt ),
1627
+ emit_pointer_from_objref (ctx,
1628
+ emit_bitcast (ctx, ary, T_prjlvalue)),
1633
1629
retboxed, rt, unionall, static_rt);
1634
- } else {
1630
+ }
1631
+ else {
1635
1632
return mark_or_box_ccall_result (
1636
1633
ctx,
1637
- maybe_decay_untracked (emit_bitcast (ctx, ary, lrt)),
1634
+ ctx.builder .CreateAddrSpaceCast (
1635
+ ctx.builder .CreateIntToPtr (ary, T_pjlvalue),
1636
+ T_prjlvalue), // TODO: this addrspace cast is invalid (implies that the value is rooted elsewhere)
1638
1637
retboxed, rt, unionall, static_rt);
1639
1638
}
1640
1639
}
@@ -1694,11 +1693,11 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1694
1693
return ghostValue (jl_void_type);
1695
1694
}
1696
1695
else if (_is_libjulia_func ((uintptr_t )ptls_getter, " jl_get_ptls_states" )) {
1697
- assert (lrt == T_pint8 );
1696
+ assert (lrt == T_size );
1698
1697
assert (!isVa && !llvmcall && nargt == 0 );
1699
1698
JL_GC_POP ();
1700
1699
return mark_or_box_ccall_result (ctx,
1701
- emit_bitcast ( ctx, ctx.ptlsStates , lrt),
1700
+ ctx. builder . CreatePtrToInt ( ctx.ptlsStates , lrt),
1702
1701
retboxed, rt, unionall, static_rt);
1703
1702
}
1704
1703
else if (is_libjulia_func (jl_threadid)) {
@@ -1771,6 +1770,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1771
1770
}
1772
1771
else if (is_libjulia_func (jl_function_ptr)) {
1773
1772
assert (!isVa && !llvmcall && nargt == 3 );
1773
+ assert (lrt == T_size);
1774
1774
jl_value_t *f = argv[0 ].constant ;
1775
1775
jl_value_t *frt = argv[1 ].constant ;
1776
1776
if (!frt) {
@@ -1797,11 +1797,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1797
1797
llvmf = NULL ;
1798
1798
}
1799
1799
if (llvmf) {
1800
- llvmf = prepare_call (llvmf);
1801
1800
JL_GC_POP ();
1802
1801
JL_GC_POP ();
1803
- return mark_or_box_ccall_result (ctx, emit_bitcast (ctx, llvmf, lrt),
1804
- retboxed, rt, unionall, static_rt);
1802
+ Value *fptr = ctx. builder . CreatePtrToInt ( prepare_call ( llvmf) , lrt);
1803
+ return mark_or_box_ccall_result (ctx, fptr, retboxed, rt, unionall, static_rt);
1805
1804
}
1806
1805
}
1807
1806
JL_GC_POP ();
@@ -1833,10 +1832,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1833
1832
}
1834
1833
}
1835
1834
else if (is_libjulia_func (jl_string_ptr)) {
1836
- assert (lrt == T_pint8 );
1835
+ assert (lrt == T_size );
1837
1836
assert (!isVa && !llvmcall && nargt == 1 && !addressOf.at (0 ));
1838
- auto obj = emit_pointer_from_objref (ctx, boxed (ctx, argv[0 ]));
1839
- auto strp = ctx.builder .CreateConstGEP1_32 ( emit_bitcast (ctx, obj, T_pint8) , sizeof (void *));
1837
+ Value * obj = emit_pointer_from_objref (ctx, boxed (ctx, argv[0 ]));
1838
+ Value * strp = ctx.builder .CreateAdd ( obj, ConstantInt::get (T_size , sizeof (void *) ));
1840
1839
JL_GC_POP ();
1841
1840
return mark_or_box_ccall_result (ctx, strp, retboxed, rt, unionall, static_rt);
1842
1841
}
@@ -1939,9 +1938,6 @@ jl_cgval_t function_sig_t::emit_a_ccall(
1939
1938
if (isa<UndefValue>(v)) {
1940
1939
return jl_cgval_t ();
1941
1940
}
1942
- // A bit of a hack, but we're trying to get rid of this feature
1943
- // anyway.
1944
- v = emit_bitcast (ctx, emit_pointer_from_objref (ctx, v), pargty);
1945
1941
assert ((!toboxed && !byRef) || isa<UndefValue>(v));
1946
1942
}
1947
1943
0 commit comments