diff options
| author | kennytm <kennytm@gmail.com> | 2018-12-14 22:10:04 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-12-14 22:10:04 +0800 |
| commit | 4f0f1102bfa20352b8afdb39ece2a3823bb0cae9 (patch) | |
| tree | 5514a9dc644ed68666987eaac38ba69ba0177262 | |
| parent | f4b07e0713b2d82417968db08cd0575734cdac0d (diff) | |
| parent | 86822eb9404382eb82404a2c7b9193980fdd5296 (diff) | |
| download | rust-4f0f1102bfa20352b8afdb39ece2a3823bb0cae9.tar.gz rust-4f0f1102bfa20352b8afdb39ece2a3823bb0cae9.zip | |
Rollup merge of #56609 - michaelwoerister:unconditional-target-cpu-attr, r=alexcrichton
Unconditionally emit the target-cpu LLVM attribute. This PR makes `rustc` always emit the `target-cpu` LLVM attribute for functions. The goal is to allow for cross-language inlining of functions defined in `libstd`. So far `libstd` functions were the only function without a `target-cpu` attribute, so in whole-crate-graph cross-lang LTO scenarios they were not eligible for inlining into foreign code. r? @alexcrichton
| -rw-r--r-- | src/librustc_codegen_llvm/attributes.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 30edc4744ec..48e0a3a12c9 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -18,6 +18,7 @@ use rustc::session::config::Sanitizer; use rustc::ty::{self, TyCtxt, PolyFnSig}; use rustc::ty::layout::HasTyCtxt; use rustc::ty::query::Providers; +use rustc_data_structures::small_c_str::SmallCStr; use rustc_data_structures::sync::Lrc; use rustc_data_structures::fx::FxHashMap; use rustc_target::spec::PanicStrategy; @@ -130,8 +131,7 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> { } pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { - let cpu = llvm_util::target_cpu(cx.tcx.sess); - let target_cpu = CString::new(cpu).unwrap(); + let target_cpu = SmallCStr::new(llvm_util::target_cpu(cx.tcx.sess)); llvm::AddFunctionAttrStringValue( llfn, llvm::AttributePlace::Function, @@ -231,11 +231,7 @@ pub fn from_fn_attrs( // Always annotate functions with the target-cpu they are compiled for. // Without this, ThinLTO won't inline Rust functions into Clang generated // functions (because Clang annotates functions this way too). - // NOTE: For now we just apply this if -Zcross-lang-lto is specified, since - // it introduce a little overhead and isn't really necessary otherwise. - if cx.tcx.sess.opts.debugging_opts.cross_lang_lto.enabled() { - apply_target_cpu_attr(cx, llfn); - } + apply_target_cpu_attr(cx, llfn); let features = llvm_target_features(cx.tcx.sess) .map(|s| s.to_string()) |
