Skip to content

Commit 116c948

Browse files
committed
remove noline and add always inline
1 parent 4a1b3b1 commit 116c948

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ pub(crate) fn apply_to_callsite(callsite: &Value, idx: AttributePlace, attrs: &[
2828
}
2929
}
3030

31-
pub(crate) fn has_attr(llfn: &Value, idx: u32, attr: AttributeKind) -> bool {
31+
pub(crate) fn has_attr(llfn: &Value, idx: AttributePlace, attr: AttributeKind) -> bool {
3232
llvm::HasAttributeAtIndex(llfn, idx, attr)
3333
}
3434

3535
pub(crate) fn remove_from_llfn(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
36-
llvm::RemoveEnumAttributeAtIndex(llfn, place, kind);
36+
llvm::RemoveRustEnumAttributeAtIndex(llfn, place, kind);
3737
}
3838

3939
/// Get LLVM attribute for the provided inline heuristic.

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,11 @@ 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, 0, llvm::AttributeKind::NoInline),
680+
!attributes::has_attr(function, Function, llvm::AttributeKind::NoInline),
681681
"Expected __enzyme function to have 'noinline' before adding 'alwaysinline'"
682682
);
683683

684-
// Removing no-inline from function.
684+
// Removing inline from function.
685685
attributes::remove_from_llfn(function, Function, llvm::AttributeKind::NoInline);
686686

687687
let attr = llvm::AttributeKind::AlwaysInline.create_attr(cx.llcx);

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +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);
1163+
pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex(Fn: &Value, index: c_uint, kind: AttributeKind);
11641164

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

compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ pub(crate) fn AddFunctionAttributes<'ll>(
4141
}
4242
}
4343

44-
pub(crate) fn HasAttributeAtIndex<'ll>(llfn: &'ll Value, idx: u32, kind: AttributeKind) -> bool {
45-
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx, kind) }
44+
pub(crate) fn HasAttributeAtIndex<'ll>(llfn: &'ll Value, idx: AttributePlace, kind: AttributeKind) -> bool {
45+
unsafe { LLVMRustHasAttributeAtIndex(llfn, idx.as_uint(), kind) }
4646
}
4747

48-
pub(crate) fn RemoveEnumAttributeAtIndex(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
48+
pub(crate) fn RemoveRustEnumAttributeAtIndex(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
4949
unsafe {
50-
LLVMRemoveEnumAttributeAtIndex(llfn, place.as_uint(), kind);
50+
LLVMRustRemoveEnumAttributeAtIndex(llfn, place.as_uint(), kind);
5151
}
5252
}
5353

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,12 @@ extern "C" LLVMMetadataRef LLVMRustDIGetInstMetadata(LLVMValueRef x) {
973973
return nullptr;
974974
}
975975

976+
977+
extern "C" void LLVMRustRemoveEnumAttributeAtIndex(LLVMValueRef F, size_t index,
978+
LLVMRustAttributeKind RustAttr) {
979+
LLVMRemoveEnumAttributeAtIndex(F, index, fromRust(RustAttr));
980+
}
981+
976982
extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind,
977983
LLVMMetadataRef MD) {
978984
unwrap<GlobalObject>(Global)->addMetadata(Kind, *unwrap<MDNode>(MD));

tests/codegen/autodiff/inline.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Zautodiff=Enable -Zautodiff=NoPostopt -C opt-level=3 -Clto=fat
1+
//@ compile-flags: -Zautodiff=Enable -C opt-level=3 -Clto=fat -Zautodiff=NoPostopt
22
//@ no-prefer-dynamic
33
//@ needs-enzyme
44

@@ -10,11 +10,15 @@ use std::autodiff::autodiff;
1010
fn square(x: &f64) -> f64 {
1111
x * x
1212
}
13-
// CHECK: ; Function Attrs: alwaysinline noinline
14-
// CHECK-NEXT: declare double @__enzyme_autodiff_ZN6inline8d_square17h021c74e92c259cdeE(...) local_unnamed_addr #8
13+
14+
15+
// CHECK: ; inline::d_square
16+
// CHECK-NEXT: ; Function Attrs: alwaysinline
17+
// CHECK-NOT: noinline
18+
// CHECK-NEXT: define internal fastcc void @_ZN6inline8d_square17h021c74e92c259cdeE
1519
fn main() {
1620
let x = std::hint::black_box(3.0);
1721
let mut dx1 = std::hint::black_box(1.0);
1822
let _ = d_square(&x, &mut dx1, 1.0);
1923
assert_eq!(dx1, 6.0);
20-
}
24+
}

0 commit comments

Comments
 (0)