rustc_trans: don't hardcode llvm version for conditional intrinsics
This commit introduce a third parameter for compatible_ifn!, as new intrinsics are being added in recent LLVM releases and there is no need to hardcode a specific case. Signed-off-by: Luca Bruno <lucab@debian.org>
This commit is contained in:
parent
1be9e6f055
commit
ce32f6412e
3 changed files with 27 additions and 10 deletions
|
@ -1772,6 +1772,8 @@ extern {
|
||||||
-> ValueRef;
|
-> ValueRef;
|
||||||
|
|
||||||
pub fn LLVMRustDebugMetadataVersion() -> u32;
|
pub fn LLVMRustDebugMetadataVersion() -> u32;
|
||||||
|
pub fn LLVMVersionMajor() -> u32;
|
||||||
|
pub fn LLVMVersionMinor() -> u32;
|
||||||
|
|
||||||
pub fn LLVMRustAddModuleFlag(M: ModuleRef,
|
pub fn LLVMRustAddModuleFlag(M: ModuleRef,
|
||||||
name: *const c_char,
|
name: *const c_char,
|
||||||
|
|
|
@ -870,6 +870,11 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
||||||
ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
|
ifn!("llvm.trunc.f32", fn(t_f32) -> t_f32);
|
||||||
ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
|
ifn!("llvm.trunc.f64", fn(t_f64) -> t_f64);
|
||||||
|
|
||||||
|
ifn!("llvm.copysign.f32", fn(t_f32, t_f32) -> t_f32);
|
||||||
|
ifn!("llvm.copysign.f64", fn(t_f64, t_f64) -> t_f64);
|
||||||
|
ifn!("llvm.round.f32", fn(t_f32) -> t_f32);
|
||||||
|
ifn!("llvm.round.f64", fn(t_f64) -> t_f64);
|
||||||
|
|
||||||
ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
|
ifn!("llvm.rint.f32", fn(t_f32) -> t_f32);
|
||||||
ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
|
ifn!("llvm.rint.f64", fn(t_f64) -> t_f64);
|
||||||
ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
|
ifn!("llvm.nearbyint.f32", fn(t_f32) -> t_f32);
|
||||||
|
@ -931,20 +936,22 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
|
||||||
ifn!("llvm.assume", fn(i1) -> void);
|
ifn!("llvm.assume", fn(i1) -> void);
|
||||||
|
|
||||||
// Some intrinsics were introduced in later versions of LLVM, but they have
|
// Some intrinsics were introduced in later versions of LLVM, but they have
|
||||||
// fallbacks in libc or libm and such. Currently, all of these intrinsics
|
// fallbacks in libc or libm and such.
|
||||||
// were introduced in LLVM 3.4, so we case on that.
|
|
||||||
macro_rules! compatible_ifn {
|
macro_rules! compatible_ifn {
|
||||||
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr) => (
|
($name:expr, $cname:ident ($($arg:expr),*) -> $ret:expr, $llvm_version:expr) => (
|
||||||
ifn!($name, fn($($arg),*) -> $ret);
|
if unsafe { llvm::LLVMVersionMinor() >= $llvm_version } {
|
||||||
|
// The `if key == $name` is already in ifn!
|
||||||
|
ifn!($name, fn($($arg),*) -> $ret);
|
||||||
|
} else if *key == $name {
|
||||||
|
let f = declare::declare_cfn(ccx, stringify!($cname),
|
||||||
|
Type::func(&[$($arg),*], &$ret),
|
||||||
|
ty::mk_nil(ccx.tcx()));
|
||||||
|
ccx.intrinsics().borrow_mut().insert($name, f.clone());
|
||||||
|
return Some(f);
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
if ccx.sess().opts.debuginfo != NoDebugInfo {
|
if ccx.sess().opts.debuginfo != NoDebugInfo {
|
||||||
ifn!("llvm.dbg.declare", fn(Type::metadata(ccx), Type::metadata(ccx)) -> void);
|
ifn!("llvm.dbg.declare", fn(Type::metadata(ccx), Type::metadata(ccx)) -> void);
|
||||||
ifn!("llvm.dbg.value", fn(Type::metadata(ccx), t_i64, Type::metadata(ccx)) -> void);
|
ifn!("llvm.dbg.value", fn(Type::metadata(ccx), t_i64, Type::metadata(ccx)) -> void);
|
||||||
|
|
|
@ -237,6 +237,14 @@ extern "C" uint32_t LLVMRustDebugMetadataVersion() {
|
||||||
return DEBUG_METADATA_VERSION;
|
return DEBUG_METADATA_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" uint32_t LLVMVersionMinor() {
|
||||||
|
return LLVM_VERSION_MINOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" uint32_t LLVMVersionMajor() {
|
||||||
|
return LLVM_VERSION_MAJOR;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
|
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
|
||||||
const char *name,
|
const char *name,
|
||||||
uint32_t value) {
|
uint32_t value) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue