@@ -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
@@ -1591,17 +1587,17 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1591
1587
1592
1588
// some special functions
1593
1589
if (is_libjulia_func (jl_array_ptr)) {
1594
- assert (lrt-> isPointerTy () );
1590
+ assert (lrt == T_size );
1595
1591
assert (!isVa && !llvmcall && nargt == 1 );
1596
1592
assert (!addressOf.at (0 ));
1597
1593
const jl_cgval_t &ary = argv[0 ];
1598
1594
jl_value_t *aryex = ccallarg (0 );
1599
1595
JL_GC_POP ();
1600
- return mark_or_box_ccall_result (ctx, emit_bitcast ( ctx, emit_arrayptr (ctx, ary, aryex), lrt),
1596
+ return mark_or_box_ccall_result (ctx, ctx. builder . CreatePtrToInt ( emit_arrayptr (ctx, ary, aryex), lrt),
1601
1597
retboxed, rt, unionall, static_rt);
1602
1598
}
1603
1599
else if (is_libjulia_func (jl_value_ptr)) {
1604
- assert (lrt-> isPointerTy () );
1600
+ assert (retboxed ? lrt == T_prjlvalue : lrt == T_size );
1605
1601
assert (!isVa && !llvmcall && nargt == 1 );
1606
1602
jl_value_t *tti = jl_svecref (at, 0 );
1607
1603
Value *ary;
@@ -1613,7 +1609,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1613
1609
}
1614
1610
else if (jl_is_abstract_ref_type (tti)) {
1615
1611
tti = (jl_value_t *)jl_voidpointer_type;
1616
- largty = T_pint8 ;
1612
+ largty = T_size ;
1617
1613
isboxed = false ;
1618
1614
}
1619
1615
else {
@@ -1629,13 +1625,16 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1629
1625
if (!retboxed) {
1630
1626
return mark_or_box_ccall_result (
1631
1627
ctx,
1632
- emit_bitcast (ctx, emit_pointer_from_objref (ctx,
1633
- emit_bitcast (ctx, ary, T_prjlvalue)), lrt ),
1628
+ emit_pointer_from_objref (ctx,
1629
+ emit_bitcast (ctx, ary, T_prjlvalue)),
1634
1630
retboxed, rt, unionall, static_rt);
1635
- } else {
1631
+ }
1632
+ else {
1636
1633
return mark_or_box_ccall_result (
1637
1634
ctx,
1638
- maybe_decay_untracked (emit_bitcast (ctx, ary, lrt)),
1635
+ ctx.builder .CreateAddrSpaceCast (
1636
+ ctx.builder .CreateIntToPtr (ary, T_pjlvalue),
1637
+ T_prjlvalue), // TODO: this addrspace cast is invalid (implies that the value is rooted elsewhere)
1639
1638
retboxed, rt, unionall, static_rt);
1640
1639
}
1641
1640
}
@@ -1688,11 +1687,11 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1688
1687
return ghostValue (jl_void_type);
1689
1688
}
1690
1689
else if (_is_libjulia_func ((uintptr_t )ptls_getter, " jl_get_ptls_states" )) {
1691
- assert (lrt == T_pint8 );
1690
+ assert (lrt == T_size );
1692
1691
assert (!isVa && !llvmcall && nargt == 0 );
1693
1692
JL_GC_POP ();
1694
1693
return mark_or_box_ccall_result (ctx,
1695
- emit_bitcast ( ctx, ctx.ptlsStates , lrt),
1694
+ ctx. builder . CreatePtrToInt ( ctx.ptlsStates , lrt),
1696
1695
retboxed, rt, unionall, static_rt);
1697
1696
}
1698
1697
else if (is_libjulia_func (jl_threadid)) {
@@ -1765,6 +1764,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1765
1764
}
1766
1765
else if (is_libjulia_func (jl_function_ptr)) {
1767
1766
assert (!isVa && !llvmcall && nargt == 3 );
1767
+ assert (lrt == T_size);
1768
1768
jl_value_t *f = argv[0 ].constant ;
1769
1769
jl_value_t *frt = argv[1 ].constant ;
1770
1770
if (!frt) {
@@ -1791,11 +1791,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1791
1791
llvmf = NULL ;
1792
1792
}
1793
1793
if (llvmf) {
1794
- llvmf = prepare_call (llvmf);
1795
1794
JL_GC_POP ();
1796
1795
JL_GC_POP ();
1797
- return mark_or_box_ccall_result (ctx, emit_bitcast (ctx, llvmf, lrt),
1798
- retboxed, rt, unionall, static_rt);
1796
+ Value *fptr = ctx. builder . CreatePtrToInt ( prepare_call ( llvmf) , lrt);
1797
+ return mark_or_box_ccall_result (ctx, fptr, retboxed, rt, unionall, static_rt);
1799
1798
}
1800
1799
}
1801
1800
JL_GC_POP ();
@@ -1827,10 +1826,10 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1827
1826
}
1828
1827
}
1829
1828
else if (is_libjulia_func (jl_string_ptr)) {
1830
- assert (lrt == T_pint8 );
1829
+ assert (lrt == T_size );
1831
1830
assert (!isVa && !llvmcall && nargt == 1 && !addressOf.at (0 ));
1832
- auto obj = emit_pointer_from_objref (ctx, boxed (ctx, argv[0 ]));
1833
- auto strp = ctx.builder .CreateConstGEP1_32 ( emit_bitcast (ctx, obj, T_pint8) , sizeof (void *));
1831
+ Value * obj = emit_pointer_from_objref (ctx, boxed (ctx, argv[0 ]));
1832
+ Value * strp = ctx.builder .CreateAdd ( obj, ConstantInt::get (T_size , sizeof (void *) ));
1834
1833
JL_GC_POP ();
1835
1834
return mark_or_box_ccall_result (ctx, strp, retboxed, rt, unionall, static_rt);
1836
1835
}
@@ -1933,9 +1932,6 @@ jl_cgval_t function_sig_t::emit_a_ccall(
1933
1932
if (isa<UndefValue>(v)) {
1934
1933
return jl_cgval_t ();
1935
1934
}
1936
- // A bit of a hack, but we're trying to get rid of this feature
1937
- // anyway.
1938
- v = emit_bitcast (ctx, emit_pointer_from_objref (ctx, v), pargty);
1939
1935
assert ((!toboxed && !byRef) || isa<UndefValue>(v));
1940
1936
}
1941
1937
0 commit comments