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.
This commit is contained in:
parent
b6f845f225
commit
095d818e0c
@ -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.as_str());
|
||||||
let global_features = cx.tcx.global_backend_features(()).iter().map(|s| &s[..]);
|
let function_features = function_features.iter().map(|s| s.as_str());
|
||||||
let val = global_features
|
let target_features =
|
||||||
.chain(function_features.iter().map(|s| &s[..]))
|
global_features.chain(function_features).intersperse(",").collect::<SmallStr<1024>>();
|
||||||
.intersperse(",")
|
if !target_features.is_empty() {
|
||||||
.collect::<SmallStr<1024>>();
|
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &target_features));
|
||||||
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "target-features", &val));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes::apply_to_llfn(llfn, Function, &to_add);
|
attributes::apply_to_llfn(llfn, Function, &to_add);
|
||||||
|
@ -29,7 +29,7 @@ pub unsafe fn apple() -> u32 {
|
|||||||
peach()
|
peach()
|
||||||
}
|
}
|
||||||
|
|
||||||
// target features same as global (not reflected or overriden in IR)
|
// target features same as global
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe fn banana() -> u32 {
|
pub unsafe fn banana() -> u32 {
|
||||||
// CHECK-LABEL: @banana()
|
// CHECK-LABEL: @banana()
|
||||||
@ -43,5 +43,5 @@ pub unsafe fn banana() -> u32 {
|
|||||||
// COMPAT-SAME: "target-features"="+avx2,+avx,+avx"
|
// COMPAT-SAME: "target-features"="+avx2,+avx,+avx"
|
||||||
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx"
|
// INCOMPAT-SAME: "target-features"="-avx2,-avx,+avx"
|
||||||
// CHECK: attributes [[BANANAATTRS]]
|
// CHECK: attributes [[BANANAATTRS]]
|
||||||
// CHECK-NOT: target-features
|
// COMPAT-SAME: "target-features"="+avx2,+avx"
|
||||||
// CHECK-SAME: }
|
// INCOMPAT-SAME: "target-features"="-avx2,-avx"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user