Skip to content

Commit 115121d

Browse files
committed
Auto merge of #26088 - tamird:llvm35-fixes, r=alexcrichton
rebase of #25739, closes #25739. r? @alexcrichton
2 parents 1ade076 + e36e97b commit 115121d

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

src/librustc_llvm/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,8 @@ extern {
17721772
-> ValueRef;
17731773

17741774
pub fn LLVMRustDebugMetadataVersion() -> u32;
1775+
pub fn LLVMVersionMajor() -> u32;
1776+
pub fn LLVMVersionMinor() -> u32;
17751777

17761778
pub fn LLVMRustAddModuleFlag(M: ModuleRef,
17771779
name: *const c_char,

src/librustc_trans/trans/context.rs

+41-10
Original file line numberDiff line numberDiff line change
@@ -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);

src/rustllvm/RustWrapper.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,18 @@ DIT unwrapDI(LLVMMetadataRef ref) {
233233
return DIT(ref ? unwrap<MDNode>(ref) : NULL);
234234
}
235235

236-
extern "C" const uint32_t LLVMRustDebugMetadataVersion() {
236+
extern "C" uint32_t LLVMRustDebugMetadataVersion() {
237237
return DEBUG_METADATA_VERSION;
238238
}
239239

240+
extern "C" uint32_t LLVMVersionMinor() {
241+
return LLVM_VERSION_MINOR;
242+
}
243+
244+
extern "C" uint32_t LLVMVersionMajor() {
245+
return LLVM_VERSION_MAJOR;
246+
}
247+
240248
extern "C" void LLVMRustAddModuleFlag(LLVMModuleRef M,
241249
const char *name,
242250
uint32_t value) {

0 commit comments

Comments
 (0)