Skip to content

Commit

Permalink
Clean llvm wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello committed Feb 18, 2025
1 parent 827a0d6 commit ecb9173
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 113 deletions.
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::mem::ManuallyDrop;
use back::owned_target_machine::OwnedTargetMachine;
use back::write::{create_informational_target_machine, create_target_machine};
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
pub(crate) use llvm_util::target_features_cfg;
use llvm_util::target_features_cfg;
use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
Expand Down Expand Up @@ -72,9 +72,7 @@ mod debuginfo;
mod declare;
mod errors;
mod intrinsic;
// FIXME(Zalathar): Fix all the unreachable-pub warnings that would occur if
// this isn't pub, then make it not pub.
pub mod llvm;
pub(crate) mod llvm;
mod llvm_util;
mod mono_item;
mod type_;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/llvm/archive_ro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ use std::{slice, str};

use rustc_fs_util::path_to_c_string;

pub struct ArchiveRO {
pub(crate) struct ArchiveRO {
pub raw: &'static mut super::Archive,
}

unsafe impl Send for ArchiveRO {}

pub struct Iter<'a> {
pub(crate) struct Iter<'a> {
raw: &'a mut super::ArchiveIterator<'a>,
}

pub struct Child<'a> {
pub(crate) struct Child<'a> {
pub raw: &'a mut super::ArchiveChild<'a>,
}

Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc_codegen_llvm/src/llvm/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
use libc::c_uint;
use rustc_span::InnerSpan;

pub use self::Diagnostic::*;
pub use self::OptimizationDiagnosticKind::*;
pub(crate) use self::Diagnostic::*;
use self::OptimizationDiagnosticKind::*;
use super::{DiagnosticInfo, SMDiagnostic};
use crate::value::Value;

#[derive(Copy, Clone, Debug)]
pub enum OptimizationDiagnosticKind {
pub(crate) enum OptimizationDiagnosticKind {
OptimizationRemark,
OptimizationMissed,
OptimizationAnalysis,
Expand All @@ -19,9 +19,10 @@ pub enum OptimizationDiagnosticKind {
OptimizationRemarkOther,
}

pub struct OptimizationDiagnostic<'ll> {
pub(crate) struct OptimizationDiagnostic<'ll> {
pub kind: OptimizationDiagnosticKind,
pub pass_name: String,
#[expect(dead_code)]
pub function: &'ll Value,
pub line: c_uint,
pub column: c_uint,
Expand Down Expand Up @@ -73,14 +74,14 @@ impl<'ll> OptimizationDiagnostic<'ll> {
}
}

pub struct SrcMgrDiagnostic {
pub(crate) struct SrcMgrDiagnostic {
pub level: super::DiagnosticLevel,
pub message: String,
pub source: Option<(String, Vec<InnerSpan>)>,
}

impl SrcMgrDiagnostic {
pub unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
pub(crate) unsafe fn unpack(diag: &SMDiagnostic) -> SrcMgrDiagnostic {
// Recover the post-substitution assembly code from LLVM for better
// diagnostics.
let mut have_source = false;
Expand Down Expand Up @@ -120,7 +121,7 @@ impl SrcMgrDiagnostic {
}

#[derive(Clone)]
pub struct InlineAsmDiagnostic {
pub(crate) struct InlineAsmDiagnostic {
pub level: super::DiagnosticLevel,
pub cookie: u64,
pub message: String,
Expand Down Expand Up @@ -158,19 +159,20 @@ impl InlineAsmDiagnostic {
}
}

pub enum Diagnostic<'ll> {
pub(crate) enum Diagnostic<'ll> {
Optimization(OptimizationDiagnostic<'ll>),
InlineAsm(InlineAsmDiagnostic),
PGO(&'ll DiagnosticInfo),
Linker(&'ll DiagnosticInfo),
Unsupported(&'ll DiagnosticInfo),

/// LLVM has other types that we do not wrap here.
#[expect(dead_code)]
UnknownDiagnostic(&'ll DiagnosticInfo),
}

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

unsafe {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern "C" {

#[repr(C)]
#[derive(Copy, Clone, PartialEq)]
pub enum LLVMRustVerifierFailureAction {
pub(crate) enum LLVMRustVerifierFailureAction {
LLVMAbortProcessAction = 0,
LLVMPrintMessageAction = 1,
LLVMReturnStatusAction = 2,
Expand Down
Loading

0 comments on commit ecb9173

Please sign in to comment.