Skip to content

Commit 87daba2

Browse files
committed
Only add feature flags on functions
1 parent 20d4c39 commit 87daba2

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

src/attributes.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,18 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
9494
}))
9595
.collect::<Vec<_>>();
9696

97-
// TODO(antoyo): cg_llvm add global features to each function so that LTO keep them.
97+
// TODO(antoyo): cg_llvm adds global features to each function so that LTO keep them.
9898
// Check if GCC requires the same.
9999
let mut global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str());
100100
function_features.extend(&mut global_features);
101101
let target_features = function_features
102102
.iter()
103103
.filter_map(|feature| {
104-
if feature.contains("soft-float") || feature.contains("retpoline-external-thunk") {
104+
// FIXME(antoyo): for some reasons, disabling SSE results in the following error when
105+
// compiling Rust for Linux:
106+
// SSE register return with SSE disabled
107+
// TODO(antoyo): support soft-float and retpoline-external-thunk.
108+
if feature.contains("soft-float") || feature.contains("retpoline-external-thunk") || *feature == "-sse" {
105109
return None;
106110
}
107111

@@ -118,7 +122,6 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
118122
.collect::<Vec<_>>()
119123
.join(",");
120124
if !target_features.is_empty() {
121-
println!("Function {:?}", function_features);
122125
#[cfg(feature="master")]
123126
func.add_attribute(FnAttribute::Target(&target_features));
124127
}

src/base.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,32 +98,10 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
9898
.map(|string| &string[1..])
9999
.collect();
100100

101-
let add_cpu_feature_flag = |feature: &str| {
102-
if target_info.cpu_supports(feature) && !disabled_features.contains(feature) {
103-
context.add_command_line_option(&format!("-m{}", feature));
104-
}
105-
};
106-
107-
let disable_cpu_feature = |feature: &str| {
108-
if disabled_features.contains(feature) {
109-
context.add_command_line_option(&format!("-mno-{}", feature));
110-
}
111-
};
112-
113101
// TODO(antoyo): only set on x86 platforms.
114102
context.add_command_line_option("-masm=intel");
115103

116-
// TODO: instead of setting the features manually, set the correct -march flag.
117-
let features = ["64", "avxvnni", "bmi", "sse2", "avx2", "sha", "fma", "fma4", "gfni", "f16c", "aes", "bmi2", "pclmul", "rtm",
118-
"vaes", "vpclmulqdq", "xsavec",
119-
];
120-
121-
122-
for feature in &features {
123-
disable_cpu_feature(feature);
124-
125-
//add_cpu_feature_flag(feature);
126-
}
104+
// TODO(antoyo): set the correct -march flag.
127105

128106
if !disabled_features.contains("avx") {
129107
// NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for

src/gcc_util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
100100
Some(to_gcc_features(sess, feature)
101101
.iter()
102102
.flat_map(|feat| to_gcc_features(sess, feat).into_iter())
103-
.map(String::from)
103+
.map(|feature| {
104+
if enable_disable == '-' {
105+
format!("-{}", feature)
106+
}
107+
else {
108+
feature.to_string()
109+
}
110+
})
104111
.collect::<Vec<_>>(),
105112
)
106113
})

0 commit comments

Comments
 (0)