]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Add --target-cpu flag to select a more specific processor instead of the defau...
authorLuqman Aden <laden@csclub.uwaterloo.ca>
Fri, 9 Aug 2013 02:16:00 +0000 (22:16 -0400)
committerLuqman Aden <laden@csclub.uwaterloo.ca>
Sat, 10 Aug 2013 21:03:43 +0000 (17:03 -0400)
src/etc/zsh/_rust
src/librustc/back/link.rs
src/librustc/driver/driver.rs
src/librustc/driver/session.rs
src/librustc/lib/llvm.rs
src/rustllvm/RustWrapper.cpp

index befed411dd1b1f1a8a623e99fbb7b7bc3790359c..7320eced7e1be74ab9f2158bfa2a8b6e5e411f1a 100644 (file)
@@ -27,7 +27,8 @@ _rustc_opts_switches=(
     --sysroot'[Override the system root]'
     --test'[Build a test harness]'
     --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]'
     {-v,--version}'[Print version info and exit]'
 )
index fbe17fb0d1c9e0ddf9a0904f1e1544d6db04e61e..c17c61e946647d7a0c8b2786b1a320f4386c4097 100644 (file)
@@ -69,6 +69,7 @@ pub fn llvm_err(sess: Session, msg: ~str) -> ! {
 pub fn WriteOutputFile(sess: Session,
         PM: lib::llvm::PassManagerRef, M: ModuleRef,
         Triple: &str,
+        Cpu: &str,
         Feature: &str,
         Output: &str,
         // FIXME: When #2334 is fixed, change
@@ -78,19 +79,22 @@ pub fn WriteOutputFile(sess: Session,
         EnableSegmentedStacks: bool) {
     unsafe {
         do Triple.to_c_str().with_ref |Triple| {
-            do Feature.to_c_str().with_ref |Feature| {
-                do Output.to_c_str().with_ref |Output| {
-                    let result = llvm::LLVMRustWriteOutputFile(
-                            PM,
-                            M,
-                            Triple,
-                            Feature,
-                            Output,
-                            FileType,
-                            OptLevel,
-                            EnableSegmentedStacks);
-                    if (!result) {
-                        llvm_err(sess, ~"Could not write output");
+            do Cpu.to_c_str().with_ref |Cpu| {
+                do Feature.to_c_str().with_ref |Feature| {
+                    do Output.to_c_str().with_ref |Output| {
+                        let result = llvm::LLVMRustWriteOutputFile(
+                                PM,
+                                M,
+                                Triple,
+                                Cpu,
+                                Feature,
+                                Output,
+                                FileType,
+                                OptLevel,
+                                EnableSegmentedStacks);
+                        if (!result) {
+                            llvm_err(sess, ~"Could not write output");
+                        }
                     }
                 }
             }
@@ -346,6 +350,7 @@ pub fn run_passes(sess: Session,
                             pm.llpm,
                             llmod,
                             sess.targ_cfg.target_strs.target_triple,
+                            opts.target_cpu,
                             opts.target_feature,
                             output.to_str(),
                             lib::llvm::AssemblyFile as c_uint,
@@ -362,6 +367,7 @@ pub fn run_passes(sess: Session,
                             pm.llpm,
                             llmod,
                             sess.targ_cfg.target_strs.target_triple,
+                            opts.target_cpu,
                             opts.target_feature,
                             output.to_str(),
                             lib::llvm::ObjectFile as c_uint,
@@ -376,6 +382,7 @@ pub fn run_passes(sess: Session,
                         pm.llpm,
                         llmod,
                         sess.targ_cfg.target_strs.target_triple,
+                        opts.target_cpu,
                         opts.target_feature,
                         output.to_str(),
                         FileType as c_uint,
index e349502d143c0b0432104190834e75621dc25d0f..2571ccc28991b24cda5e6a47ed5a4f69089ff0bd 100644 (file)
@@ -684,8 +684,9 @@ pub fn build_session_options(binary: @str,
             link::output_type_bitcode
         } else { link::output_type_exe };
     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_feature_opt = getopts::opt_maybe_str(matches, "target-feature");
+    let target = getopts::opt_maybe_str(matches, "target").unwrap_or_default(host_triple());
+    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 opt_level = {
         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 ||
         extra_debuginfo;
     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 linker = getopts::opt_maybe_str(matches, "linker");
@@ -760,6 +752,7 @@ pub fn build_session_options(binary: @str,
         linker_args: linker_args,
         maybe_sysroot: sysroot_opt,
         target_triple: target,
+        target_cpu: target_cpu,
         target_feature: target_feature,
         cfg: cfg,
         binary: binary,
@@ -876,10 +869,13 @@ pub fn optgroups() -> ~[getopts::groups::OptGroup] {
   optopt("", "target",
                         "Target triple cpu-manufacturer-kernel[-os]
                           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",
                         "Target specific attributes (llc -mattr=help
-                          for detail)", "FEATURE"),
+                          for details)", "FEATURE"),
   optopt("", "android-cross-path",
          "The path to the Android NDK", "PATH"),
   optflagopt("W", "warn",
index d725e2db1eba109474b71b0a65eaf6d655fd8e6c..fe1b49b96a232ad37153c00d08dbc2839302d860 100644 (file)
@@ -153,6 +153,7 @@ pub struct options {
     linker_args: ~[~str],
     maybe_sysroot: Option<@Path>,
     target_triple: ~str,
+    target_cpu: ~str,
     target_feature: ~str,
     // User-specified cfg meta items. The compiler itself will add additional
     // items to the crate config, and during parsing the entire crate config
@@ -340,6 +341,7 @@ pub fn basic_options() -> @options {
         linker_args: ~[],
         maybe_sysroot: None,
         target_triple: host_triple(),
+        target_cpu: ~"generic",
         target_feature: ~"",
         cfg: ~[],
         binary: @"rustc",
index 5801e43a54cd2ba0bfd7d02757a35909b18ee931..cddb8920f677a41af7a6566b81ea17f7bdbb2782 100644 (file)
@@ -1811,6 +1811,7 @@ pub fn LLVMRustCreateMemoryBufferWithContentsOfFile(Path: *c_char)
         pub fn LLVMRustWriteOutputFile(PM: PassManagerRef,
                                        M: ModuleRef,
                                        Triple: *c_char,
+                                       Cpu: *c_char,
                                        Feature: *c_char,
                                        Output: *c_char,
                                        // FIXME: When #2334 is fixed,
index 04c062072d6cb4d8fd9dc4152f0af3f028f95f25..e47ed82c28190f6b9e300289d102507a5959ac2c 100644 (file)
@@ -372,6 +372,7 @@ extern "C" bool
 LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
                         LLVMModuleRef M,
                         const char *triple,
+                        const char *cpu,
                         const char *feature,
                         const char *path,
                         TargetMachine::CodeGenFileType FileType,
@@ -401,7 +402,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
   std::string Err;
   std::string Trip(Triple::normalize(triple));
   std::string FeaturesStr(feature);
-  std::string CPUStr("generic");
+  std::string CPUStr(cpu);
   const Target *TheTarget = TargetRegistry::lookupTarget(Trip, Err);
   TargetMachine *Target =
     TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr,