@@ -870,6 +870,11 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
870870 ifn ! ( "llvm.trunc.f32" , fn ( t_f32) -> t_f32) ;
871871 ifn ! ( "llvm.trunc.f64" , fn ( t_f64) -> t_f64) ;
872872
873+ ifn ! ( "llvm.copysign.f32" , fn ( t_f32, t_f32) -> t_f32) ;
874+ ifn ! ( "llvm.copysign.f64" , fn ( t_f64, t_f64) -> t_f64) ;
875+ ifn ! ( "llvm.round.f32" , fn ( t_f32) -> t_f32) ;
876+ ifn ! ( "llvm.round.f64" , fn ( t_f64) -> t_f64) ;
877+
873878 ifn ! ( "llvm.rint.f32" , fn ( t_f32) -> t_f32) ;
874879 ifn ! ( "llvm.rint.f64" , fn ( t_f64) -> t_f64) ;
875880 ifn ! ( "llvm.nearbyint.f32" , fn ( t_f32) -> t_f32) ;
@@ -928,22 +933,48 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
928933 ifn ! ( "llvm.lifetime.end" , fn ( t_i64, i8p) -> void) ;
929934
930935 ifn ! ( "llvm.expect.i1" , fn ( i1, i1) -> i1) ;
931- ifn ! ( "llvm.assume" , fn ( i1) -> void) ;
932936
933937 // Some intrinsics were introduced in later versions of LLVM, but they have
934- // fallbacks in libc or libm and such. Currently, all of these intrinsics
935- // were introduced in LLVM 3.4, so we case on that.
938+ // fallbacks in libc or libm and such.
936939 macro_rules! compatible_ifn {
937- ( $name: expr, $cname: ident ( $( $arg: expr) ,* ) -> $ret: expr) => (
938- ifn!( $name, fn ( $( $arg) ,* ) -> $ret) ;
940+ ( $name: expr, noop( $cname: ident ( $( $arg: expr) ,* ) -> void) , $llvm_version: expr) => (
941+ if unsafe { llvm:: LLVMVersionMinor ( ) >= $llvm_version } {
942+ // The `if key == $name` is already in ifn!
943+ ifn!( $name, fn ( $( $arg) ,* ) -> void) ;
944+ } else if * key == $name {
945+ let f = declare:: declare_cfn( ccx, stringify!( $cname) ,
946+ Type :: func( & [ $( $arg) ,* ] , & void) ,
947+ ty:: mk_nil( ccx. tcx( ) ) ) ;
948+ llvm:: SetLinkage ( f, llvm:: InternalLinkage ) ;
949+
950+ let bld = ccx. builder( ) ;
951+ let llbb = unsafe {
952+ llvm:: LLVMAppendBasicBlockInContext ( ccx. llcx( ) , f,
953+ "entry-block\0 " . as_ptr( ) as * const _)
954+ } ;
955+
956+ bld. position_at_end( llbb) ;
957+ bld. ret_void( ) ;
958+
959+ ccx. intrinsics( ) . borrow_mut( ) . insert( $name, f. clone( ) ) ;
960+ return Some ( f) ;
961+ }
962+ ) ;
963+ ( $name: expr, $cname: ident ( $( $arg: expr) ,* ) -> $ret: expr, $llvm_version: expr) => (
964+ if unsafe { llvm:: LLVMVersionMinor ( ) >= $llvm_version } {
965+ // The `if key == $name` is already in ifn!
966+ ifn!( $name, fn ( $( $arg) ,* ) -> $ret) ;
967+ } else if * key == $name {
968+ let f = declare:: declare_cfn( ccx, stringify!( $cname) ,
969+ Type :: func( & [ $( $arg) ,* ] , & $ret) ,
970+ ty:: mk_nil( ccx. tcx( ) ) ) ;
971+ ccx. intrinsics( ) . borrow_mut( ) . insert( $name, f. clone( ) ) ;
972+ return Some ( f) ;
973+ }
939974 )
940975 }
941976
942- compatible_ifn ! ( "llvm.copysign.f32" , copysignf( t_f32, t_f32) -> t_f32) ;
943- compatible_ifn ! ( "llvm.copysign.f64" , copysign( t_f64, t_f64) -> t_f64) ;
944- compatible_ifn ! ( "llvm.round.f32" , roundf( t_f32) -> t_f32) ;
945- compatible_ifn ! ( "llvm.round.f64" , round( t_f64) -> t_f64) ;
946-
977+ compatible_ifn ! ( "llvm.assume" , noop( llvmcompat_assume( i1) -> void) , 6 ) ;
947978
948979 if ccx. sess ( ) . opts . debuginfo != NoDebugInfo {
949980 ifn ! ( "llvm.dbg.declare" , fn ( Type :: metadata( ccx) , Type :: metadata( ccx) ) -> void) ;
0 commit comments