Skip to content

Commit 530b565

Browse files
committed
Add explicit inlining to methods after AD layer
1 parent 0af8474 commit 530b565

File tree

1 file changed

+16
-2
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+16
-2
lines changed

Diff for: compiler/rustc_codegen_llvm/src/back/lto.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ use crate::back::write::{
2828
use crate::errors::{
2929
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
3030
};
31-
use crate::llvm::{self, build_string};
32-
use crate::{LlvmCodegenBackend, ModuleLlvm};
31+
use crate::llvm::AttributePlace::Function;
32+
use crate::llvm::{self, build_string, get_value_name};
33+
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, attributes};
3334

3435
/// We keep track of the computed LTO cache keys from the previous
3536
/// session to determine which CGUs we can reuse.
@@ -664,6 +665,19 @@ pub(crate) fn run_pass_manager(
664665
unsafe { llvm::LLVMDumpModule(module.module_llvm.llmod()) };
665666
}
666667

668+
let cx =
669+
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
670+
671+
for function in cx.get_functions() {
672+
let name = get_value_name(function);
673+
let name = std::str::from_utf8(name).unwrap();
674+
675+
if name.starts_with("__enzyme") {
676+
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
677+
attributes::apply_to_llfn(function, Function, &[attr]);
678+
}
679+
}
680+
667681
let opt_stage = llvm::OptStage::FatLTO;
668682
let stage = write::AutodiffStage::PostAD;
669683
unsafe {

0 commit comments

Comments
 (0)