10
10
11
11
12
12
use back:: { link, abi} ;
13
- use lib:: llvm:: { ValueRef } ;
13
+ use lib:: llvm:: { Pointer , ValueRef } ;
14
14
use lib;
15
15
use middle:: trans:: base:: * ;
16
16
use middle:: trans:: cabi;
@@ -558,7 +558,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
558
558
args[ i] = get_param( bcx. fcx. llfn, first_real_arg + i) ;
559
559
}
560
560
let llfn = bcx. ccx( ) . intrinsics. get_copy( & name) ;
561
- Store ( bcx, Call ( bcx, llfn, args. slice( 0 , num_args) ) , bcx . fcx . llretptr . get ( ) ) ;
561
+ Ret ( bcx, Call ( bcx, llfn, args. slice( 0 , num_args) ) ) ;
562
562
}
563
563
564
564
fn memcpy_intrinsic( bcx: block, name: & ' static str , tp_ty: ty:: t, sizebits: u8 ) {
@@ -579,6 +579,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
579
579
let volatile = C_i1 ( false ) ;
580
580
let llfn = bcx. ccx( ) . intrinsics. get_copy( & name) ;
581
581
Call ( bcx, llfn, [ dst_ptr, src_ptr, Mul ( bcx, size, count) , align, volatile] ) ;
582
+ RetVoid ( bcx) ;
582
583
}
583
584
584
585
fn memset_intrinsic( bcx: block, name: & ' static str , tp_ty: ty:: t, sizebits: u8 ) {
@@ -599,13 +600,14 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
599
600
let volatile = C_i1 ( false ) ;
600
601
let llfn = bcx. ccx( ) . intrinsics. get_copy( & name) ;
601
602
Call ( bcx, llfn, [ dst_ptr, val, Mul ( bcx, size, count) , align, volatile] ) ;
603
+ RetVoid ( bcx) ;
602
604
}
603
605
604
606
fn count_zeros_intrinsic( bcx: block, name: & ' static str ) {
605
607
let x = get_param( bcx. fcx. llfn, bcx. fcx. arg_pos( 0 u) ) ;
606
608
let y = C_i1 ( false ) ;
607
609
let llfn = bcx. ccx( ) . intrinsics. get_copy( & name) ;
608
- Store ( bcx, Call ( bcx, llfn, [ x, y] ) , bcx . fcx . llretptr . get ( ) )
610
+ Ret ( bcx, Call ( bcx, llfn, [ x, y] ) ) ;
609
611
}
610
612
611
613
let output_type = ty:: ty_fn_ret( ty:: node_id_to_type( ccx. tcx, item. id) ) ;
@@ -615,16 +617,18 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
615
617
decl,
616
618
item. id,
617
619
output_type,
620
+ true ,
618
621
Some ( substs) ,
619
622
Some ( item. span) ) ;
620
623
624
+ set_always_inline( fcx. llfn) ;
625
+
621
626
// Set the fixed stack segment flag if necessary.
622
627
if attr:: attrs_contains_name( attributes, "fixed_stack_segment" ) {
623
628
set_fixed_stack_segment( fcx. llfn) ;
624
629
}
625
630
626
631
let mut bcx = top_scope_block( fcx, None ) ;
627
- let lltop = bcx. llbb;
628
632
let first_real_arg = fcx. arg_pos( 0 u) ;
629
633
630
634
let nm = ccx. sess. str_of( item. ident) ;
@@ -653,17 +657,18 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
653
657
get_param( decl, first_real_arg + 1 u) ,
654
658
get_param( decl, first_real_arg + 2 u) ,
655
659
order) ;
656
- Store ( bcx, old, fcx . llretptr . get ( ) ) ;
660
+ Ret ( bcx, old) ;
657
661
}
658
662
"load" => {
659
663
let old = AtomicLoad ( bcx, get_param( decl, first_real_arg) ,
660
664
order) ;
661
- Store ( bcx, old, fcx . llretptr . get ( ) ) ;
665
+ Ret ( bcx, old) ;
662
666
}
663
667
"store" => {
664
668
AtomicStore ( bcx, get_param( decl, first_real_arg + 1 u) ,
665
669
get_param( decl, first_real_arg) ,
666
670
order) ;
671
+ RetVoid ( bcx) ;
667
672
}
668
673
op => {
669
674
// These are all AtomicRMW ops
@@ -685,21 +690,18 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
685
690
let old = AtomicRMW ( bcx, atom_op, get_param( decl, first_real_arg) ,
686
691
get_param( decl, first_real_arg + 1 u) ,
687
692
order) ;
688
- Store ( bcx, old, fcx . llretptr . get ( ) ) ;
693
+ Ret ( bcx, old) ;
689
694
}
690
695
}
691
696
692
- finish_fn( fcx, lltop, bcx) ;
693
-
694
697
return ;
695
698
}
696
699
697
700
match name {
698
701
"size_of" => {
699
702
let tp_ty = substs. tys[ 0 ] ;
700
703
let lltp_ty = type_of:: type_of( ccx, tp_ty) ;
701
- Store ( bcx, C_uint ( ccx, machine:: llsize_of_real( ccx, lltp_ty) ) ,
702
- fcx. llretptr. get( ) ) ;
704
+ Ret ( bcx, C_uint ( ccx, machine:: llsize_of_real( ccx, lltp_ty) ) ) ;
703
705
}
704
706
"move_val" => {
705
707
// Create a datum reflecting the value being moved.
@@ -713,6 +715,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
713
715
ty : tp_ty, mode : mode} ;
714
716
bcx = src. move_to( bcx, DROP_EXISTING ,
715
717
get_param( decl, first_real_arg) ) ;
718
+ RetVoid ( bcx) ;
716
719
}
717
720
"move_val_init" => {
718
721
// See comments for `"move_val"`.
@@ -721,18 +724,17 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
721
724
let src = Datum { val : get_param( decl, first_real_arg + 1 u) ,
722
725
ty : tp_ty, mode : mode} ;
723
726
bcx = src. move_to( bcx, INIT , get_param( decl, first_real_arg) ) ;
727
+ RetVoid ( bcx) ;
724
728
}
725
729
"min_align_of" => {
726
730
let tp_ty = substs. tys[ 0 ] ;
727
731
let lltp_ty = type_of:: type_of( ccx, tp_ty) ;
728
- Store ( bcx, C_uint ( ccx, machine:: llalign_of_min( ccx, lltp_ty) ) ,
729
- fcx. llretptr. get( ) ) ;
732
+ Ret ( bcx, C_uint ( ccx, machine:: llalign_of_min( ccx, lltp_ty) ) ) ;
730
733
}
731
734
"pref_align_of" => {
732
735
let tp_ty = substs. tys[ 0 ] ;
733
736
let lltp_ty = type_of:: type_of( ccx, tp_ty) ;
734
- Store ( bcx, C_uint ( ccx, machine:: llalign_of_pref( ccx, lltp_ty) ) ,
735
- fcx. llretptr. get( ) ) ;
737
+ Ret ( bcx, C_uint ( ccx, machine:: llalign_of_pref( ccx, lltp_ty) ) ) ;
736
738
}
737
739
"get_tydesc" => {
738
740
let tp_ty = substs. tys[ 0 ] ;
@@ -745,19 +747,31 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
745
747
// the llvm type of intrinsic::TyDesc struct.
746
748
let userland_tydesc_ty = type_of:: type_of( ccx, output_type) ;
747
749
let td = PointerCast ( bcx, static_ti. tydesc, userland_tydesc_ty) ;
748
- Store ( bcx, td, fcx . llretptr . get ( ) ) ;
750
+ Ret ( bcx, td) ;
749
751
}
750
752
"init" => {
751
753
let tp_ty = substs. tys[ 0 ] ;
752
754
let lltp_ty = type_of:: type_of( ccx, tp_ty) ;
753
- if !ty:: type_is_nil( tp_ty) {
754
- Store ( bcx, C_null ( lltp_ty) , fcx. llretptr. get( ) ) ;
755
+ match bcx. fcx. llretptr {
756
+ Some ( ptr) => { Store ( bcx, C_null ( lltp_ty) , ptr) ; RetVoid ( bcx) ; }
757
+ None if ty:: type_is_nil( tp_ty) => RetVoid ( bcx) ,
758
+ None => Ret ( bcx, C_null ( lltp_ty) ) ,
755
759
}
756
760
}
757
761
"uninit" => {
758
762
// Do nothing, this is effectively a no-op
763
+ let retty = substs. tys[ 0 ] ;
764
+ if ty:: type_is_immediate( ccx. tcx, retty) && !ty:: type_is_nil( retty) {
765
+ unsafe {
766
+ Ret ( bcx, lib:: llvm:: llvm:: LLVMGetUndef ( type_of( ccx, retty) . to_ref( ) ) ) ;
767
+ }
768
+ } else {
769
+ RetVoid ( bcx)
770
+ }
771
+ }
772
+ "forget" => {
773
+ RetVoid ( bcx) ;
759
774
}
760
- "forget" => { }
761
775
"transmute" => {
762
776
let ( in_type, out_type) = ( substs. tys[ 0 ] , substs. tys[ 1 ] ) ;
763
777
let llintype = type_of:: type_of( ccx, in_type) ;
@@ -784,34 +798,45 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
784
798
}
785
799
786
800
if !ty:: type_is_nil ( out_type) {
787
- let lldestptr = fcx. llretptr. get( ) ;
788
801
let llsrcval = get_param ( decl, first_real_arg) ;
789
802
if ty:: type_is_immediate ( ccx. tcx , in_type) {
790
- let lldestptr = PointerCast ( bcx, lldestptr, llintype. ptr_to( ) ) ;
791
- Store ( bcx, llsrcval, lldestptr) ;
803
+ match fcx. llretptr {
804
+ Some ( llretptr) => {
805
+ Store ( bcx, llsrcval, PointerCast ( bcx, llretptr, llintype. ptr_to ( ) ) ) ;
806
+ RetVoid ( bcx) ;
807
+ }
808
+ None => match ( llintype. kind ( ) , llouttype. kind ( ) ) {
809
+ ( Pointer , other) | ( other, Pointer ) if other != Pointer => {
810
+ let tmp = Alloca ( bcx, llouttype, "" ) ;
811
+ Store ( bcx, llsrcval, PointerCast ( bcx, tmp, llintype. ptr_to ( ) ) ) ;
812
+ Ret ( bcx, Load ( bcx, tmp) ) ;
813
+ }
814
+ _ => Ret ( bcx, BitCast ( bcx, llsrcval, llouttype) )
815
+ }
816
+ }
792
817
} else {
793
818
// NB: Do not use a Load and Store here. This causes massive
794
819
// code bloat when `transmute` is used on large structural
795
820
// types.
821
+ let lldestptr = fcx. llretptr . get ( ) ;
796
822
let lldestptr = PointerCast ( bcx, lldestptr, Type :: i8p ( ) ) ;
797
823
let llsrcptr = PointerCast ( bcx, llsrcval, Type :: i8p ( ) ) ;
798
824
799
825
let llsize = llsize_of ( ccx, llintype) ;
800
826
call_memcpy ( bcx, lldestptr, llsrcptr, llsize, 1 ) ;
827
+ RetVoid ( bcx) ;
801
828
} ;
829
+ } else {
830
+ RetVoid ( bcx) ;
802
831
}
803
832
}
804
833
"needs_drop" => {
805
834
let tp_ty = substs. tys [ 0 ] ;
806
- Store ( bcx,
807
- C_bool ( ty:: type_needs_drop( ccx. tcx, tp_ty) ) ,
808
- fcx. llretptr. get( ) ) ;
835
+ Ret ( bcx, C_bool ( ty:: type_needs_drop ( ccx. tcx , tp_ty) ) ) ;
809
836
}
810
837
"contains_managed" => {
811
838
let tp_ty = substs. tys [ 0 ] ;
812
- Store ( bcx,
813
- C_bool ( ty:: type_contents( ccx. tcx, tp_ty) . contains_managed( ) ) ,
814
- fcx. llretptr. get( ) ) ;
839
+ Ret ( bcx, C_bool ( ty:: type_contents ( ccx. tcx , tp_ty) . contains_managed ( ) ) ) ;
815
840
}
816
841
"visit_tydesc" => {
817
842
let td = get_param ( decl, first_real_arg) ;
@@ -821,6 +846,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
821
846
let td = PointerCast ( bcx, td, ccx. tydesc_type . ptr_to ( ) ) ;
822
847
glue:: call_tydesc_glue_full ( bcx, visitor, td,
823
848
abi:: tydesc_field_visit_glue, None ) ;
849
+ RetVoid ( bcx) ;
824
850
}
825
851
"frame_address" => {
826
852
let frameaddress = ccx. intrinsics . get_copy ( & & "llvm.frameaddress" ) ;
@@ -847,6 +873,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
847
873
bcx, None , fty, ty:: mk_nil ( ) ,
848
874
|bcx| Callee { bcx : bcx, data : Closure ( datum) } ,
849
875
ArgVals ( arg_vals) , Some ( Ignore ) , DontAutorefArg ) . bcx ;
876
+ RetVoid ( bcx) ;
850
877
}
851
878
"morestack_addr" => {
852
879
// XXX This is a hack to grab the address of this particular
@@ -856,7 +883,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
856
883
let morestack_addr = decl_cdecl_fn (
857
884
bcx. ccx ( ) . llmod , "__morestack" , llfty) ;
858
885
let morestack_addr = PointerCast ( bcx, morestack_addr, Type :: nil ( ) . ptr_to ( ) ) ;
859
- Store ( bcx, morestack_addr, fcx . llretptr . get ( ) ) ;
886
+ Ret ( bcx, morestack_addr) ;
860
887
}
861
888
"memcpy32" => memcpy_intrinsic ( bcx, "llvm.memcpy.p0i8.p0i8.i32" , substs. tys [ 0 ] , 32 ) ,
862
889
"memcpy64" => memcpy_intrinsic ( bcx, "llvm.memcpy.p0i8.p0i8.i64" , substs. tys [ 0 ] , 64 ) ,
@@ -915,7 +942,6 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
915
942
ccx. sess . span_bug ( item. span , "unknown intrinsic" ) ;
916
943
}
917
944
}
918
- finish_fn( fcx, lltop, bcx) ;
919
945
}
920
946
921
947
/**
0 commit comments