/// 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,
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,
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);
#[repr(C)]
pub enum CodeModel {
Other,
- Default,
- JITDefault,
Small,
Kernel,
Medium,
Large,
+ None,
}
/// LLVMRustDiagnosticKind
("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),
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;
#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"
+#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"
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:
bool TrapUnreachable,
bool Singlethread) {
- auto CM = fromRust(RustCM);
auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
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);