auto merge of #8410 : luqmana/rust/mcpu, r=sanxiyn
Adds `--target-cpu` flag which lets you choose a more specific target cpu instead of just passing the default, `generic`. It's more or less akin to `-mcpu`/`-mtune` in clang/gcc.
This commit is contained in:
commit
1785841a5b
6 changed files with 36 additions and 28 deletions
|
@ -27,7 +27,8 @@ _rustc_opts_switches=(
|
||||||
--sysroot'[Override the system root]'
|
--sysroot'[Override the system root]'
|
||||||
--test'[Build a test harness]'
|
--test'[Build a test harness]'
|
||||||
--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
|
--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
|
||||||
--target-feature'[Target specific attributes (llc -mattr=help for detail)]'
|
--target-cpu'[Select target processor (llc -mcpu=help for details)]'
|
||||||
|
--target-feature'[Target specific attributes (llc -mattr=help for details)]'
|
||||||
--android-cross-path'[The path to the Android NDK]'
|
--android-cross-path'[The path to the Android NDK]'
|
||||||
{-v,--version}'[Print version info and exit]'
|
{-v,--version}'[Print version info and exit]'
|
||||||
)
|
)
|
||||||
|
|
|
@ -69,6 +69,7 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
|
||||||
pub fn WriteOutputFile(sess: Session,
|
pub fn WriteOutputFile(sess: Session,
|
||||||
PM: lib::llvm::PassManagerRef, M: ModuleRef,
|
PM: lib::llvm::PassManagerRef, M: ModuleRef,
|
||||||
Triple: &str,
|
Triple: &str,
|
||||||
|
Cpu: &str,
|
||||||
Feature: &str,
|
Feature: &str,
|
||||||
Output: &str,
|
Output: &str,
|
||||||
// FIXME: When #2334 is fixed, change
|
// FIXME: When #2334 is fixed, change
|
||||||
|
@ -78,12 +79,14 @@ pub fn WriteOutputFile(sess: Session,
|
||||||
EnableSegmentedStacks: bool) {
|
EnableSegmentedStacks: bool) {
|
||||||
unsafe {
|
unsafe {
|
||||||
do Triple.to_c_str().with_ref |Triple| {
|
do Triple.to_c_str().with_ref |Triple| {
|
||||||
|
do Cpu.to_c_str().with_ref |Cpu| {
|
||||||
do Feature.to_c_str().with_ref |Feature| {
|
do Feature.to_c_str().with_ref |Feature| {
|
||||||
do Output.to_c_str().with_ref |Output| {
|
do Output.to_c_str().with_ref |Output| {
|
||||||
let result = llvm::LLVMRustWriteOutputFile(
|
let result = llvm::LLVMRustWriteOutputFile(
|
||||||
PM,
|
PM,
|
||||||
M,
|
M,
|
||||||
Triple,
|
Triple,
|
||||||
|
Cpu,
|
||||||
Feature,
|
Feature,
|
||||||
Output,
|
Output,
|
||||||
FileType,
|
FileType,
|
||||||
|
@ -96,6 +99,7 @@ pub fn WriteOutputFile(sess: Session,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod jit {
|
pub mod jit {
|
||||||
|
@ -346,6 +350,7 @@ pub mod write {
|
||||||
pm.llpm,
|
pm.llpm,
|
||||||
llmod,
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|
opts.target_cpu,
|
||||||
opts.target_feature,
|
opts.target_feature,
|
||||||
output.to_str(),
|
output.to_str(),
|
||||||
lib::llvm::AssemblyFile as c_uint,
|
lib::llvm::AssemblyFile as c_uint,
|
||||||
|
@ -362,6 +367,7 @@ pub mod write {
|
||||||
pm.llpm,
|
pm.llpm,
|
||||||
llmod,
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|
opts.target_cpu,
|
||||||
opts.target_feature,
|
opts.target_feature,
|
||||||
output.to_str(),
|
output.to_str(),
|
||||||
lib::llvm::ObjectFile as c_uint,
|
lib::llvm::ObjectFile as c_uint,
|
||||||
|
@ -376,6 +382,7 @@ pub mod write {
|
||||||
pm.llpm,
|
pm.llpm,
|
||||||
llmod,
|
llmod,
|
||||||
sess.targ_cfg.target_strs.target_triple,
|
sess.targ_cfg.target_strs.target_triple,
|
||||||
|
opts.target_cpu,
|
||||||
opts.target_feature,
|
opts.target_feature,
|
||||||
output.to_str(),
|
output.to_str(),
|
||||||
FileType as c_uint,
|
FileType as c_uint,
|
||||||
|
|
|
@ -684,8 +684,9 @@ pub fn build_session_options(binary: @str,
|
||||||
link::output_type_bitcode
|
link::output_type_bitcode
|
||||||
} else { link::output_type_exe };
|
} else { link::output_type_exe };
|
||||||
let sysroot_opt = getopts::opt_maybe_str(matches, "sysroot").map_move(|m| @Path(m));
|
let sysroot_opt = getopts::opt_maybe_str(matches, "sysroot").map_move(|m| @Path(m));
|
||||||
let target_opt = getopts::opt_maybe_str(matches, "target");
|
let target = getopts::opt_maybe_str(matches, "target").unwrap_or_default(host_triple());
|
||||||
let target_feature_opt = getopts::opt_maybe_str(matches, "target-feature");
|
let target_cpu = getopts::opt_maybe_str(matches, "target-cpu").unwrap_or_default(~"generic");
|
||||||
|
let target_feature = getopts::opt_maybe_str(matches, "target-feature").unwrap_or_default(~"");
|
||||||
let save_temps = getopts::opt_present(matches, "save-temps");
|
let save_temps = getopts::opt_present(matches, "save-temps");
|
||||||
let opt_level = {
|
let opt_level = {
|
||||||
if (debugging_opts & session::no_opt) != 0 {
|
if (debugging_opts & session::no_opt) != 0 {
|
||||||
|
@ -713,15 +714,6 @@ pub fn build_session_options(binary: @str,
|
||||||
let debuginfo = debugging_opts & session::debug_info != 0 ||
|
let debuginfo = debugging_opts & session::debug_info != 0 ||
|
||||||
extra_debuginfo;
|
extra_debuginfo;
|
||||||
let statik = debugging_opts & session::statik != 0;
|
let statik = debugging_opts & session::statik != 0;
|
||||||
let target =
|
|
||||||
match target_opt {
|
|
||||||
None => host_triple(),
|
|
||||||
Some(s) => s
|
|
||||||
};
|
|
||||||
let target_feature = match target_feature_opt {
|
|
||||||
None => ~"",
|
|
||||||
Some(s) => s
|
|
||||||
};
|
|
||||||
|
|
||||||
let addl_lib_search_paths = getopts::opt_strs(matches, "L").map(|s| Path(*s));
|
let addl_lib_search_paths = getopts::opt_strs(matches, "L").map(|s| Path(*s));
|
||||||
let linker = getopts::opt_maybe_str(matches, "linker");
|
let linker = getopts::opt_maybe_str(matches, "linker");
|
||||||
|
@ -760,6 +752,7 @@ pub fn build_session_options(binary: @str,
|
||||||
linker_args: linker_args,
|
linker_args: linker_args,
|
||||||
maybe_sysroot: sysroot_opt,
|
maybe_sysroot: sysroot_opt,
|
||||||
target_triple: target,
|
target_triple: target,
|
||||||
|
target_cpu: target_cpu,
|
||||||
target_feature: target_feature,
|
target_feature: target_feature,
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
binary: binary,
|
binary: binary,
|
||||||
|
@ -876,10 +869,13 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
|
||||||
optopt("", "target",
|
optopt("", "target",
|
||||||
"Target triple cpu-manufacturer-kernel[-os]
|
"Target triple cpu-manufacturer-kernel[-os]
|
||||||
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
||||||
for detail)", "TRIPLE"),
|
for details)", "TRIPLE"),
|
||||||
|
optopt("", "target-cpu",
|
||||||
|
"Select target processor (llc -mcpu=help
|
||||||
|
for details)", "CPU"),
|
||||||
optopt("", "target-feature",
|
optopt("", "target-feature",
|
||||||
"Target specific attributes (llc -mattr=help
|
"Target specific attributes (llc -mattr=help
|
||||||
for detail)", "FEATURE"),
|
for details)", "FEATURE"),
|
||||||
optopt("", "android-cross-path",
|
optopt("", "android-cross-path",
|
||||||
"The path to the Android NDK", "PATH"),
|
"The path to the Android NDK", "PATH"),
|
||||||
optflagopt("W", "warn",
|
optflagopt("W", "warn",
|
||||||
|
|
|
@ -153,6 +153,7 @@ pub struct options {
|
||||||
linker_args: ~[~str],
|
linker_args: ~[~str],
|
||||||
maybe_sysroot: Option<@Path>,
|
maybe_sysroot: Option<@Path>,
|
||||||
target_triple: ~str,
|
target_triple: ~str,
|
||||||
|
target_cpu: ~str,
|
||||||
target_feature: ~str,
|
target_feature: ~str,
|
||||||
// User-specified cfg meta items. The compiler itself will add additional
|
// User-specified cfg meta items. The compiler itself will add additional
|
||||||
// items to the crate config, and during parsing the entire crate config
|
// items to the crate config, and during parsing the entire crate config
|
||||||
|
@ -340,6 +341,7 @@ pub fn basic_options() -> @options {
|
||||||
linker_args: ~[],
|
linker_args: ~[],
|
||||||
maybe_sysroot: None,
|
maybe_sysroot: None,
|
||||||
target_triple: host_triple(),
|
target_triple: host_triple(),
|
||||||
|
target_cpu: ~"generic",
|
||||||
target_feature: ~"",
|
target_feature: ~"",
|
||||||
cfg: ~[],
|
cfg: ~[],
|
||||||
binary: @"rustc",
|
binary: @"rustc",
|
||||||
|
|
|
@ -1811,6 +1811,7 @@ pub mod llvm {
|
||||||
pub fn LLVMRustWriteOutputFile(PM: PassManagerRef,
|
pub fn LLVMRustWriteOutputFile(PM: PassManagerRef,
|
||||||
M: ModuleRef,
|
M: ModuleRef,
|
||||||
Triple: *c_char,
|
Triple: *c_char,
|
||||||
|
Cpu: *c_char,
|
||||||
Feature: *c_char,
|
Feature: *c_char,
|
||||||
Output: *c_char,
|
Output: *c_char,
|
||||||
// FIXME: When #2334 is fixed,
|
// FIXME: When #2334 is fixed,
|
||||||
|
|
|
@ -372,6 +372,7 @@ extern "C" bool
|
||||||
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||||
LLVMModuleRef M,
|
LLVMModuleRef M,
|
||||||
const char *triple,
|
const char *triple,
|
||||||
|
const char *cpu,
|
||||||
const char *feature,
|
const char *feature,
|
||||||
const char *path,
|
const char *path,
|
||||||
TargetMachine::CodeGenFileType FileType,
|
TargetMachine::CodeGenFileType FileType,
|
||||||
|
@ -401,7 +402,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
|
||||||
std::string Err;
|
std::string Err;
|
||||||
std::string Trip(Triple::normalize(triple));
|
std::string Trip(Triple::normalize(triple));
|
||||||
std::string FeaturesStr(feature);
|
std::string FeaturesStr(feature);
|
||||||
std::string CPUStr("generic");
|
std::string CPUStr(cpu);
|
||||||
const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
|
const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
|
||||||
TargetMachine *Target =
|
TargetMachine *Target =
|
||||||
TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr,
|
TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue