rustc_codegen_llvm/llvm/
enzyme_ffi.rs1#![allow(non_camel_case_types)]
2#![expect(dead_code)]
3
4use libc::{c_char, c_uint};
5
6use super::MetadataKindId;
7use super::ffi::{AttributeKind, BasicBlock, Metadata, Module, Type, Value};
8use crate::llvm::Bool;
9
10#[link(name = "llvm-wrapper", kind = "static")]
11unsafe extern "C" {
12 pub(crate) safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool;
14 pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value);
15 pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
16 pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
17 pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
18 pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
19 pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
20 pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
21 pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
22 pub(crate) fn LLVMRustHasFnAttribute(
23 F: &Value,
24 Name: *const c_char,
25 NameLen: libc::size_t,
26 ) -> bool;
27 pub(crate) fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char, NameLen: libc::size_t);
28 pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
29 pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
30 pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex(
31 Fn: &Value,
32 index: c_uint,
33 kind: AttributeKind,
34 );
35}
36
37unsafe extern "C" {
38 pub(crate) fn LLVMDumpModule(M: &Module);
40 pub(crate) fn LLVMDumpValue(V: &Value);
41 pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
42 pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
43 pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
44 pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
45}
46
47#[repr(C)]
48#[derive(Copy, Clone, PartialEq)]
49pub(crate) enum LLVMRustVerifierFailureAction {
50 LLVMAbortProcessAction = 0,
51 LLVMPrintMessageAction = 1,
52 LLVMReturnStatusAction = 2,
53}
54
55#[cfg(llvm_enzyme)]
56pub(crate) use self::Enzyme_AD::*;
57
58#[cfg(llvm_enzyme)]
59pub(crate) mod Enzyme_AD {
60 use libc::c_void;
61 unsafe extern "C" {
62 pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
63 }
64 unsafe extern "C" {
65 static mut EnzymePrintPerf: c_void;
66 static mut EnzymePrintActivity: c_void;
67 static mut EnzymePrintType: c_void;
68 static mut EnzymePrint: c_void;
69 static mut EnzymeStrictAliasing: c_void;
70 static mut looseTypeAnalysis: c_void;
71 static mut EnzymeInline: c_void;
72 static mut RustTypeRules: c_void;
73 }
74 pub(crate) fn set_print_perf(print: bool) {
75 unsafe {
76 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8);
77 }
78 }
79 pub(crate) fn set_print_activity(print: bool) {
80 unsafe {
81 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8);
82 }
83 }
84 pub(crate) fn set_print_type(print: bool) {
85 unsafe {
86 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
87 }
88 }
89 pub(crate) fn set_print(print: bool) {
90 unsafe {
91 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8);
92 }
93 }
94 pub(crate) fn set_strict_aliasing(strict: bool) {
95 unsafe {
96 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8);
97 }
98 }
99 pub(crate) fn set_loose_types(loose: bool) {
100 unsafe {
101 EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8);
102 }
103 }
104 pub(crate) fn set_inline(val: bool) {
105 unsafe {
106 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8);
107 }
108 }
109 pub(crate) fn set_rust_rules(val: bool) {
110 unsafe {
111 EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8);
112 }
113 }
114}
115
116#[cfg(not(llvm_enzyme))]
117pub(crate) use self::Fallback_AD::*;
118
119#[cfg(not(llvm_enzyme))]
120pub(crate) mod Fallback_AD {
121 #![allow(unused_variables)]
122
123 pub(crate) fn set_inline(val: bool) {
124 unimplemented!()
125 }
126 pub(crate) fn set_print_perf(print: bool) {
127 unimplemented!()
128 }
129 pub(crate) fn set_print_activity(print: bool) {
130 unimplemented!()
131 }
132 pub(crate) fn set_print_type(print: bool) {
133 unimplemented!()
134 }
135 pub(crate) fn set_print(print: bool) {
136 unimplemented!()
137 }
138 pub(crate) fn set_strict_aliasing(strict: bool) {
139 unimplemented!()
140 }
141 pub(crate) fn set_loose_types(loose: bool) {
142 unimplemented!()
143 }
144 pub(crate) fn set_rust_rules(val: bool) {
145 unimplemented!()
146 }
147}