From b6f845f22524c161d94ab37d630086780c4aabc1 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Thu, 3 Mar 2022 00:00:00 +0000 Subject: Use SmallStr when building target-features LLVM attribute --- compiler/rustc_codegen_llvm/src/attributes.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'compiler/rustc_codegen_llvm') diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 6fd836946ff..31117e1c11f 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -1,6 +1,7 @@ //! Set and unset common attributes on LLVM values. use rustc_codegen_ssa::traits::*; +use rustc_data_structures::small_str::SmallStr; use rustc_hir::def_id::DefId; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::ty::{self, TyCtxt}; @@ -382,7 +383,7 @@ pub fn from_fn_attrs<'ll, 'tcx>( let val = global_features .chain(function_features.iter().map(|s| &s[..])) .intersperse(",") - .collect::(); + .collect::>(); to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &val)); } -- cgit 1.4.1-3-g733a5 From 095d818e0c9c2428e11287e918c38bb6c487e6ed Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Thu, 3 Mar 2022 00:00:00 +0000 Subject: Always include global target features in function attributes This ensures that information about target features configured with `-C target-feature=...` or detected with `-C target-cpu=native` is retained for subsequent consumers of LLVM bitcode. This is crucial for linker plugin LTO, since this information is not conveyed to the plugin otherwise. --- compiler/rustc_codegen_llvm/src/attributes.rs | 13 ++++++------- src/test/codegen/target-feature-overrides.rs | 6 +++--- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'compiler/rustc_codegen_llvm') diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index 31117e1c11f..101da0012cb 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -378,13 +378,12 @@ pub fn from_fn_attrs<'ll, 'tcx>( } } - if !function_features.is_empty() { - let global_features = cx.tcx.global_backend_features(()).iter().map(|s| &s[..]); - let val = global_features - .chain(function_features.iter().map(|s| &s[..])) - .intersperse(",") - .collect::>(); - to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &val)); + let global_features = cx.tcx.global_backend_features(()).iter().map(|s| s.as_str()); + let function_features = function_features.iter().map(|s| s.as_str()); + let target_features = + global_features.chain(function_features).intersperse(",").collect::>(); + if !target_features.is_empty() { + to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features)); } attributes::apply_to_llfn(llfn, Function, &to_add); diff --git a/src/test/codegen/target-feature-overrides.rs b/src/test/codegen/target-feature-overrides.rs index 2c19cfd8c22..4be77e36e76 100644 --- a/src/test/codegen/target-feature-overrides.rs +++ b/src/test/codegen/target-feature-overrides.rs @@ -29,7 +29,7 @@ pub unsafe fn apple() -> u32 { peach() } -// target features same as global (not reflected or overriden in IR) +// target features same as global #[no_mangle] pub unsafe fn banana() -> u32 { // CHECK-LABEL: @banana() @@ -43,5 +43,5 @@ pub unsafe fn banana() -> u32 { // COMPAT-SAME: "target-features"="+avx2,+avx,+avx" // INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx" // CHECK: attributes [[BANANAATTRS]] -// CHECK-NOT: target-features -// CHECK-SAME: } +// COMPAT-SAME: "target-features"="+avx2,+avx" +// INCOMPAT-SAME: "target-features"="-avx2,-avx" -- cgit 1.4.1-3-g733a5