@@ -933,11 +933,33 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
933
933
ifn ! ( "llvm.lifetime.end" , fn ( t_i64, i8p) -> void) ;
934
934
935
935
ifn ! ( "llvm.expect.i1" , fn ( i1, i1) -> i1) ;
936
- ifn ! ( "llvm.assume" , fn ( i1) -> void) ;
937
936
938
937
// Some intrinsics were introduced in later versions of LLVM, but they have
939
938
// fallbacks in libc or libm and such.
940
939
macro_rules! compatible_ifn {
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
+ ) ;
941
963
( $name: expr, $cname: ident ( $( $arg: expr) ,* ) -> $ret: expr, $llvm_version: expr) => (
942
964
if unsafe { llvm:: LLVMVersionMinor ( ) >= $llvm_version } {
943
965
// The `if key == $name` is already in ifn!
@@ -952,6 +974,8 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
952
974
)
953
975
}
954
976
977
+ compatible_ifn ! ( "llvm.assume" , noop( llvmcompat_assume( i1) -> void) , 6 ) ;
978
+
955
979
if ccx. sess ( ) . opts . debuginfo != NoDebugInfo {
956
980
ifn ! ( "llvm.dbg.declare" , fn ( Type :: metadata( ccx) , Type :: metadata( ccx) ) -> void) ;
957
981
ifn ! ( "llvm.dbg.value" , fn ( Type :: metadata( ccx) , t_i64, Type :: metadata( ccx) ) -> void) ;
0 commit comments