Skip to content

Commit 84945fd

Browse files
Add support for passing -Zregparm option to LLVM
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]>
1 parent 7b18b3e commit 84945fd

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,20 @@ pub(crate) unsafe fn create_module<'ll>(
305305
}
306306
}
307307

308+
if let Some(regparm) = sess.opts.cg.regparm {
309+
if sess.target.arch != "x86" && sess.target.arch != "x86_64" {
310+
todo!("regparm is not supported on this target");
311+
}
312+
unsafe {
313+
llvm::LLVMRustAddModuleFlagU32(
314+
llmod,
315+
llvm::LLVMModFlagBehavior::Override,
316+
c"NumRegisterParameters".as_ptr(),
317+
regparm,
318+
);
319+
};
320+
}
321+
308322
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
309323
if sess.target.arch == "aarch64" {
310324
unsafe {

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,8 @@ options! {
15951595
"compile the program with profiling instrumentation"),
15961596
profile_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
15971597
"use the given `.profdata` file for profile-guided optimization"),
1598+
regparm: Option<u32> = (None, parse_opt_number, [UNTRACKED],
1599+
"set the number of registers used for parameter passing"),
15981600
#[rustc_lint_opt_deny_field_access("use `Session::relocation_model` instead of this field")]
15991601
relocation_model: Option<RelocModel> = (None, parse_relocation_model, [TRACKED],
16001602
"control generation of position-independent code (PIC) \

0 commit comments

Comments
 (0)