Skip to content

Commit

Permalink
Add support for passing -Zregparm option to LLVM
Browse files Browse the repository at this point in the history
introducing a new command-line option `-Zregparm` to `rustc`, and
modify the code generation phase to pass the `regparm` value to LLVM.

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Sep 8, 2024
1 parent 7b18b3e commit 84945fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,20 @@ pub(crate) unsafe fn create_module<'ll>(
}
}

if let Some(regparm) = sess.opts.cg.regparm {
if sess.target.arch != "x86" && sess.target.arch != "x86_64" {
todo!("regparm is not supported on this target");
}
unsafe {
llvm::LLVMRustAddModuleFlagU32(
llmod,
llvm::LLVMModFlagBehavior::Override,
c"NumRegisterParameters".as_ptr(),
regparm,
);
};
}

if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
if sess.target.arch == "aarch64" {
unsafe {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ options! {
"compile the program with profiling instrumentation"),
profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
"use the given `.profdata` file for profile-guided optimization"),
regparm: Option<u32> = (None, parse_opt_number, [UNTRACKED],
"set the number of registers used for parameter passing"),
#[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")]
relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
"control generation of position-independent code (PIC) \
Expand Down

0 comments on commit 84945fd

Please sign in to comment.