Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9c7173c

Browse files
committedJan 15, 2025·
Clean llvm wrapper
1 parent 2ae9916 commit 9c7173c

File tree

12 files changed

+630
-622
lines changed

12 files changed

+630
-622
lines changed
 

‎compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 14 additions & 17 deletions
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

Lines changed: 13 additions & 12 deletions
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,

‎compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 530 additions & 490 deletions
Large diffs are not rendered by default.

‎compiler/rustc_codegen_llvm/src/llvm/mod.rs

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,39 @@ use libc::c_uint;
1010
use rustc_abi::{Align, Size, WrappingRange};
1111
use rustc_llvm::RustString;
1212

13-
pub use self::AtomicRmwBinOp::*;
14-
pub use self::CallConv::*;
15-
pub use self::CodeGenOptSize::*;
16-
pub use self::IntPredicate::*;
17-
pub use self::Linkage::*;
18-
pub use self::MetadataType::*;
19-
pub use self::RealPredicate::*;
20-
pub use self::ffi::*;
13+
pub(crate) use self::CallConv::*;
14+
pub(crate) use self::CodeGenOptSize::*;
15+
pub(crate) use self::MetadataType::*;
16+
pub(crate) use self::ffi::*;
2117
use crate::common::AsCCharPtr;
2218

23-
pub mod archive_ro;
24-
pub mod diagnostic;
25-
pub mod enzyme_ffi;
19+
pub(crate) mod archive_ro;
20+
pub(crate) mod diagnostic;
21+
pub(crate) mod enzyme_ffi;
2622
mod ffi;
2723

28-
pub use self::enzyme_ffi::*;
24+
pub(crate) use self::enzyme_ffi::*;
2925

3026
impl LLVMRustResult {
31-
pub fn into_result(self) -> Result<(), ()> {
27+
pub(crate) fn into_result(self) -> Result<(), ()> {
3228
match self {
3329
LLVMRustResult::Success => Ok(()),
3430
LLVMRustResult::Failure => Err(()),
3531
}
3632
}
3733
}
3834

39-
pub fn AddFunctionAttributes<'ll>(llfn: &'ll Value, idx: AttributePlace, attrs: &[&'ll Attribute]) {
35+
pub(crate) fn AddFunctionAttributes<'ll>(
36+
llfn: &'ll Value,
37+
idx: AttributePlace,
38+
attrs: &[&'ll Attribute],
39+
) {
4040
unsafe {
4141
LLVMRustAddFunctionAttributes(llfn, idx.as_uint(), attrs.as_ptr(), attrs.len());
4242
}
4343
}
4444

45-
pub fn AddCallSiteAttributes<'ll>(
45+
pub(crate) fn AddCallSiteAttributes<'ll>(
4646
callsite: &'ll Value,
4747
idx: AttributePlace,
4848
attrs: &[&'ll Attribute],
@@ -52,7 +52,11 @@ pub fn AddCallSiteAttributes<'ll>(
5252
}
5353
}
5454

55-
pub fn CreateAttrStringValue<'ll>(llcx: &'ll Context, attr: &str, value: &str) -> &'ll Attribute {
55+
pub(crate) fn CreateAttrStringValue<'ll>(
56+
llcx: &'ll Context,
57+
attr: &str,
58+
value: &str,
59+
) -> &'ll Attribute {
5660
unsafe {
5761
LLVMCreateStringAttribute(
5862
llcx,
@@ -64,7 +68,7 @@ pub fn CreateAttrStringValue<'ll>(llcx: &'ll Context, attr: &str, value: &str) -
6468
}
6569
}
6670

67-
pub fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute {
71+
pub(crate) fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute {
6872
unsafe {
6973
LLVMCreateStringAttribute(
7074
llcx,
@@ -76,39 +80,39 @@ pub fn CreateAttrString<'ll>(llcx: &'ll Context, attr: &str) -> &'ll Attribute {
7680
}
7781
}
7882

79-
pub fn CreateAlignmentAttr(llcx: &Context, bytes: u64) -> &Attribute {
83+
pub(crate) fn CreateAlignmentAttr(llcx: &Context, bytes: u64) -> &Attribute {
8084
unsafe { LLVMRustCreateAlignmentAttr(llcx, bytes) }
8185
}
8286

83-
pub fn CreateDereferenceableAttr(llcx: &Context, bytes: u64) -> &Attribute {
87+
pub(crate) fn CreateDereferenceableAttr(llcx: &Context, bytes: u64) -> &Attribute {
8488
unsafe { LLVMRustCreateDereferenceableAttr(llcx, bytes) }
8589
}
8690

87-
pub fn CreateDereferenceableOrNullAttr(llcx: &Context, bytes: u64) -> &Attribute {
91+
pub(crate) fn CreateDereferenceableOrNullAttr(llcx: &Context, bytes: u64) -> &Attribute {
8892
unsafe { LLVMRustCreateDereferenceableOrNullAttr(llcx, bytes) }
8993
}
9094

91-
pub fn CreateByValAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute {
95+
pub(crate) fn CreateByValAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute {
9296
unsafe { LLVMRustCreateByValAttr(llcx, ty) }
9397
}
9498

95-
pub fn CreateStructRetAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute {
99+
pub(crate) fn CreateStructRetAttr<'ll>(llcx: &'ll Context, ty: &'ll Type) -> &'ll Attribute {
96100
unsafe { LLVMRustCreateStructRetAttr(llcx, ty) }
97101
}
98102

99-
pub fn CreateUWTableAttr(llcx: &Context, async_: bool) -> &Attribute {
103+
pub(crate) fn CreateUWTableAttr(llcx: &Context, async_: bool) -> &Attribute {
100104
unsafe { LLVMRustCreateUWTableAttr(llcx, async_) }
101105
}
102106

103-
pub fn CreateAllocSizeAttr(llcx: &Context, size_arg: u32) -> &Attribute {
107+
pub(crate) fn CreateAllocSizeAttr(llcx: &Context, size_arg: u32) -> &Attribute {
104108
unsafe { LLVMRustCreateAllocSizeAttr(llcx, size_arg) }
105109
}
106110

107-
pub fn CreateAllocKindAttr(llcx: &Context, kind_arg: AllocKindFlags) -> &Attribute {
111+
pub(crate) fn CreateAllocKindAttr(llcx: &Context, kind_arg: AllocKindFlags) -> &Attribute {
108112
unsafe { LLVMRustCreateAllocKindAttr(llcx, kind_arg.bits()) }
109113
}
110114

111-
pub fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Attribute {
115+
pub(crate) fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Attribute {
112116
let lower = range.start;
113117
let upper = range.end.wrapping_add(1);
114118
let lower_words = [lower as u64, (lower >> 64) as u64];
@@ -124,14 +128,14 @@ pub fn CreateRangeAttr(llcx: &Context, size: Size, range: WrappingRange) -> &Att
124128
}
125129

126130
#[derive(Copy, Clone)]
127-
pub enum AttributePlace {
131+
pub(crate) enum AttributePlace {
128132
ReturnValue,
129133
Argument(u32),
130134
Function,
131135
}
132136

133137
impl AttributePlace {
134-
pub fn as_uint(self) -> c_uint {
138+
pub(crate) fn as_uint(self) -> c_uint {
135139
match self {
136140
AttributePlace::ReturnValue => 0,
137141
AttributePlace::Argument(i) => 1 + i,
@@ -142,7 +146,7 @@ impl AttributePlace {
142146

143147
#[derive(Copy, Clone, PartialEq)]
144148
#[repr(C)]
145-
pub enum CodeGenOptSize {
149+
pub(crate) enum CodeGenOptSize {
146150
CodeGenOptSizeNone = 0,
147151
CodeGenOptSizeDefault = 1,
148152
CodeGenOptSizeAggressive = 2,
@@ -163,12 +167,12 @@ impl FromStr for ArchiveKind {
163167
}
164168
}
165169

166-
pub fn SetInstructionCallConv(instr: &Value, cc: CallConv) {
170+
pub(crate) fn SetInstructionCallConv(instr: &Value, cc: CallConv) {
167171
unsafe {
168172
LLVMSetInstructionCallConv(instr, cc as c_uint);
169173
}
170174
}
171-
pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
175+
pub(crate) fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
172176
unsafe {
173177
LLVMSetFunctionCallConv(fn_, cc as c_uint);
174178
}
@@ -180,82 +184,82 @@ pub fn SetFunctionCallConv(fn_: &Value, cc: CallConv) {
180184
// value's name as the comdat value to make sure that it is in a 1-to-1 relationship to the
181185
// function.
182186
// For more details on COMDAT sections see e.g., https://www.airs.com/blog/archives/52
183-
pub fn SetUniqueComdat(llmod: &Module, val: &Value) {
187+
pub(crate) fn SetUniqueComdat(llmod: &Module, val: &Value) {
184188
let name_buf = get_value_name(val).to_vec();
185189
let name =
186190
CString::from_vec_with_nul(name_buf).or_else(|buf| CString::new(buf.into_bytes())).unwrap();
187191
set_comdat(llmod, val, &name);
188192
}
189193

190-
pub fn SetUnnamedAddress(global: &Value, unnamed: UnnamedAddr) {
194+
pub(crate) fn SetUnnamedAddress(global: &Value, unnamed: UnnamedAddr) {
191195
unsafe {
192196
LLVMSetUnnamedAddress(global, unnamed);
193197
}
194198
}
195199

196-
pub fn set_thread_local_mode(global: &Value, mode: ThreadLocalMode) {
200+
pub(crate) fn set_thread_local_mode(global: &Value, mode: ThreadLocalMode) {
197201
unsafe {
198202
LLVMSetThreadLocalMode(global, mode);
199203
}
200204
}
201205

202206
impl AttributeKind {
203207
/// Create an LLVM Attribute with no associated value.
204-
pub fn create_attr(self, llcx: &Context) -> &Attribute {
208+
pub(crate) fn create_attr(self, llcx: &Context) -> &Attribute {
205209
unsafe { LLVMRustCreateAttrNoValue(llcx, self) }
206210
}
207211
}
208212

209213
impl MemoryEffects {
210214
/// Create an LLVM Attribute with these memory effects.
211-
pub fn create_attr(self, llcx: &Context) -> &Attribute {
215+
pub(crate) fn create_attr(self, llcx: &Context) -> &Attribute {
212216
unsafe { LLVMRustCreateMemoryEffectsAttr(llcx, self) }
213217
}
214218
}
215219

216-
pub fn set_section(llglobal: &Value, section_name: &CStr) {
220+
pub(crate) fn set_section(llglobal: &Value, section_name: &CStr) {
217221
unsafe {
218222
LLVMSetSection(llglobal, section_name.as_ptr());
219223
}
220224
}
221225

222-
pub fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name_cstr: &CStr) -> &'a Value {
226+
pub(crate) fn add_global<'a>(llmod: &'a Module, ty: &'a Type, name_cstr: &CStr) -> &'a Value {
223227
unsafe { LLVMAddGlobal(llmod, ty, name_cstr.as_ptr()) }
224228
}
225229

226-
pub fn set_initializer(llglobal: &Value, constant_val: &Value) {
230+
pub(crate) fn set_initializer(llglobal: &Value, constant_val: &Value) {
227231
unsafe {
228232
LLVMSetInitializer(llglobal, constant_val);
229233
}
230234
}
231235

232-
pub fn set_global_constant(llglobal: &Value, is_constant: bool) {
236+
pub(crate) fn set_global_constant(llglobal: &Value, is_constant: bool) {
233237
unsafe {
234238
LLVMSetGlobalConstant(llglobal, if is_constant { ffi::True } else { ffi::False });
235239
}
236240
}
237241

238-
pub fn get_linkage(llglobal: &Value) -> Linkage {
242+
pub(crate) fn get_linkage(llglobal: &Value) -> Linkage {
239243
unsafe { LLVMGetLinkage(llglobal) }.to_rust()
240244
}
241245

242-
pub fn set_linkage(llglobal: &Value, linkage: Linkage) {
246+
pub(crate) fn set_linkage(llglobal: &Value, linkage: Linkage) {
243247
unsafe {
244248
LLVMSetLinkage(llglobal, linkage);
245249
}
246250
}
247251

248-
pub fn get_visibility(llglobal: &Value) -> Visibility {
252+
pub(crate) fn get_visibility(llglobal: &Value) -> Visibility {
249253
unsafe { LLVMGetVisibility(llglobal) }.to_rust()
250254
}
251255

252-
pub fn set_visibility(llglobal: &Value, visibility: Visibility) {
256+
pub(crate) fn set_visibility(llglobal: &Value, visibility: Visibility) {
253257
unsafe {
254258
LLVMSetVisibility(llglobal, visibility);
255259
}
256260
}
257261

258-
pub fn set_alignment(llglobal: &Value, align: Align) {
262+
pub(crate) fn set_alignment(llglobal: &Value, align: Align) {
259263
unsafe {
260264
ffi::LLVMSetAlignment(llglobal, align.bytes() as c_uint);
261265
}
@@ -265,15 +269,15 @@ pub fn set_alignment(llglobal: &Value, align: Align) {
265269
///
266270
/// Inserts the comdat into `llmod` if it does not exist.
267271
/// It is an error to call this if the target does not support comdat.
268-
pub fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
272+
pub(crate) fn set_comdat(llmod: &Module, llglobal: &Value, name: &CStr) {
269273
unsafe {
270274
let comdat = LLVMGetOrInsertComdat(llmod, name.as_ptr());
271275
LLVMSetComdat(llglobal, comdat);
272276
}
273277
}
274278

275279
/// Safe wrapper around `LLVMGetParam`, because segfaults are no fun.
276-
pub fn get_param(llfn: &Value, index: c_uint) -> &Value {
280+
pub(crate) fn get_param(llfn: &Value, index: c_uint) -> &Value {
277281
unsafe {
278282
assert!(
279283
index < LLVMCountParams(llfn),
@@ -286,7 +290,7 @@ pub fn get_param(llfn: &Value, index: c_uint) -> &Value {
286290
}
287291

288292
/// Safe wrapper for `LLVMGetValueName2` into a byte slice
289-
pub fn get_value_name(value: &Value) -> &[u8] {
293+
pub(crate) fn get_value_name(value: &Value) -> &[u8] {
290294
unsafe {
291295
let mut len = 0;
292296
let data = LLVMGetValueName2(value, &mut len);
@@ -295,28 +299,28 @@ pub fn get_value_name(value: &Value) -> &[u8] {
295299
}
296300

297301
/// Safe wrapper for `LLVMSetValueName2` from a byte slice
298-
pub fn set_value_name(value: &Value, name: &[u8]) {
302+
pub(crate) fn set_value_name(value: &Value, name: &[u8]) {
299303
unsafe {
300304
let data = name.as_c_char_ptr();
301305
LLVMSetValueName2(value, data, name.len());
302306
}
303307
}
304308

305-
pub fn build_string(f: impl FnOnce(&RustString)) -> Result<String, FromUtf8Error> {
309+
pub(crate) fn build_string(f: impl FnOnce(&RustString)) -> Result<String, FromUtf8Error> {
306310
String::from_utf8(RustString::build_byte_buffer(f))
307311
}
308312

309-
pub fn build_byte_buffer(f: impl FnOnce(&RustString)) -> Vec<u8> {
313+
pub(crate) fn build_byte_buffer(f: impl FnOnce(&RustString)) -> Vec<u8> {
310314
RustString::build_byte_buffer(f)
311315
}
312316

313-
pub fn twine_to_string(tr: &Twine) -> String {
317+
pub(crate) fn twine_to_string(tr: &Twine) -> String {
314318
unsafe {
315319
build_string(|s| LLVMRustWriteTwineToString(tr, s)).expect("got a non-UTF8 Twine from LLVM")
316320
}
317321
}
318322

319-
pub fn last_error() -> Option<String> {
323+
pub(crate) fn last_error() -> Option<String> {
320324
unsafe {
321325
let cstr = LLVMRustGetLastError();
322326
if cstr.is_null() {

‎compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
303303
/// Must express features in the way Rust understands them.
304304
///
305305
/// We do not have to worry about RUSTC_SPECIFIC_FEATURES here, those are handled outside codegen.
306-
pub fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
306+
pub(crate) fn target_features_cfg(sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
307307
let mut features: FxHashSet<Symbol> = Default::default();
308308

309309
// Add base features for the target.

‎compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,11 @@ impl<'ll, 'tcx> BaseTypeCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
236236

237237
impl Type {
238238
/// Creates an integer type with the given number of bits, e.g., i24
239-
pub fn ix_llcx(llcx: &llvm::Context, num_bits: u64) -> &Type {
239+
pub(crate) fn ix_llcx(llcx: &llvm::Context, num_bits: u64) -> &Type {
240240
unsafe { llvm::LLVMIntTypeInContext(llcx, num_bits as c_uint) }
241241
}
242242

243-
pub fn ptr_llcx(llcx: &llvm::Context) -> &Type {
243+
pub(crate) fn ptr_llcx(llcx: &llvm::Context) -> &Type {
244244
unsafe { llvm::LLVMPointerTypeInContext(llcx, AddressSpace::DATA.0) }
245245
}
246246
}

‎compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -194,33 +194,6 @@ LLVMRustVerifyFunction(LLVMValueRef Fn, LLVMRustVerifierFailureAction Action) {
194194
return LLVMVerifyFunction(Fn, fromRust(Action));
195195
}
196196

197-
enum class LLVMRustTailCallKind {
198-
None,
199-
Tail,
200-
MustTail,
201-
NoTail,
202-
};
203-
204-
static CallInst::TailCallKind fromRust(LLVMRustTailCallKind Kind) {
205-
switch (Kind) {
206-
case LLVMRustTailCallKind::None:
207-
return CallInst::TailCallKind::TCK_None;
208-
case LLVMRustTailCallKind::Tail:
209-
return CallInst::TailCallKind::TCK_Tail;
210-
case LLVMRustTailCallKind::MustTail:
211-
return CallInst::TailCallKind::TCK_MustTail;
212-
case LLVMRustTailCallKind::NoTail:
213-
return CallInst::TailCallKind::TCK_NoTail;
214-
default:
215-
report_fatal_error("bad CallInst::TailCallKind.");
216-
}
217-
}
218-
219-
extern "C" void LLVMRustSetTailCallKind(LLVMValueRef Call,
220-
LLVMRustTailCallKind TCK) {
221-
unwrap<CallInst>(Call)->setTailCallKind(fromRust(TCK));
222-
}
223-
224197
extern "C" LLVMValueRef LLVMRustGetOrInsertFunction(LLVMModuleRef M,
225198
const char *Name,
226199
size_t NameLen,
@@ -887,7 +860,6 @@ fromRust(LLVMRustDebugEmissionKind Kind) {
887860

888861
enum class LLVMRustDebugNameTableKind {
889862
Default,
890-
GNU,
891863
None,
892864
};
893865

@@ -896,8 +868,6 @@ fromRust(LLVMRustDebugNameTableKind Kind) {
896868
switch (Kind) {
897869
case LLVMRustDebugNameTableKind::Default:
898870
return DICompileUnit::DebugNameTableKind::Default;
899-
case LLVMRustDebugNameTableKind::GNU:
900-
return DICompileUnit::DebugNameTableKind::GNU;
901871
case LLVMRustDebugNameTableKind::None:
902872
return DICompileUnit::DebugNameTableKind::None;
903873
default:
@@ -2054,10 +2024,6 @@ extern "C" int32_t LLVMRustGetElementTypeArgIndex(LLVMValueRef CallSite) {
20542024
return -1;
20552025
}
20562026

2057-
extern "C" bool LLVMRustIsBitcode(char *ptr, size_t len) {
2058-
return identify_magic(StringRef(ptr, len)) == file_magic::bitcode;
2059-
}
2060-
20612027
extern "C" bool LLVMRustIsNonGVFunctionPointerTy(LLVMValueRef V) {
20622028
if (unwrap<Value>(V)->getType()->isPointerTy()) {
20632029
if (auto *GV = dyn_cast<GlobalValue>(unwrap<Value>(V))) {

0 commit comments

Comments
 (0)
Please sign in to comment.