Skip to content

Commit 904f579

Browse files
authored
Rollup merge of #128221 - calebzulawski:implied-target-features, r=Amanieu
Add implied target features to target_feature attribute See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context. Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`. Fixes #128125, fixes #128426 The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add. Please feel free to reassign this to whoever should review it. r? ``@Amanieu``
2 parents 8d00669 + 8818c95 commit 904f579

File tree

22 files changed

+593
-484
lines changed

22 files changed

+593
-484
lines changed

compiler/rustc_codegen_gcc/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
7575
let function_features = codegen_fn_attrs
7676
.target_features
7777
.iter()
78-
.map(|features| features.as_str())
78+
.map(|features| features.name.as_str())
7979
.collect::<Vec<&str>>();
8080

8181
if let Some(features) = check_tied_features(

compiler/rustc_codegen_gcc/src/gcc_util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ pub(crate) fn global_gcc_features(sess: &Session, diagnostics: bool) -> Vec<Stri
6565

6666
let feature = backend_feature_name(s)?;
6767
// Warn against use of GCC specific feature names on the CLI.
68-
if diagnostics && !supported_features.iter().any(|&(v, _)| v == feature) {
69-
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _)| {
68+
if diagnostics && !supported_features.iter().any(|&(v, _, _)| v == feature) {
69+
let rust_feature = supported_features.iter().find_map(|&(rust_feature, _, _)| {
7070
let gcc_features = to_gcc_features(sess, rust_feature);
7171
if gcc_features.contains(&feature) && !gcc_features.contains(&rust_feature) {
7272
Some(rust_feature)

compiler/rustc_codegen_gcc/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ pub fn target_features(
486486
sess.target
487487
.supported_target_features()
488488
.iter()
489-
.filter_map(|&(feature, gate)| {
489+
.filter_map(|&(feature, gate, _)| {
490490
if sess.is_nightly_build() || allow_unstable || gate.is_stable() {
491491
Some(feature)
492492
} else {

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
496496
to_add.extend(tune_cpu_attr(cx));
497497

498498
let function_features =
499-
codegen_fn_attrs.target_features.iter().map(|f| f.as_str()).collect::<Vec<&str>>();
499+
codegen_fn_attrs.target_features.iter().map(|f| f.name.as_str()).collect::<Vec<&str>>();
500500

501501
if let Some(f) = llvm_util::check_tied_features(
502502
cx.tcx.sess,

compiler/rustc_codegen_llvm/src/back/write.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ pub fn write_output_file<'ll>(
9595
}
9696
}
9797

98-
pub fn create_informational_target_machine(sess: &Session) -> OwnedTargetMachine {
98+
pub fn create_informational_target_machine(
99+
sess: &Session,
100+
only_base_features: bool,
101+
) -> OwnedTargetMachine {
99102
let config = TargetMachineFactoryConfig { split_dwarf_file: None, output_obj_file: None };
100103
// Can't use query system here quite yet because this function is invoked before the query
101104
// system/tcx is set up.
102-
let features = llvm_util::global_llvm_features(sess, false);
105+
let features = llvm_util::global_llvm_features(sess, false, only_base_features);
103106
target_machine_factory(sess, config::OptLevel::No, &features)(config)
104107
.unwrap_or_else(|err| llvm_err(sess.dcx(), err).raise())
105108
}

compiler/rustc_codegen_llvm/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub unsafe fn create_module<'ll>(
149149

150150
// Ensure the data-layout values hardcoded remain the defaults.
151151
{
152-
let tm = crate::back::write::create_informational_target_machine(tcx.sess);
152+
let tm = crate::back::write::create_informational_target_machine(tcx.sess, false);
153153
unsafe {
154154
llvm::LLVMRustSetDataLayoutFromTargetMachine(llmod, &tm);
155155
}

compiler/rustc_codegen_llvm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl CodegenBackend for LlvmCodegenBackend {
269269

270270
fn provide(&self, providers: &mut Providers) {
271271
providers.global_backend_features =
272-
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
272+
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true, false)
273273
}
274274

275275
fn print(&self, req: &PrintRequest, out: &mut String, sess: &Session) {
@@ -434,7 +434,7 @@ impl ModuleLlvm {
434434
ModuleLlvm {
435435
llmod_raw,
436436
llcx,
437-
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess)),
437+
tm: ManuallyDrop::new(create_informational_target_machine(tcx.sess, false)),
438438
}
439439
}
440440
}

0 commit comments

Comments
 (0)