Skip to content

Commit 157137a

Browse files
committed
Change signature of target_features_cfg.
Currently it is called twice, once with `allow_unstable` set to true and once with it set to false. This results in some duplicated work. Most notably, for the LLVM backend, `LLVMRustHasFeature` is called twice for every feature, and it's moderately slow. For very short running compilations on platforms with many features (e.g. a `check` build of hello-world on x86) this is a significant fraction of runtime. This commit changes `target_features_cfg` so it is only called once, and it now returns a pair of feature sets. This halves the number of `LLVMRustHasFeature` calls.
1 parent ee5bae8 commit 157137a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,9 @@ impl CodegenBackend for CraneliftCodegenBackend {
176176
}
177177
}
178178

179-
fn target_features_cfg(
180-
&self,
181-
sess: &Session,
182-
_allow_unstable: bool,
183-
) -> Vec<rustc_span::Symbol> {
179+
fn target_features_cfg(&self, sess: &Session) -> (Vec<Symbol>, Vec<Symbol>) {
184180
// FIXME return the actually used target features. this is necessary for #[cfg(target_feature)]
185-
if sess.target.arch == "x86_64" && sess.target.os != "none" {
181+
let target_features = if sess.target.arch == "x86_64" && sess.target.os != "none" {
186182
// x86_64 mandates SSE2 support and rustc requires the x87 feature to be enabled
187183
vec![sym::fsxr, sym::sse, sym::sse2, Symbol::intern("x87")]
188184
} else if sess.target.arch == "aarch64" {
@@ -196,7 +192,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
196192
}
197193
} else {
198194
vec![]
199-
}
195+
};
196+
// FIXME do `unstable_target_features` properly
197+
let unstable_target_features = target_features.clone();
198+
(target_features, unstable_target_features)
200199
}
201200

202201
fn print_version(&self) {

0 commit comments

Comments
 (0)