Annotate functions in LLVM with target-cpu, same as Clang does.
This commit is contained in:
parent
f2969ed6c3
commit
b27a161939
4 changed files with 50 additions and 0 deletions
|
@ -123,6 +123,15 @@ pub fn llvm_target_features(sess: &Session) -> impl Iterator<Item = &str> {
|
|||
.filter(|l| !l.is_empty())
|
||||
}
|
||||
|
||||
pub fn apply_target_cpu_attr(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
|
||||
let target_cpu = CString::new(cx.tcx.sess.target_cpu().to_string()).unwrap();
|
||||
llvm::AddFunctionAttrStringValue(
|
||||
llfn,
|
||||
llvm::AttributePlace::Function,
|
||||
cstr("target-cpu\0"),
|
||||
target_cpu.as_c_str());
|
||||
}
|
||||
|
||||
/// Composite function which sets LLVM attributes for function depending on its AST (#[attribute])
|
||||
/// attributes.
|
||||
pub fn from_fn_attrs(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value, id: DefId) {
|
||||
|
@ -167,6 +176,15 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value, id: DefId) {
|
|||
Some(true) | None => {}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
let features = llvm_target_features(cx.tcx.sess)
|
||||
.map(|s| s.to_string())
|
||||
.chain(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue