Files
rust/compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

144 lines
4.7 KiB
Rust
Raw Normal View History

#![allow(non_camel_case_types)]
#![expect(dead_code)]
use libc::{c_char, c_uint};
2025-02-24 14:38:55 +00:00
use super::MetadataKindId;
2025-04-04 14:24:23 -04:00
use super::ffi::{AttributeKind, BasicBlock, Metadata, Module, Type, Value};
use crate::llvm::Bool;
2025-01-31 21:11:23 -05:00
#[link(name = "llvm-wrapper", kind = "static")]
unsafe extern "C" {
// Enzyme
2025-02-24 14:38:55 +00:00
pub(crate) safe fn LLVMRustHasMetadata(I: &Value, KindID: MetadataKindId) -> bool;
pub(crate) fn LLVMRustEraseInstUntilInclusive(BB: &BasicBlock, I: &Value);
pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
2025-04-04 14:24:23 -04:00
pub(crate) fn LLVMRustHasAttributeAtIndex(V: &Value, i: c_uint, Kind: AttributeKind) -> bool;
pub(crate) fn LLVMRustGetArrayNumElements(Ty: &Type) -> u64;
pub(crate) fn LLVMRustHasFnAttribute(F: &Value, Name: *const c_char) -> bool;
pub(crate) fn LLVMRustRemoveFnAttribute(F: &Value, Name: *const c_char);
pub(crate) fn LLVMGetFirstFunction(M: &Module) -> Option<&Value>;
pub(crate) fn LLVMGetNextFunction(Fn: &Value) -> Option<&Value>;
pub(crate) fn LLVMRustRemoveEnumAttributeAtIndex(
Fn: &Value,
index: c_uint,
kind: AttributeKind,
);
2025-01-31 21:11:23 -05:00
}
unsafe extern "C" {
2025-01-31 21:11:23 -05:00
// Enzyme
pub(crate) fn LLVMDumpModule(M: &Module);
pub(crate) fn LLVMDumpValue(V: &Value);
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
}
#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub(crate) enum LLVMRustVerifierFailureAction {
LLVMAbortProcessAction = 0,
LLVMPrintMessageAction = 1,
LLVMReturnStatusAction = 2,
}
2025-02-21 21:51:20 -05:00
#[cfg(llvm_enzyme)]
pub(crate) use self::Enzyme_AD::*;
2025-02-21 21:51:20 -05:00
#[cfg(llvm_enzyme)]
pub(crate) mod Enzyme_AD {
2025-02-21 21:51:20 -05:00
use libc::c_void;
2025-02-25 17:25:50 +05:30
unsafe extern "C" {
pub(crate) fn EnzymeSetCLBool(arg1: *mut ::std::os::raw::c_void, arg2: u8);
2025-02-21 21:51:20 -05:00
}
2025-02-25 17:25:50 +05:30
unsafe extern "C" {
2025-02-21 21:51:20 -05:00
static mut EnzymePrintPerf: c_void;
static mut EnzymePrintActivity: c_void;
static mut EnzymePrintType: c_void;
static mut EnzymePrint: c_void;
static mut EnzymeStrictAliasing: c_void;
static mut looseTypeAnalysis: c_void;
static mut EnzymeInline: c_void;
static mut RustTypeRules: c_void;
}
pub(crate) fn set_print_perf(print: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintPerf), print as u8);
}
}
pub(crate) fn set_print_activity(print: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintActivity), print as u8);
}
}
pub(crate) fn set_print_type(print: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrintType), print as u8);
}
}
pub(crate) fn set_print(print: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymePrint), print as u8);
}
}
pub(crate) fn set_strict_aliasing(strict: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeStrictAliasing), strict as u8);
}
}
pub(crate) fn set_loose_types(loose: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), loose as u8);
}
}
pub(crate) fn set_inline(val: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), val as u8);
}
}
pub(crate) fn set_rust_rules(val: bool) {
2025-02-21 21:51:20 -05:00
unsafe {
EnzymeSetCLBool(std::ptr::addr_of_mut!(RustTypeRules), val as u8);
}
}
}
#[cfg(not(llvm_enzyme))]
pub(crate) use self::Fallback_AD::*;
2025-02-21 21:51:20 -05:00
#[cfg(not(llvm_enzyme))]
pub(crate) mod Fallback_AD {
2025-02-21 21:51:20 -05:00
#![allow(unused_variables)]
pub(crate) fn set_inline(val: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_print_perf(print: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_print_activity(print: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_print_type(print: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_print(print: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_strict_aliasing(strict: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_loose_types(loose: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
pub(crate) fn set_rust_rules(val: bool) {
2025-02-21 21:51:20 -05:00
unimplemented!()
}
}