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

First round of LLVM 6.0.0 compatibility #47710

Merged
merged 7 commits into from
Jan 26, 2018
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
2 changes: 1 addition & 1 deletion src/ci/docker/dist-i686-freebsd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04
FROM ubuntu:18.04

RUN apt-get update && apt-get install -y --no-install-recommends \
clang \
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/dist-x86_64-freebsd/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:16.04
FROM ubuntu:18.04

RUN apt-get update && apt-get install -y --no-install-recommends \
clang \
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ pub struct TargetOptions {
/// Relocation model to use in object file. Corresponds to `llc
/// -relocation-model=$relocation_model`. Defaults to "pic".
pub relocation_model: String,
/// Code model to use. Corresponds to `llc -code-model=$code_model`. Defaults to "default".
pub code_model: String,
/// Code model to use. Corresponds to `llc -code-model=$code_model`.
pub code_model: Option<String>,
/// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec"
/// and "local-exec". This is similar to the -ftls-model option in GCC/Clang.
pub tls_model: String,
Expand Down Expand Up @@ -483,7 +483,7 @@ impl Default for TargetOptions {
only_cdylib: false,
executables: false,
relocation_model: "pic".to_string(),
code_model: "default".to_string(),
code_model: None,
tls_model: "global-dynamic".to_string(),
disable_redzone: false,
eliminate_frame_pointer: true,
Expand Down Expand Up @@ -736,7 +736,7 @@ impl Target {
key!(only_cdylib, bool);
key!(executables, bool);
key!(relocation_model);
key!(code_model);
key!(code_model, optional);
key!(tls_model);
key!(disable_redzone, bool);
key!(eliminate_frame_pointer, bool);
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,11 @@ pub enum RelocMode {
#[repr(C)]
pub enum CodeModel {
Other,
Default,
JITDefault,
Small,
Kernel,
Medium,
Large,
None,
}

/// LLVMRustDiagnosticKind
Expand All @@ -331,7 +330,6 @@ pub enum DiagnosticKind {
pub enum ArchiveKind {
Other,
K_GNU,
K_MIPS64,
K_BSD,
K_COFF,
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ impl FromStr for ArchiveKind {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"gnu" => Ok(ArchiveKind::K_GNU),
"mips64" => Ok(ArchiveKind::K_MIPS64),
"bsd" => Ok(ArchiveKind::K_BSD),
"coff" => Ok(ArchiveKind::K_COFF),
_ => Err(()),
Expand Down
36 changes: 19 additions & 17 deletions src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
("ropi-rwpi", llvm::RelocMode::ROPI_RWPI),
];

pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [
("default", llvm::CodeModel::Default),
pub const CODE_GEN_MODEL_ARGS: &[(&str, llvm::CodeModel)] = &[
("small", llvm::CodeModel::Small),
("kernel", llvm::CodeModel::Kernel),
("medium", llvm::CodeModel::Medium),
Expand Down Expand Up @@ -170,20 +169,23 @@ pub fn target_machine_factory(sess: &Session)
let ffunction_sections = sess.target.target.options.function_sections;
let fdata_sections = ffunction_sections;

let code_model_arg = match sess.opts.cg.code_model {
Some(ref s) => &s,
None => &sess.target.target.options.code_model,
};

let code_model = match CODE_GEN_MODEL_ARGS.iter().find(
|&&arg| arg.0 == code_model_arg) {
Some(x) => x.1,
_ => {
sess.err(&format!("{:?} is not a valid code model",
code_model_arg));
sess.abort_if_errors();
bug!();
let code_model_arg = sess.opts.cg.code_model.as_ref().or(
sess.target.target.options.code_model.as_ref(),
);

let code_model = match code_model_arg {
Some(s) => {
match CODE_GEN_MODEL_ARGS.iter().find(|arg| arg.0 == s) {
Some(x) => x.1,
_ => {
sess.err(&format!("{:?} is not a valid code model",
code_model_arg));
sess.abort_if_errors();
bug!();
}
}
}
None => llvm::CodeModel::None,
};

let singlethread = sess.target.target.options.singlethread;
Expand Down Expand Up @@ -731,7 +733,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
// We can't use the same module for asm and binary output, because that triggers
// various errors like invalid IR or broken binaries, so we might have to clone the
// module to produce the asm output
let llmod = if config.emit_obj {
let llmod = if config.emit_obj && !asm2wasm {
llvm::LLVMCloneModule(llmod)
} else {
llmod
Expand All @@ -740,7 +742,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
write_output_file(diag_handler, tm, cpm, llmod, &path,
llvm::FileType::AssemblyFile)
})?;
if config.emit_obj {
if config.emit_obj && !asm2wasm {
llvm::LLVMDisposeModule(llmod);
}
timeline.record("asm");
Expand Down
1 change: 1 addition & 0 deletions src/llvm-emscripten
Submodule llvm-emscripten added at 271744
16 changes: 10 additions & 6 deletions src/rustllvm/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct RustArchiveIterator {
enum class LLVMRustArchiveKind {
Other,
GNU,
MIPS64,
BSD,
COFF,
};
Expand All @@ -51,8 +50,6 @@ static Archive::Kind fromRust(LLVMRustArchiveKind Kind) {
switch (Kind) {
case LLVMRustArchiveKind::GNU:
return Archive::K_GNU;
case LLVMRustArchiveKind::MIPS64:
return Archive::K_MIPS64;
case LLVMRustArchiveKind::BSD:
return Archive::K_BSD;
case LLVMRustArchiveKind::COFF:
Expand Down Expand Up @@ -235,9 +232,16 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
Members.push_back(std::move(*MOrErr));
}
}
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
if (!Pair.second)
auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
#if LLVM_VERSION_GE(6, 0)
if (!Result)
return LLVMRustResult::Success;
LLVMRustSetLastError(Pair.second.message().c_str());
LLVMRustSetLastError(toString(std::move(Result)).c_str());
#else
if (!Result.second)
return LLVMRustResult::Success;
LLVMRustSetLastError(Result.second.message().c_str());
#endif

return LLVMRustResult::Failure;
}
23 changes: 15 additions & 8 deletions src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"

#if LLVM_VERSION_GE(6, 0)
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/IR/IntrinsicInst.h"
#else
#include "llvm/Target/TargetSubtargetInfo.h"
#endif

#if LLVM_VERSION_GE(4, 0)
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
Expand Down Expand Up @@ -210,20 +216,15 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,

enum class LLVMRustCodeModel {
Other,
Default,
JITDefault,
Small,
Kernel,
Medium,
Large,
None,
};

static CodeModel::Model fromRust(LLVMRustCodeModel Model) {
switch (Model) {
case LLVMRustCodeModel::Default:
return CodeModel::Default;
case LLVMRustCodeModel::JITDefault:
return CodeModel::JITDefault;
case LLVMRustCodeModel::Small:
return CodeModel::Small;
case LLVMRustCodeModel::Kernel:
Expand Down Expand Up @@ -360,7 +361,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
bool TrapUnreachable,
bool Singlethread) {

auto CM = fromRust(RustCM);
auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);

Expand Down Expand Up @@ -399,6 +399,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
Options.ThreadModel = ThreadModel::Single;
}

#if LLVM_VERSION_GE(6, 0)
Optional<CodeModel::Model> CM;
#else
CodeModel::Model CM = CodeModel::Model::Default;
#endif
if (RustCM != LLVMRustCodeModel::None)
CM = fromRust(RustCM);
TargetMachine *TM = TheTarget->createTargetMachine(
Trip.getTriple(), RealCPU, Feature, Options, RM, CM, OptLevel);
return wrap(TM);
Expand Down
4 changes: 4 additions & 0 deletions src/rustllvm/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,11 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
// enable fpmath flag UnsafeAlgebra
extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) {
if (auto I = dyn_cast<Instruction>(unwrap<Value>(V))) {
#if LLVM_VERSION_GE(6, 0)
I->setFast(true);
#else
I->setHasUnsafeAlgebra(true);
#endif
}
}

Expand Down