Skip to content

Commit a9a2c68

Browse files
committed
Send -march to gcc
1 parent 87daba2 commit a9a2c68

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/base.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_codegen_ssa::traits::DebugInfoMethods;
1919
use rustc_session::config::DebugInfo;
2020
use rustc_span::Symbol;
2121

22-
use crate::LockedTargetInfo;
22+
use crate::{LockedTargetInfo, gcc_util};
2323
use crate::GccContext;
2424
use crate::builder::Builder;
2525
use crate::context::CodegenCx;
@@ -101,8 +101,6 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
101101
// TODO(antoyo): only set on x86 platforms.
102102
context.add_command_line_option("-masm=intel");
103103

104-
// TODO(antoyo): set the correct -march flag.
105-
106104
if !disabled_features.contains("avx") {
107105
// NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for
108106
// SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead.
@@ -127,6 +125,11 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
127125
context.add_command_line_option("-fno-pie");
128126
}
129127

128+
let target_cpu = gcc_util::target_cpu(tcx.sess);
129+
if target_cpu != "generic" {
130+
context.add_command_line_option(&format!("-march={}", target_cpu));
131+
}
132+
130133
if tcx.sess.opts.unstable_opts.function_sections.unwrap_or(tcx.sess.target.function_sections) {
131134
context.add_command_line_option("-ffunction-sections");
132135
context.add_command_line_option("-fdata-sections");

src/gcc_util.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,18 @@ pub fn check_tied_features(sess: &Session, features: &FxHashMap<&str, bool>) ->
198198
}
199199
None
200200
}
201+
202+
fn handle_native(name: &str) -> &str {
203+
if name != "native" {
204+
return name;
205+
}
206+
207+
unimplemented!();
208+
}
209+
210+
pub fn target_cpu(sess: &Session) -> &str {
211+
match sess.opts.cg.target_cpu {
212+
Some(ref name) => handle_native(name),
213+
None => handle_native(sess.target.cpu.as_ref()),
214+
}
215+
}

src/lib.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ use rustc_span::fatal_error::FatalError;
107107
use tempfile::TempDir;
108108

109109
use crate::back::lto::ModuleBuffer;
110+
use crate::gcc_util::target_cpu;
110111

111112
fluent_messages! { "../messages.ftl" }
112113

@@ -366,21 +367,6 @@ fn to_gcc_opt_level(optlevel: Option<OptLevel>) -> OptimizationLevel {
366367
}
367368
}
368369

369-
fn handle_native(name: &str) -> &str {
370-
if name != "native" {
371-
return name;
372-
}
373-
374-
unimplemented!();
375-
}
376-
377-
pub fn target_cpu(sess: &Session) -> &str {
378-
match sess.opts.cg.target_cpu {
379-
Some(ref name) => handle_native(name),
380-
None => handle_native(sess.target.cpu.as_ref()),
381-
}
382-
}
383-
384370
pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &LockedTargetInfo) -> Vec<Symbol> {
385371
supported_target_features(sess)
386372
.iter()

0 commit comments

Comments
 (0)