Skip to content

Commit ce3e200

Browse files
committed
bind LLVMRemoveEnumAttributeAtIndex and remove noinline attribute from function
1 parent b149ed4 commit ce3e200

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ 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 {
31+
pub(crate) fn has_attr(llfn: &Value, idx: AttributePlace, attr: AttributeKind) -> bool {
3232
llvm::HasAttributeAtIndex(llfn, idx, attr)
3333
}
3434

35+
pub(crate) fn remove_from_llfn(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
36+
llvm::RemoveEnumAttributeAtIndex(llfn, place, kind);
37+
}
38+
3539
/// Get LLVM attribute for the provided inline heuristic.
3640
#[inline]
3741
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {

compiler/rustc_codegen_llvm/src/back/lto.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,13 @@ pub(crate) fn run_pass_manager(
677677
// This is not strictly necessary for correctness, but serves as a sanity check
678678
// in case the autodiff pass stops injecting `noinline` in the future.
679679
assert!(
680-
attributes::has_attr(function, llvm::AttributeKind::NoInline, Function),
680+
attributes::has_attr(function, Function, llvm::AttributeKind::NoInline),
681681
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
682682
);
683683

684+
// Removing inline from function.
685+
attributes::remove_from_llfn(function, Function, llvm::AttributeKind::NoInline);
686+
684687
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);
685688
attributes::apply_to_llfn(function, Function, &[attr]);
686689
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ unsafe extern "C" {
11601160

11611161
pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
11621162
pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
1163+
pub(crate) fn LLVMRemoveEnumAttributeAtIndex(Fn: &Value, index: c_uint, kind: c_uint);
11631164

11641165
pub(crate) fn LLVMDeleteGlobal(GlobalVar: &Value);
11651166
pub(crate) fn LLVMGetInitializer(GlobalVar: &Value) -> Option<&Value>;

compiler/rustc_codegen_llvm/src/llvm/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ pub(crate) fn AddFunctionAttributes<'ll>(
4444
pub(crate) fn HasAttributeAtIndex<'ll>(
4545
llfn: &'ll Value,
4646
idx: AttributePlace,
47-
attr: &'ll Attribute,
47+
kind: AttributeKind,
4848
) -> bool {
49-
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx.as_uint(), attrs.as_ptr()) }
49+
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx.as_uint(), kind) }
50+
}
51+
52+
pub(crate) fn RemoveEnumAttributeAtIndex(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
53+
unsafe {
54+
LLVMRemoveEnumAttributeAtIndex(llfn, place.as_uint(), kind as u32);
55+
}
5056
}
5157

5258
pub(crate) fn AddCallSiteAttributes<'ll>(

0 commit comments

Comments
 (0)