Skip to content

Commit 0acbf65

Browse files
committed
Clean llvm wrapper
1 parent 2ae9916 commit 0acbf65

File tree

12 files changed

+631
-618
lines changed

12 files changed

+631
-618
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ unsafe impl Send for ModuleBuffer {}
622622
unsafe impl Sync for ModuleBuffer {}
623623

624624
impl ModuleBuffer {
625-
pub fn new(m: &llvm::Module) -> ModuleBuffer {
625+
pub(crate) fn new(m: &llvm::Module) -> ModuleBuffer {
626626
ModuleBuffer(unsafe { llvm::LLVMRustModuleBufferCreate(m) })
627627
}
628628
}
@@ -664,7 +664,7 @@ unsafe impl Send for ThinBuffer {}
664664
unsafe impl Sync for ThinBuffer {}
665665

666666
impl ThinBuffer {
667-
pub fn new(m: &llvm::Module, is_thin: bool, emit_summary: bool) -> ThinBuffer {
667+
pub(crate) fn new(m: &llvm::Module, is_thin: bool, emit_summary: bool) -> ThinBuffer {
668668
unsafe {
669669
let buffer = llvm::LLVMRustThinLTOBufferCreate(m, is_thin, emit_summary);
670670
ThinBuffer(buffer)

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct OwnedTargetMachine {
1717
}
1818

1919
impl OwnedTargetMachine {
20-
pub fn new(
20+
pub(crate) fn new(
2121
triple: &CStr,
2222
cpu: &CStr,
2323
features: &CStr,

compiler/rustc_codegen_llvm/src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
493493
.expect("non-UTF8 diagnostic");
494494
dcx.emit_err(FromLlvmDiag { message });
495495
}
496-
llvm::diagnostic::UnknownDiagnostic(..) => {}
496+
llvm::diagnostic::UnknownDiagnostic => {}
497497
}
498498
}
499499

compiler/rustc_codegen_llvm/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use std::mem::ManuallyDrop;
2929
use back::owned_target_machine::OwnedTargetMachine;
3030
use back::write::{create_informational_target_machine, create_target_machine};
3131
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
32-
pub use llvm_util::target_features_cfg;
32+
pub(crate) use llvm_util::target_features_cfg;
3333
use rustc_ast::expand::allocator::AllocatorKind;
3434
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
3535
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
@@ -75,8 +75,8 @@ mod intrinsic;
7575
// The following is a workaround that replaces `pub mod llvm;` and that fixes issue 53912.
7676
#[path = "llvm/mod.rs"]
7777
mod llvm_;
78-
pub mod llvm {
79-
pub use super::llvm_::*;
78+
pub(crate) mod llvm {
79+
pub(crate) use super::llvm_::*;
8080
}
8181

8282
mod llvm_util;

compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ use std::{slice, str};
55

66
use rustc_fs_util::path_to_c_string;
77

8-
pub struct ArchiveRO {
8+
pub(crate) struct ArchiveRO {
99
pub raw: &'static mut super::Archive,
1010
}
1111

1212
unsafe impl Send for ArchiveRO {}
1313

14-
pub struct Iter<'a> {
14+
pub(crate) struct Iter<'a> {
1515
raw: &'a mut super::ArchiveIterator<'a>,
1616
}
1717

18-
pub struct Child<'a> {
18+
pub(crate) struct Child<'a> {
1919
pub raw: &'a mut super::ArchiveChild<'a>,
2020
}
2121

@@ -26,7 +26,7 @@ impl ArchiveRO {
2626
///
2727
/// If this archive is used with a mutable method, then an error will be
2828
/// raised.
29-
pub fn open(dst: &Path) -> Result<ArchiveRO, String> {
29+
pub(crate) fn open(dst: &Path) -> Result<ArchiveRO, String> {
3030
unsafe {
3131
let s = path_to_c_string(dst);
3232
let ar = super::LLVMRustOpenArchive(s.as_ptr()).ok_or_else(|| {
@@ -36,7 +36,7 @@ impl ArchiveRO {
3636
}
3737
}
3838

39-
pub fn iter(&self) -> Iter<'_> {
39+
pub(crate) fn iter(&self) -> Iter<'_> {
4040
unsafe { Iter { raw: super::LLVMRustArchiveIteratorNew(self.raw) } }
4141
}
4242
}
@@ -71,7 +71,7 @@ impl<'a> Drop for Iter<'a> {
7171
}
7272

7373
impl<'a> Child<'a> {
74-
pub fn name(&self) -> Option<&'a str> {
74+
pub(crate) fn name(&self) -> Option<&'a str> {
7575
unsafe {
7676
let mut name_len = 0;
7777
let name_ptr = super::LLVMRustArchiveChildName(self.raw, &mut name_len);

compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
use libc::c_uint;
44
use rustc_span::InnerSpan;
55

6-
pub use self::Diagnostic::*;
7-
pub use self::OptimizationDiagnosticKind::*;
6+
pub(crate) use self::Diagnostic::*;
7+
pub(crate) use self::OptimizationDiagnosticKind::*;
88
use super::{DiagnosticInfo, SMDiagnostic};
9-
use crate::value::Value;
109

1110
#[derive(Copy, Clone, Debug)]
12-
pub enum OptimizationDiagnosticKind {
11+
pub(crate) enum OptimizationDiagnosticKind {
1312
OptimizationRemark,
1413
OptimizationMissed,
1514
OptimizationAnalysis,
@@ -19,18 +18,17 @@ pub enum OptimizationDiagnosticKind {
1918
OptimizationRemarkOther,
2019
}
2120

22-
pub struct OptimizationDiagnostic<'ll> {
21+
pub(crate) struct OptimizationDiagnostic {
2322
pub kind: OptimizationDiagnosticKind,
2423
pub pass_name: String,
25-
pub function: &'ll Value,
2624
pub line: c_uint,
2725
pub column: c_uint,
2826
pub filename: String,
2927
pub message: String,
3028
}
3129

32-
impl<'ll> OptimizationDiagnostic<'ll> {
33-
unsafe fn unpack(kind: OptimizationDiagnosticKind, di: &'ll DiagnosticInfo) -> Self {
30+
impl OptimizationDiagnostic {
31+
unsafe fn unpack(kind: OptimizationDiagnosticKind, di: &DiagnosticInfo) -> Self {
3432
let mut function = None;
3533
let mut line = 0;
3634
let mut column = 0;
@@ -64,7 +62,6 @@ impl<'ll> OptimizationDiagnostic<'ll> {
6462
OptimizationDiagnostic {
6563
kind,
6664
pass_name: pass_name.expect("got a non-UTF8 pass name from LLVM"),
67-
function: function.unwrap(),
6865
line,
6966
column,
7067
filename,
@@ -73,14 +70,14 @@ impl<'ll> OptimizationDiagnostic<'ll> {
7370
}
7471
}
7572

76-
pub struct SrcMgrDiagnostic {
73+
pub(crate) struct SrcMgrDiagnostic {
7774
pub level: super::DiagnosticLevel,
7875
pub message: String,
7976
pub source: Option<(String, Vec<InnerSpan>)>,
8077
}
8178

8279
impl SrcMgrDiagnostic {
83-
pub unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
80+
pub(crate) unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
8481
// Recover the post-substitution assembly code from LLVM for better
8582
// diagnostics.
8683
let mut have_source = false;
@@ -120,7 +117,7 @@ impl SrcMgrDiagnostic {
120117
}
121118

122119
#[derive(Clone)]
123-
pub struct InlineAsmDiagnostic {
120+
pub(crate) struct InlineAsmDiagnostic {
124121
pub level: super::DiagnosticLevel,
125122
pub cookie: u64,
126123
pub message: String,
@@ -158,19 +155,19 @@ impl InlineAsmDiagnostic {
158155
}
159156
}
160157

161-
pub enum Diagnostic<'ll> {
162-
Optimization(OptimizationDiagnostic<'ll>),
158+
pub(crate) enum Diagnostic<'ll> {
159+
Optimization(OptimizationDiagnostic),
163160
InlineAsm(InlineAsmDiagnostic),
164161
PGO(&'ll DiagnosticInfo),
165162
Linker(&'ll DiagnosticInfo),
166163
Unsupported(&'ll DiagnosticInfo),
167164

168165
/// LLVM has other types that we do not wrap here.
169-
UnknownDiagnostic(&'ll DiagnosticInfo),
166+
UnknownDiagnostic,
170167
}
171168

172169
impl<'ll> Diagnostic<'ll> {
173-
pub unsafe fn unpack(di: &'ll DiagnosticInfo) -> Self {
170+
pub(crate) unsafe fn unpack(di: &'ll DiagnosticInfo) -> Self {
174171
use super::DiagnosticKind as Dk;
175172

176173
unsafe {
@@ -210,7 +207,7 @@ impl<'ll> Diagnostic<'ll> {
210207

211208
Dk::SrcMgr => InlineAsm(InlineAsmDiagnostic::unpackSrcMgr(di)),
212209

213-
_ => UnknownDiagnostic(di),
210+
_ => UnknownDiagnostic,
214211
}
215212
}
216213
}

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
#![allow(non_camel_case_types)]
2+
#![expect(dead_code)]
23

34
use libc::{c_char, c_uint};
45

56
use super::ffi::{BasicBlock, Metadata, Module, Type, Value};
67
use crate::llvm::Bool;
78
extern "C" {
89
// Enzyme
9-
pub fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool;
10-
pub fn LLVMRustEraseInstBefore(BB: &BasicBlock, I: &Value);
11-
pub fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
12-
pub fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
13-
pub fn LLVMRustEraseInstFromParent(V: &Value);
14-
pub fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
15-
pub fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
10+
pub(crate) fn LLVMRustHasMetadata(I: &Value, KindID: c_uint) -> bool;
11+
pub(crate) fn LLVMRustEraseInstBefore(BB: &BasicBlock, I: &Value);
12+
pub(crate) fn LLVMRustGetLastInstruction<'a>(BB: &BasicBlock) -> Option<&'a Value>;
13+
pub(crate) fn LLVMRustDIGetInstMetadata(I: &Value) -> Option<&Metadata>;
14+
pub(crate) fn LLVMRustEraseInstFromParent(V: &Value);
15+
pub(crate) fn LLVMRustGetTerminator<'a>(B: &BasicBlock) -> &'a Value;
16+
pub(crate) fn LLVMRustVerifyFunction(V: &Value, action: LLVMRustVerifierFailureAction) -> Bool;
1617

17-
pub fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
18-
pub fn LLVMGetReturnType(T: &Type) -> &Type;
19-
pub fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
20-
pub fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
18+
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
19+
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
20+
pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
21+
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
2122
}
2223

2324
#[repr(C)]
2425
#[derive(Copy, Clone, PartialEq)]
25-
pub enum LLVMRustVerifierFailureAction {
26+
pub(crate) enum LLVMRustVerifierFailureAction {
2627
LLVMAbortProcessAction = 0,
2728
LLVMPrintMessageAction = 1,
2829
LLVMReturnStatusAction = 2,

0 commit comments

Comments
 (0)