Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable: Compatibility fixes for LLVM 3.5 #25739

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/librustc_trans/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,14 +871,35 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
ifn!("llvm.lifetime.end", fn(t_i64, i8p) -> void);

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

// Some intrinsics were introduced in later versions of LLVM, but they have
// fallbacks in libc or libm and such. Currently, all of these intrinsics
// were introduced in LLVM 3.4, so we case on that.
// fallbacks in libc or libm and such.
macro_rules! compatible_ifn {
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr) => (
if unsafe { llvm::LLVMVersionMinor() >= 4 } {
($name:expr, noop($cname:ident ($($arg:expr),*) -> void), $llvm_version:expr) => (
if unsafe { llvm::LLVMVersionMinor() >= $llvm_version } {
// The `if key == $name` is already in ifn!
ifn!($name, fn($($arg),*) -> void);
} else if *key == $name {
let f = declare::declare_cfn(ccx, stringify!($cname),
Type::func(&[$($arg),*], &void),
ty::mk_nil(ccx.tcx()));
llvm::SetLinkage(f, llvm::InternalLinkage);

let bld = ccx.builder();
let llbb = unsafe {
llvm::LLVMAppendBasicBlockInContext(ccx.llcx(), f,
"entry-block\0".as_ptr() as *const _)
};

bld.position_at_end(llbb);
bld.ret_void();

ccx.intrinsics().borrow_mut().insert($name, f.clone());
return Some(f);
}
);
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr, $llvm_version:expr) => (
if unsafe { llvm::LLVMVersionMinor() >= $llvm_version } {
// The `if key == $name` is already in ifn!
ifn!($name, fn($($arg),*) -> $ret);
} else if *key == $name {
Expand All @@ -891,10 +912,11 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
)
}

compatible_ifn!("llvm.copysign.f32", copysignf(t_f32, t_f32) -> t_f32);
compatible_ifn!("llvm.copysign.f64", copysign(t_f64, t_f64) -> t_f64);
compatible_ifn!("llvm.round.f32", roundf(t_f32) -> t_f32);
compatible_ifn!("llvm.round.f64", round(t_f64) -> t_f64);
compatible_ifn!("llvm.copysign.f32", copysignf(t_f32, t_f32) -> t_f32, 4);
compatible_ifn!("llvm.copysign.f64", copysign(t_f64, t_f64) -> t_f64, 4);
compatible_ifn!("llvm.round.f32", roundf(t_f32) -> t_f32, 4);
compatible_ifn!("llvm.round.f64", round(t_f64) -> t_f64, 4);
compatible_ifn!("llvm.assume", noop(llvmcompat_assume(i1) -> void), 6);


if ccx.sess().opts.debuginfo != NoDebugInfo {
Expand Down