Skip to content

Commit 9720be6

Browse files
committed
adressing more feedback
1 parent 437202b commit 9720be6

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ fn generate_enzyme_call<'ll, 'tcx>(
267267
}
268268

269269
// Let's crash in case that we messed something up above and generated invalid IR.
270-
llvm::LLVMVerifyFunction(outer_fn, llvm::LLVMVerifierFailureAction::LLVMAbortProcessAction);
270+
llvm::LLVMRustVerifyFunction(
271+
outer_fn,
272+
llvm::LLVMRustVerifierFailureAction::LLVMAbortProcessAction,
273+
);
271274
}
272275
}
273276

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
use libc::{c_char, c_uint};
44

5-
use super::Bool;
6-
use super::ffi::{Attribute, BasicBlock, Metadata, Module, Type, Value};
5+
use super::ffi::{BasicBlock, Metadata, Module, Type, Value};
76
extern "C" {
87
// Enzyme
98
pub fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool;
@@ -12,21 +11,18 @@ extern "C" {
1211
pub fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
1312
pub fn LLVMRustEraseInstFromParent(V: &Value);
1413
pub fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
14+
pub fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> bool;
1515

1616
pub fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
1717
pub fn LLVMGetReturnType(T: &Type) -> &Type;
18-
pub fn LLVMDumpModule(M: &Module);
19-
pub fn LLVMCountStructElementTypes(T: &Type) -> c_uint;
20-
pub fn LLVMVerifyFunction(V: &Value, action: LLVMVerifierFailureAction) -> Bool;
2118
pub fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
2219
pub fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
23-
pub fn LLVMIsEnumAttribute(A: &Attribute) -> Bool;
24-
pub fn LLVMIsStringAttribute(A: &Attribute) -> Bool;
2520
}
2621

2722
#[repr(C)]
28-
pub enum LLVMVerifierFailureAction {
29-
LLVMAbortProcessAction,
30-
LLVMPrintMessageAction,
31-
LLVMReturnStatusAction,
23+
#[derive(Copy, Clone, PartialEq)]
24+
pub enum LLVMRustVerifierFailureAction {
25+
LLVMAbortProcessAction = 0,
26+
LLVMPrintMessageAction = 1,
27+
LLVMReturnStatusAction = 2,
3228
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "LLVMWrapper.h"
22

33
#include "llvm-c/Core.h"
4+
#include "llvm-c/Analysis.h"
45
#include "llvm/ADT/ArrayRef.h"
56
#include "llvm/ADT/SmallVector.h"
67
#include "llvm/ADT/Statistic.h"
@@ -165,6 +166,31 @@ extern "C" LLVMValueRef LLVMRustGetNamedValue(LLVMModuleRef M, const char *Name,
165166
return wrap(unwrap(M)->getNamedValue(StringRef(Name, NameLen)));
166167
}
167168

169+
enum class LLVMRustVerifierFailureAction {
170+
AbortProcessAction = 0,
171+
PrintMessageAction = 1,
172+
ReturnStatusAction = 2,
173+
};
174+
175+
static LLVMVerifierFailureAction fromRust(LLVMRustVerifierFailureAction Action) {
176+
switch (Action) {
177+
case LLVMRustVerifierFailureAction::AbortProcessAction:
178+
return LLVMAbortProcessAction;
179+
case LLVMRustVerifierFailureAction::PrintMessageAction:
180+
return LLVMPrintMessageAction;
181+
case LLVMRustVerifierFailureAction::ReturnStatusAction:
182+
return LLVMReturnStatusAction;
183+
}
184+
report_fatal_error("Invalid LLVMVerifierFailureAction value!");
185+
}
186+
187+
// pub fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
188+
extern "C" bool LLVMRustVerifyFunction(LLVMValueRef Fn,
189+
LLVMRustVerifierFailureAction Action) {
190+
//Function *F = unwrap<Function>(Fn);
191+
return LLVMVerifyFunction(Fn, fromRust(Action));
192+
}
193+
168194
enum class LLVMRustTailCallKind {
169195
None,
170196
Tail,

0 commit comments

Comments
 (0)