Skip to content

Commit f319dd9

Browse files
committed
add llvm wrappers and corresponding methods in attribute
1 parent 847e3ee commit f319dd9

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ 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: AttributeKind) -> bool {
32+
llvm::HasAttributeAtIndex(llfn, idx, attr)
33+
}
34+
35+
pub(crate) fn has_string_attr(llfn: &Value, name: *const i8) -> bool {
36+
llvm::HasStringAttribute(llfn, name)
37+
}
38+
39+
pub(crate) fn remove_from_llfn(llfn: &Value, place: AttributePlace, kind: AttributeKind) {
40+
llvm::RemoveRustEnumAttributeAtIndex(llfn, place, kind);
41+
}
42+
43+
pub(crate) fn remove_string_attr_from_llfn(llfn: &Value, name: *const i8) {
44+
llvm::RemoveStringAttrFromFn(llfn, name);
45+
}
46+
3147
/// Get LLVM attribute for the provided inline heuristic.
3248
#[inline]
3349
fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll Attribute> {

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ unsafe extern "C" {
1919
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
2020
pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
2121
pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
22+
pub(crate) fn LLVMRustHasFnAttribute(F: &Value, Name: *const c_char) -> bool;
23+
pub(crate) fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char);
24+
pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
25+
pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
26+
pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex(
27+
Fn: &Value,
28+
index: c_uint,
29+
kind: AttributeKind,
30+
);
2231
}
2332

2433
unsafe extern "C" {

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

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

976+
extern "C" void
977+
LLVMRustRemoveEnumAttributeAtIndex(LLVMValueRef F, size_t index,
978+
LLVMRustAttributeKind RustAttr) {
979+
LLVMRemoveEnumAttributeAtIndex(F, index, fromRust(RustAttr));
980+
}
981+
982+
extern "C" bool LLVMRustHasFnAttribute(LLVMValueRef F, const char *Name) {
983+
if (auto *Fn = dyn_cast<Function>(unwrap<Value>(F))) {
984+
return Fn->hasFnAttribute(Name);
985+
}
986+
return false;
987+
}
988+
989+
extern "C" void LLVMRustRemoveFnAttribute(LLVMValueRef Fn, const char *Name) {
990+
if (auto *F = dyn_cast<Function>(unwrap<Value>(Fn))) {
991+
F->removeFnAttr(Name);
992+
}
993+
}
994+
976995
extern "C" void LLVMRustGlobalAddMetadata(LLVMValueRef Global, unsigned Kind,
977996
LLVMMetadataRef MD) {
978997
unwrap<GlobalObject>(Global)->addMetadata(Kind, *unwrap<MDNode>(MD));

0 commit comments

Comments
 (0)