Skip to content

Commit b149ed4

Browse files
committed
add check for noinline attribute
1 parent d7d617f commit b149ed4

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Diff for: compiler/rustc_codegen_llvm/src/attributes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[
2828
}
2929
}
3030

31+
pub(crate) fn has_attr(llfn: &Value, idx: AttributePlace, attr: &Attribute) -> bool {
32+
llvm::HasAttributeAtIndex(llfn, idx, attr)
33+
}
34+
3135
/// Get LLVM attribute for the provided inline heuristic.
3236
#[inline]
3337
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {

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

+8
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,14 @@ pub(crate) fn run_pass_manager(
673673
let name = std::str::from_utf8(name).unwrap();
674674

675675
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.
679+
assert!(
680+
attributes::has_attr(function, llvm::AttributeKind::NoInline, Function),
681+
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
682+
);
683+
676684
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
677685
attributes::apply_to_llfn(function, Function, &[attr]);
678686
}

Diff for: compiler/rustc_codegen_llvm/src/llvm/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ pub(crate) fn AddFunctionAttributes<'ll>(
4141
}
4242
}
4343

44+
pub(crate) fn HasAttributeAtIndex<'ll>(
45+
llfn: &'ll Value,
46+
idx: AttributePlace,
47+
attr: &'ll Attribute,
48+
) -> bool {
49+
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx.as_uint(), attrs.as_ptr()) }
50+
}
51+
4452
pub(crate) fn AddCallSiteAttributes<'ll>(
4553
callsite: &'ll Value,
4654
idx: AttributePlace,

0 commit comments

Comments
 (0)