Skip to content

Compatibility fixes for LLVM 3.5 #21588

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

Closed
wants to merge 3 commits into from
Closed
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
17 changes: 8 additions & 9 deletions src/librustc_trans/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,14 +873,12 @@ 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, $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 @@ -893,10 +891,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", llvmcompat_assume(i1) -> void, 6);


if ccx.sess().opts.debuginfo != NoDebugInfo {
Expand Down
6 changes: 6 additions & 0 deletions src/rt/rust_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdbool.h>

#if !defined(__WIN32__)
#include <sys/time.h>
Expand Down Expand Up @@ -199,6 +200,11 @@ rust_unset_sigprocmask() {
int *__dfly_error(void) { return __error(); }
#endif

void
llvmcompat_assume(bool c) {
// empty stub for LLVM before 3.6
}

//
// Local Variables:
// mode: C++
Expand Down
11 changes: 10 additions & 1 deletion src/rustllvm/ExecutionEngineWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ extern "C" LLVMExecutionEngineRef LLVMBuildExecutionEngine(
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();

std::unique_ptr<Module> m(unwrap(mod));
RustJITMemoryManager *mm = unwrap(mref);

std::string error_str;
Expand All @@ -91,12 +90,22 @@ extern "C" LLVMExecutionEngineRef LLVMBuildExecutionEngine(
options.JITEmitDebugInfo = true;
options.NoFramePointerElim = true;

#if LLVM_VERSION_MINOR > 5
std::unique_ptr<Module> m(unwrap(mod));
ExecutionEngine *ee = EngineBuilder(std::move(m))
.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str)
.setMCJITMemoryManager(mm)
.setTargetOptions(options)
.create();
#else
ExecutionEngine *ee = EngineBuilder(unwrap(mod))
.setEngineKind(EngineKind::JIT)
.setErrorStr(&error_str)
.setMCJITMemoryManager(mm)
.setTargetOptions(options)
.create();
#endif

if (!ee)
LLVMRustSetLastError(error_str.c_str());
Expand Down