Skip to content

Commit 4a1b3b1

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

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
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: u32, 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, 0, llvm::AttributeKind::NoInline),
681681
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
682682
);
683683

684+
// Removing no-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: AttributeKind);
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-6
Original file line numberDiff line numberDiff line change
@@ -41,12 +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()) }
44+
pub(crate) fn HasAttributeAtIndex<'ll>(llfn: &'ll Value, idx: u32, kind: AttributeKind) -> bool {
45+
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx, kind) }
46+
}
47+
48+
pub(crate) fn RemoveEnumAttributeAtIndex(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
49+
unsafe {
50+
LLVMRemoveEnumAttributeAtIndex(llfn, place.as_uint(), kind);
51+
}
5052
}
5153

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

0 commit comments

Comments
 (0)