Skip to content

Commit 0d0162b

Browse files
fix(compiler/rustc_codegen_llvm): apply target-cpu attribute
1 parent 6355cd3 commit 0d0162b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ use rustc_middle::bug;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_session::config::{DebugInfo, OomStrategy};
1010
use rustc_symbol_mangling::mangle_internal_symbol;
11+
use smallvec::SmallVec;
1112

1213
use crate::builder::SBuilder;
1314
use crate::declare::declare_simple_fn;
1415
use crate::llvm::{self, False, True, Type, Value};
16+
use crate::llvm_util;
1517
use crate::{SimpleCx, attributes, debuginfo};
1618

1719
pub(crate) unsafe fn codegen(
@@ -147,6 +149,20 @@ fn create_wrapper_function(
147149
llvm::Visibility::from_generic(tcx.sess.default_visibility()),
148150
ty,
149151
);
152+
153+
let mut attrs = SmallVec::<[_; 2]>::new();
154+
155+
let target_cpu = llvm_util::target_cpu(tcx.sess);
156+
let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu);
157+
158+
let tune_cpu_attr = llvm_util::tune_cpu(tcx.sess)
159+
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu));
160+
161+
attrs.push(target_cpu_attr);
162+
attrs.extend(tune_cpu_attr);
163+
164+
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
165+
150166
let no_return = if no_return {
151167
// -> ! DIFlagNoReturn
152168
let no_return = llvm::AttributeKind::NoReturn.create_attr(cx.llcx);

0 commit comments

Comments
 (0)