Skip to content

Commit 5fddbe3

Browse files
committed
Add explicit inlining to methods after AD layer
1 parent d7a7d01 commit 5fddbe3

File tree

1 file changed

+17
-1
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+17
-1
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::back::write::{
2828
use crate::errors::{
2929
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
3030
};
31-
use crate::llvm::{self, build_string};
31+
use crate::llvm::{self, LLVMCreateStringAttribute, build_string};
3232
use crate::{LlvmCodegenBackend, ModuleLlvm};
3333

3434
/// We keep track of the computed LTO cache keys from the previous
@@ -657,6 +657,22 @@ pub(crate) fn run_pass_manager(
657657
}
658658

659659
if cfg!(llvm_enzyme) && enable_ad {
660+
let llmod = module.module_llvm.llmod();
661+
662+
for function in llvm::get_functions(llmod) {
663+
let attr_name = CString::new("alwaysinline").unwrap();
664+
unsafe {
665+
let attr = LLVMCreateStringAttribute(
666+
llvm::LLVMGetModuleContext(llmod),
667+
attr_name.as_ptr(),
668+
attr_name.as_bytes().len() as u32,
669+
std::ptr::null(),
670+
0,
671+
);
672+
llvm::LLVMAddAttributeAtIndex(function, llvm::LLVMAttributeFunctionIndex, attr);
673+
}
674+
}
675+
660676
let opt_stage = llvm::OptStage::FatLTO;
661677
let stage = write::AutodiffStage::PostAD;
662678
unsafe {

0 commit comments

Comments
 (0)