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

rustc: Fix support for LLVM 3.3 #12719

Merged
merged 1 commit into from
Mar 6, 2014
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/librustc/lib/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ pub mod llvm {
pub fn LLVMRustDestroyArchive(AR: ArchiveRef);

pub fn LLVMRustSetDLLExportStorageClass(V: ValueRef);
pub fn LLVMVersionMinor() -> c_int;
}
}

Expand Down
30 changes: 26 additions & 4 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,8 +2286,6 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {

ifn!(intrinsics, "llvm.fabs.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.fabs.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.copysign.f32", [Type::f32(), Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.copysign.f64", [Type::f64(), Type::f64()], Type::f64());

ifn!(intrinsics, "llvm.floor.f32",[Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.floor.f64",[Type::f64()], Type::f64());
Expand All @@ -2300,8 +2298,6 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
ifn!(intrinsics, "llvm.rint.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.nearbyint.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.nearbyint.f64", [Type::f64()], Type::f64());
ifn!(intrinsics, "llvm.round.f32", [Type::f32()], Type::f32());
ifn!(intrinsics, "llvm.round.f64", [Type::f64()], Type::f64());

ifn!(intrinsics, "llvm.ctpop.i8", [Type::i8()], Type::i8());
ifn!(intrinsics, "llvm.ctpop.i16",[Type::i16()], Type::i16());
Expand Down Expand Up @@ -2378,6 +2374,32 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {

ifn!(intrinsics, "llvm.expect.i1", [Type::i1(), Type::i1()], Type::i1());

// 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.
macro_rules! compatible_ifn (
($intrinsics:ident, $name:expr, $cname:expr, $args:expr, $ret:expr) => ({
let name = $name;
if unsafe { llvm::LLVMVersionMinor() >= 4 } {
ifn!($intrinsics, $name, $args, $ret);
} else {
let f = decl_cdecl_fn(llmod, $cname,
Type::func($args, &$ret),
ty::mk_nil());
$intrinsics.insert(name, f);
}
})
)

compatible_ifn!(intrinsics, "llvm.copysign.f32", "copysignf",
[Type::f32(), Type::f32()], Type::f32());
compatible_ifn!(intrinsics, "llvm.copysign.f64", "copysign",
[Type::f64(), Type::f64()], Type::f64());
compatible_ifn!(intrinsics, "llvm.round.f32", "roundf",
[Type::f32()], Type::f32());
compatible_ifn!(intrinsics, "llvm.round.f64", "round",
[Type::f64()], Type::f64());

return intrinsics;
}

Expand Down
5 changes: 5 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,8 @@ LLVMRustSetDLLExportStorageClass(LLVMValueRef Value) {
LLVMSetLinkage(Value, LLVMDLLExportLinkage);
}
#endif

extern "C" int
LLVMVersionMinor() {
return LLVM_VERSION_MINOR;
}