Skip to content

Commit e36e97b

Browse files
davidvoittamird
authored andcommitted
rustc_trans: 'assume' intrinsic is only available on LLVM >= 3.6
Based on the patch from Luca Bruno. Instead of creating an empty C function in the rt, this version creates an shim noop function using llvm. This function is declared as internal, and the unsupported assume intrinsic and the shim gets completly removed by the optimizer.
1 parent ce32f64 commit e36e97b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/librustc_trans/trans/context.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -933,11 +933,33 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
933933
ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);
934934

935935
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
936-
ifn!("llvm.assume", fn(i1) -> void);
937936

938937
// Some intrinsics were introduced in later versions of LLVM, but they have
939938
// fallbacks in libc or libm and such.
940939
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+
);
941963
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr, $llvm_version:expr) => (
942964
if unsafe { llvm::LLVMVersionMinor() >= $llvm_version } {
943965
// The `if key == $name` is already in ifn!
@@ -952,6 +974,8 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
952974
)
953975
}
954976

977+
compatible_ifn!("llvm.assume", noop(llvmcompat_assume(i1) -> void), 6);
978+
955979
if ccx.sess().opts.debuginfo != NoDebugInfo {
956980
ifn!("llvm.dbg.declare", fn(Type::metadata(ccx), Type::metadata(ccx)) -> void);
957981
ifn!("llvm.dbg.value", fn(Type::metadata(ccx), t_i64, Type::metadata(ccx)) -> void);

0 commit comments

Comments
 (0)