Skip to content

Commit 8a9381d

Browse files
committed
Rollup merge of rust-lang#47710 - alexcrichton:llvm-6-compat, r=nikomatsakis
First round of LLVM 6.0.0 compatibility This includes a number of commits for the first round of upgrading to LLVM 6. There are still [lingering bugs](rust-lang#47683) but I believe all of this will nonetheless be necessary!
2 parents f7706d5 + e9a6499 commit 8a9381d

File tree

10 files changed

+56
-41
lines changed

10 files changed

+56
-41
lines changed

src/ci/docker/dist-i686-freebsd/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:16.04
1+
FROM ubuntu:18.04
22

33
RUN apt-get update && apt-get install -y --no-install-recommends \
44
clang \

src/ci/docker/dist-x86_64-freebsd/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:16.04
1+
FROM ubuntu:18.04
22

33
RUN apt-get update && apt-get install -y --no-install-recommends \
44
clang \

src/librustc_back/target/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ pub struct TargetOptions {
320320
/// Relocation model to use in object file. Corresponds to `llc
321321
/// -relocation-model=$relocation_model`. Defaults to "pic".
322322
pub relocation_model: String,
323-
/// Code model to use. Corresponds to `llc -code-model=$code_model`. Defaults to "default".
324-
pub code_model: String,
323+
/// Code model to use. Corresponds to `llc -code-model=$code_model`.
324+
pub code_model: Option<String>,
325325
/// TLS model to use. Options are "global-dynamic" (default), "local-dynamic", "initial-exec"
326326
/// and "local-exec". This is similar to the -ftls-model option in GCC/Clang.
327327
pub tls_model: String,
@@ -483,7 +483,7 @@ impl Default for TargetOptions {
483483
only_cdylib: false,
484484
executables: false,
485485
relocation_model: "pic".to_string(),
486-
code_model: "default".to_string(),
486+
code_model: None,
487487
tls_model: "global-dynamic".to_string(),
488488
disable_redzone: false,
489489
eliminate_frame_pointer: true,
@@ -736,7 +736,7 @@ impl Target {
736736
key!(only_cdylib, bool);
737737
key!(executables, bool);
738738
key!(relocation_model);
739-
key!(code_model);
739+
key!(code_model, optional);
740740
key!(tls_model);
741741
key!(disable_redzone, bool);
742742
key!(eliminate_frame_pointer, bool);

src/librustc_llvm/ffi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,11 @@ pub enum RelocMode {
299299
#[repr(C)]
300300
pub enum CodeModel {
301301
Other,
302-
Default,
303-
JITDefault,
304302
Small,
305303
Kernel,
306304
Medium,
307305
Large,
306+
None,
308307
}
309308

310309
/// LLVMRustDiagnosticKind
@@ -331,7 +330,6 @@ pub enum DiagnosticKind {
331330
pub enum ArchiveKind {
332331
Other,
333332
K_GNU,
334-
K_MIPS64,
335333
K_BSD,
336334
K_COFF,
337335
}

src/librustc_llvm/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ impl FromStr for ArchiveKind {
105105
fn from_str(s: &str) -> Result<Self, Self::Err> {
106106
match s {
107107
"gnu" => Ok(ArchiveKind::K_GNU),
108-
"mips64" => Ok(ArchiveKind::K_MIPS64),
109108
"bsd" => Ok(ArchiveKind::K_BSD),
110109
"coff" => Ok(ArchiveKind::K_COFF),
111110
_ => Err(()),

src/librustc_trans/back/write.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ pub const RELOC_MODEL_ARGS : [(&'static str, llvm::RelocMode); 7] = [
6969
("ropi-rwpi", llvm::RelocMode::ROPI_RWPI),
7070
];
7171

72-
pub const CODE_GEN_MODEL_ARGS : [(&'static str, llvm::CodeModel); 5] = [
73-
("default", llvm::CodeModel::Default),
72+
pub const CODE_GEN_MODEL_ARGS: &[(&str, llvm::CodeModel)] = &[
7473
("small", llvm::CodeModel::Small),
7574
("kernel", llvm::CodeModel::Kernel),
7675
("medium", llvm::CodeModel::Medium),
@@ -171,20 +170,23 @@ pub fn target_machine_factory(sess: &Session)
171170
let ffunction_sections = sess.target.target.options.function_sections;
172171
let fdata_sections = ffunction_sections;
173172

174-
let code_model_arg = match sess.opts.cg.code_model {
175-
Some(ref s) => &s,
176-
None => &sess.target.target.options.code_model,
177-
};
178-
179-
let code_model = match CODE_GEN_MODEL_ARGS.iter().find(
180-
|&&arg| arg.0 == code_model_arg) {
181-
Some(x) => x.1,
182-
_ => {
183-
sess.err(&format!("{:?} is not a valid code model",
184-
code_model_arg));
185-
sess.abort_if_errors();
186-
bug!();
173+
let code_model_arg = sess.opts.cg.code_model.as_ref().or(
174+
sess.target.target.options.code_model.as_ref(),
175+
);
176+
177+
let code_model = match code_model_arg {
178+
Some(s) => {
179+
match CODE_GEN_MODEL_ARGS.iter().find(|arg| arg.0 == s) {
180+
Some(x) => x.1,
181+
_ => {
182+
sess.err(&format!("{:?} is not a valid code model",
183+
code_model_arg));
184+
sess.abort_if_errors();
185+
bug!();
186+
}
187+
}
187188
}
189+
None => llvm::CodeModel::None,
188190
};
189191

190192
let singlethread = sess.target.target.options.singlethread;
@@ -746,7 +748,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
746748
// We can't use the same module for asm and binary output, because that triggers
747749
// various errors like invalid IR or broken binaries, so we might have to clone the
748750
// module to produce the asm output
749-
let llmod = if config.emit_obj {
751+
let llmod = if config.emit_obj && !asm2wasm {
750752
llvm::LLVMCloneModule(llmod)
751753
} else {
752754
llmod
@@ -755,7 +757,7 @@ unsafe fn codegen(cgcx: &CodegenContext,
755757
write_output_file(diag_handler, tm, cpm, llmod, &path,
756758
llvm::FileType::AssemblyFile)
757759
})?;
758-
if config.emit_obj {
760+
if config.emit_obj && !asm2wasm {
759761
llvm::LLVMDisposeModule(llmod);
760762
}
761763
timeline.record("asm");

src/llvm-emscripten

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 2717444753318e461e0c3b30dacd03ffbac96903

src/rustllvm/ArchiveWrapper.cpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ struct RustArchiveIterator {
4242
enum class LLVMRustArchiveKind {
4343
Other,
4444
GNU,
45-
MIPS64,
4645
BSD,
4746
COFF,
4847
};
@@ -51,8 +50,6 @@ static Archive::Kind fromRust(LLVMRustArchiveKind Kind) {
5150
switch (Kind) {
5251
case LLVMRustArchiveKind::GNU:
5352
return Archive::K_GNU;
54-
case LLVMRustArchiveKind::MIPS64:
55-
return Archive::K_MIPS64;
5653
case LLVMRustArchiveKind::BSD:
5754
return Archive::K_BSD;
5855
case LLVMRustArchiveKind::COFF:
@@ -235,9 +232,16 @@ LLVMRustWriteArchive(char *Dst, size_t NumMembers,
235232
Members.push_back(std::move(*MOrErr));
236233
}
237234
}
238-
auto Pair = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
239-
if (!Pair.second)
235+
auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
236+
#if LLVM_VERSION_GE(6, 0)
237+
if (!Result)
240238
return LLVMRustResult::Success;
241-
LLVMRustSetLastError(Pair.second.message().c_str());
239+
LLVMRustSetLastError(toString(std::move(Result)).c_str());
240+
#else
241+
if (!Result.second)
242+
return LLVMRustResult::Success;
243+
LLVMRustSetLastError(Result.second.message().c_str());
244+
#endif
245+
242246
return LLVMRustResult::Failure;
243247
}

src/rustllvm/PassWrapper.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
#include "llvm/Support/FileSystem.h"
2424
#include "llvm/Support/Host.h"
2525
#include "llvm/Target/TargetMachine.h"
26-
#include "llvm/Target/TargetSubtargetInfo.h"
2726
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
2827

28+
#if LLVM_VERSION_GE(6, 0)
29+
#include "llvm/CodeGen/TargetSubtargetInfo.h"
30+
#include "llvm/IR/IntrinsicInst.h"
31+
#else
32+
#include "llvm/Target/TargetSubtargetInfo.h"
33+
#endif
34+
2935
#if LLVM_VERSION_GE(4, 0)
3036
#include "llvm/Transforms/IPO/AlwaysInliner.h"
3137
#include "llvm/Transforms/IPO/FunctionImport.h"
@@ -210,20 +216,15 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
210216

211217
enum class LLVMRustCodeModel {
212218
Other,
213-
Default,
214-
JITDefault,
215219
Small,
216220
Kernel,
217221
Medium,
218222
Large,
223+
None,
219224
};
220225

221226
static CodeModel::Model fromRust(LLVMRustCodeModel Model) {
222227
switch (Model) {
223-
case LLVMRustCodeModel::Default:
224-
return CodeModel::Default;
225-
case LLVMRustCodeModel::JITDefault:
226-
return CodeModel::JITDefault;
227228
case LLVMRustCodeModel::Small:
228229
return CodeModel::Small;
229230
case LLVMRustCodeModel::Kernel:
@@ -360,7 +361,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
360361
bool TrapUnreachable,
361362
bool Singlethread) {
362363

363-
auto CM = fromRust(RustCM);
364364
auto OptLevel = fromRust(RustOptLevel);
365365
auto RM = fromRust(RustReloc);
366366

@@ -399,6 +399,13 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
399399
Options.ThreadModel = ThreadModel::Single;
400400
}
401401

402+
#if LLVM_VERSION_GE(6, 0)
403+
Optional<CodeModel::Model> CM;
404+
#else
405+
CodeModel::Model CM = CodeModel::Model::Default;
406+
#endif
407+
if (RustCM != LLVMRustCodeModel::None)
408+
CM = fromRust(RustCM);
402409
TargetMachine *TM = TheTarget->createTargetMachine(
403410
Trip.getTriple(), RealCPU, Feature, Options, RM, CM, OptLevel);
404411
return wrap(TM);

src/rustllvm/RustWrapper.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,
315315
// enable fpmath flag UnsafeAlgebra
316316
extern "C" void LLVMRustSetHasUnsafeAlgebra(LLVMValueRef V) {
317317
if (auto I = dyn_cast<Instruction>(unwrap<Value>(V))) {
318+
#if LLVM_VERSION_GE(6, 0)
319+
I->setFast(true);
320+
#else
318321
I->setHasUnsafeAlgebra(true);
322+
#endif
319323
}
320324
}
321325

0 commit comments

Comments
 (0)