diff options
| author | StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> | 2025-08-12 00:39:24 +0300 |
|---|---|---|
| committer | StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> | 2025-08-13 17:49:06 +0000 |
| commit | f978932903cac8cf508ef78b8133fafd9fe5a5b8 (patch) | |
| tree | 0177cd2c746c49ae97a2a33804be34ed6b45438b /compiler/rustc_codegen_llvm | |
| parent | 350d0ef0ec0493e6d21cfb265cb8211a0e74d766 (diff) | |
| download | rust-f978932903cac8cf508ef78b8133fafd9fe5a5b8.tar.gz rust-f978932903cac8cf508ef78b8133fafd9fe5a5b8.zip | |
fix(compiler/rustc_codegen_llvm): apply `target-cpu` attribute
Diffstat (limited to 'compiler/rustc_codegen_llvm')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/allocator.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index 2b5090ed6db..23610aa856c 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -8,11 +8,12 @@ use rustc_middle::bug; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, OomStrategy}; use rustc_symbol_mangling::mangle_internal_symbol; +use smallvec::SmallVec; use crate::builder::SBuilder; use crate::declare::declare_simple_fn; use crate::llvm::{self, False, True, Type, Value}; -use crate::{SimpleCx, attributes, debuginfo}; +use crate::{SimpleCx, attributes, debuginfo, llvm_util}; pub(crate) unsafe fn codegen( tcx: TyCtxt<'_>, @@ -147,6 +148,20 @@ fn create_wrapper_function( llvm::Visibility::from_generic(tcx.sess.default_visibility()), ty, ); + + let mut attrs = SmallVec::<[_; 2]>::new(); + + let target_cpu = llvm_util::target_cpu(tcx.sess); + let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu); + + let tune_cpu_attr = llvm_util::tune_cpu(tcx.sess) + .map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu)); + + attrs.push(target_cpu_attr); + attrs.extend(tune_cpu_attr); + + attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs); + let no_return = if no_return { // -> ! DIFlagNoReturn let no_return = llvm::AttributeKind::NoReturn.create_attr(cx.llcx); |
