Skip to content

Commit beb0304

Browse files
committed
compiler: Apply target features to the entry function
1 parent 51ff895 commit beb0304

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,10 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
483483
// TODO(antoyo)
484484
}
485485

486+
fn apply_target_features(&self, _llfn: Function<'gcc>) {
487+
// TODO(antoyo)
488+
}
489+
486490
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
487491
let entry_name = self.sess().target.entry_name.as_ref();
488492
if !self.functions.borrow().contains_key(entry_name) {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,16 @@ impl<'ll, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
846846
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
847847
}
848848

849+
fn apply_target_features(&self, llfn: &'ll Value) {
850+
let mut attrs = SmallVec::<[_; 2]>::new();
851+
let global_features = self.tcx.global_backend_features(()).iter().map(|s| s.as_str());
852+
let target_features: String = global_features.intersperse(",").collect();
853+
if !target_features.is_empty() {
854+
attrs.push(llvm::CreateAttrStringValue(self.llcx, "target-features", &target_features));
855+
}
856+
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &attrs);
857+
}
858+
849859
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function> {
850860
let entry_name = self.sess().target.entry_name.as_ref();
851861
if self.get_declared_value(entry_name).is_none() {

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
524524
// `main` should respect same config for frame pointer elimination as rest of code
525525
cx.set_frame_pointer_type(llfn);
526526
cx.apply_target_cpu_attr(llfn);
527+
cx.apply_target_features(llfn);
527528

528529
let llbb = Bx::append_block(cx, llfn, "top");
529530
let mut bx = Bx::build(cx, llbb);

compiler/rustc_codegen_ssa/src/traits/misc.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ pub trait MiscCodegenMethods<'tcx>: BackendTypes {
2323
fn sess(&self) -> &Session;
2424
fn set_frame_pointer_type(&self, llfn: Self::Function);
2525
fn apply_target_cpu_attr(&self, llfn: Self::Function);
26+
/// Apply global target features to a given LLVM function.
27+
fn apply_target_features(&self, llfn: Self::Function);
2628
/// Declares the extern "C" main function for the entry point. Returns None if the symbol
2729
/// already exists.
2830
fn declare_c_main(&self, fn_type: Self::Type) -> Option<Self::Function>;

0 commit comments

Comments
 (0)