Skip to content

Commit 2f5cb60

Browse files
committed
Use standard attribute logic for allocator shim
Use llfn_attrs_from_instance() to generate the attributes for the allocator shim. This ensures that we generate all the usual attributes (and don't get to find out one-by-one that a certain attribute is important for a certain target). Additionally this will enable emitting the allocator-specific attributes (not included here). This change is quite awkward because the allocator shim uses SimpleCx, while llfn_attrs_from_instance uses CodegenCx. I've switched it to use SimpleCx plus tcx/sess arguments where necessary. If there's a simpler way to do this, I'd love to know about it...
1 parent 32e3d9f commit 2f5cb60

File tree

7 files changed

+126
-116
lines changed

7 files changed

+126
-116
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,13 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
538538

539539
// If the declaration has an associated instance, compute extra attributes based on that.
540540
if let Some(instance) = instance {
541-
llfn_attrs_from_instance(cx, llfn, instance);
541+
llfn_attrs_from_instance(
542+
cx,
543+
cx.tcx,
544+
llfn,
545+
&cx.tcx.codegen_instance_attrs(instance.def),
546+
Some(instance),
547+
);
542548
}
543549
}
544550

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ use rustc_ast::expand::allocator::{
55
};
66
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
77
use rustc_middle::bug;
8+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
89
use rustc_middle::ty::TyCtxt;
910
use rustc_session::config::{DebugInfo, OomStrategy};
1011
use rustc_symbol_mangling::mangle_internal_symbol;
11-
use smallvec::SmallVec;
1212

13+
use crate::attributes::llfn_attrs_from_instance;
1314
use crate::builder::SBuilder;
1415
use crate::declare::declare_simple_fn;
1516
use crate::llvm::{self, FALSE, TRUE, Type, Value};
16-
use crate::{SimpleCx, attributes, debuginfo, llvm_util};
17+
use crate::{SimpleCx, attributes, debuginfo};
1718

1819
pub(crate) unsafe fn codegen(
1920
tcx: TyCtxt<'_>,
@@ -149,18 +150,8 @@ fn create_wrapper_function(
149150
ty,
150151
);
151152

152-
let mut attrs = SmallVec::<[_; 2]>::new();
153-
154-
let target_cpu = llvm_util::target_cpu(tcx.sess);
155-
let target_cpu_attr = llvm::CreateAttrStringValue(cx.llcx, "target-cpu", target_cpu);
156-
157-
let tune_cpu_attr = llvm_util::tune_cpu(tcx.sess)
158-
.map(|tune_cpu| llvm::CreateAttrStringValue(cx.llcx, "tune-cpu", tune_cpu));
159-
160-
attrs.push(target_cpu_attr);
161-
attrs.extend(tune_cpu_attr);
162-
163-
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
153+
let attrs = CodegenFnAttrs::new();
154+
llfn_attrs_from_instance(cx, tcx, llfn, &attrs, None);
164155

165156
let no_return = if no_return {
166157
// -> ! DIFlagNoReturn
@@ -171,12 +162,6 @@ fn create_wrapper_function(
171162
None
172163
};
173164

174-
if tcx.sess.must_emit_unwind_tables() {
175-
let uwtable =
176-
attributes::uwtable_attr(cx.llcx, tcx.sess.opts.unstable_opts.use_sync_unwind);
177-
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]);
178-
}
179-
180165
let llbb = unsafe { llvm::LLVMAppendBasicBlockInContext(cx.llcx, llfn, c"entry".as_ptr()) };
181166
let mut bx = SBuilder::build(&cx, llbb);
182167

0 commit comments

Comments
 (0)