Skip to content

Commit 9caef13

Browse files
committed
improve inline addition logic
1 parent e5d4ac8 commit 9caef13

File tree

1 file changed

+13
-10
lines changed
  • compiler/rustc_codegen_llvm/src/back

1 file changed

+13
-10
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::errors::{
2929
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib, LtoProcMacro,
3030
};
3131
use crate::llvm::AttributePlace::Function;
32-
use crate::llvm::{self, build_string, get_value_name};
32+
use crate::llvm::{self, build_string};
3333
use crate::{LlvmCodegenBackend, ModuleLlvm, SimpleCx, attributes};
3434

3535
/// We keep track of the computed LTO cache keys from the previous
@@ -669,23 +669,26 @@ pub(crate) fn run_pass_manager(
669669
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
670670

671671
for function in cx.get_functions() {
672-
let name = get_value_name(function);
673-
let name = std::str::from_utf8(name).unwrap();
672+
let enzyme_marker = CString::new("enzyme_marker").unwrap();
673+
let marker_ptr = enzyme_marker.as_ptr();
674674

675-
if name.starts_with("__enzyme") {
676-
// Ensure `noinline` is present before replacing it.
677-
// This is not strictly necessary for correctness, but serves as a sanity check
678-
// in case the autodiff pass stops injecting `noinline` in the future.
675+
if attributes::has_string_attr(function, marker_ptr) {
676+
// Sanity check: Ensure 'noinline' is present before replacing it.
679677
assert!(
680678
!attributes::has_attr(function, Function, llvm::AttributeKind::NoInline),
681679
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
682680
);
683681

684-
// Removing inline from function.
685682
attributes::remove_from_llfn(function, Function, llvm::AttributeKind::NoInline);
683+
attributes::remove_string_attr_from_llfn(function, marker_ptr);
686684

687-
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
688-
attributes::apply_to_llfn(function, Function, &[attr]);
685+
assert!(
686+
!attributes::has_string_attr(function, marker_ptr),
687+
"Expected function to not have 'enzyme_marker'"
688+
);
689+
690+
let always_inline = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
691+
attributes::apply_to_llfn(function, Function, &[always_inline]);
689692
}
690693
}
691694

0 commit comments

Comments
 (0)