Add a target option "merge-functions" taking values in ("disabled",
"trampolines", or "aliases (the default)) to allow targets to opt out of the MergeFunctions LLVM pass. Also add a corresponding -Z option with the same name and values. This works around: https://github.com/rust-lang/rust/issues/57356 Motivation: Basically, the problem is that the MergeFunctions pass, which rustc currently enables by default at -O2 and -O3, and `extern "ptx-kernel"` functions (specific to the NVPTX target) are currently not compatible with each other. If the MergeFunctions pass is allowed to run, rustc can generate invalid PTX assembly (i.e. a PTX file that is not accepted by the native PTX assembler ptxas). Therefore we would like a way to opt out of the MergeFunctions pass, which is what our target option does. Related work: The current behavior of rustc is to enable MergeFunctions at -O2 and -O3, and also to enable the use of function aliases within MergeFunctions. MergeFunctions both with and without function aliases is incompatible with the NVPTX target. clang's "solution" is to have a "-fmerge-functions" flag that opts in to the MergeFunctions pass, but it is not enabled by default.
This commit is contained in:
parent
2442823ef5
commit
b91d211b40
4 changed files with 117 additions and 8 deletions
|
@ -3,6 +3,7 @@ use back::write::create_target_machine;
|
|||
use llvm;
|
||||
use rustc::session::Session;
|
||||
use rustc::session::config::PrintRequest;
|
||||
use rustc_target::spec::MergeFunctions;
|
||||
use libc::c_int;
|
||||
use std::ffi::CString;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
|
@ -61,7 +62,14 @@ unsafe fn configure_llvm(sess: &Session) {
|
|||
add("-disable-preinline");
|
||||
}
|
||||
if llvm::LLVMRustIsRustLLVM() {
|
||||
add("-mergefunc-use-aliases");
|
||||
match sess.opts.debugging_opts.merge_functions
|
||||
.unwrap_or(sess.target.target.options.merge_functions) {
|
||||
MergeFunctions::Disabled |
|
||||
MergeFunctions::Trampolines => {}
|
||||
MergeFunctions::Aliases => {
|
||||
add("-mergefunc-use-aliases");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// HACK(eddyb) LLVM inserts `llvm.assume` calls to preserve align attributes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue