rustc_codegen_llvm/llvm/
enzyme_ffi.rs
1#![allow(non_camel_case_types)]
2#![expect(dead_code)]
3
4use libc::{c_char, c_uint};
5
6use super::MetadataKindId;
7use super::ffi::{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}
21
22unsafe extern "C" {
23 pub(crate) fn LLVMDumpModule(M: &Module);
25 pub(crate) fn LLVMDumpValue(V: &Value);
26 pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
27 pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
28 pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
29 pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
30}
31
32#[repr(C)]
33#[derive(Copy, Clone, PartialEq)]
34pub(crate) enum LLVMRustVerifierFailureAction {
35 LLVMAbortProcessAction = 0,
36 LLVMPrintMessageAction = 1,
37 LLVMReturnStatusAction = 2,
38}
39
40#[cfg(llvm_enzyme)]
41pub(crate) use self::Enzyme_AD::*;
42
43#[cfg(llvm_enzyme)]
44pub(crate) mod Enzyme_AD {
45 use libc::c_void;
46 unsafe extern "C" {
47 pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
48 }
49 unsafe extern "C" {
50 static mut EnzymePrintPerf: c_void;
51 static mut EnzymePrintActivity: c_void;
52 static mut EnzymePrintType: c_void;
53 static mut EnzymePrint: c_void;
54 static mut EnzymeStrictAliasing: c_void;
55 static mut looseTypeAnalysis: c_void;
56 static mut EnzymeInline: c_void;
57 static mut RustTypeRules: c_void;
58 }
59 pub(crate) fn set_print_perf(print: bool) {
60 unsafe {
61 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8);
62 }
63 }
64 pub(crate) fn set_print_activity(print: bool) {
65 unsafe {
66 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8);
67 }
68 }
69 pub(crate) fn set_print_type(print: bool) {
70 unsafe {
71 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
72 }
73 }
74 pub(crate) fn set_print(print: bool) {
75 unsafe {
76 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8);
77 }
78 }
79 pub(crate) fn set_strict_aliasing(strict: bool) {
80 unsafe {
81 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8);
82 }
83 }
84 pub(crate) fn set_loose_types(loose: bool) {
85 unsafe {
86 EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8);
87 }
88 }
89 pub(crate) fn set_inline(val: bool) {
90 unsafe {
91 EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8);
92 }
93 }
94 pub(crate) fn set_rust_rules(val: bool) {
95 unsafe {
96 EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8);
97 }
98 }
99}
100
101#[cfg(not(llvm_enzyme))]
102pub(crate) use self::Fallback_AD::*;
103
104#[cfg(not(llvm_enzyme))]
105pub(crate) mod Fallback_AD {
106 #![allow(unused_variables)]
107
108 pub(crate) fn set_inline(val: bool) {
109 unimplemented!()
110 }
111 pub(crate) fn set_print_perf(print: bool) {
112 unimplemented!()
113 }
114 pub(crate) fn set_print_activity(print: bool) {
115 unimplemented!()
116 }
117 pub(crate) fn set_print_type(print: bool) {
118 unimplemented!()
119 }
120 pub(crate) fn set_print(print: bool) {
121 unimplemented!()
122 }
123 pub(crate) fn set_strict_aliasing(strict: bool) {
124 unimplemented!()
125 }
126 pub(crate) fn set_loose_types(loose: bool) {
127 unimplemented!()
128 }
129 pub(crate) fn set_rust_rules(val: bool) {
130 unimplemented!()
131 }
132}