Skip to content

Commit 101b8d5

Browse files
committed
refactor: Remove LLVMRustInsertPrivateGlobal
Since it can easily be implemented using the existing LLVM C API in terms of `LLVMAddGlobal` and `LLVMSetLinkage`.
1 parent 5767910 commit 101b8d5

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use tracing::debug;
2424

2525
use crate::abi::FnAbiLlvmExt;
2626
use crate::attributes;
27+
use crate::builder::UNNAMED;
2728
use crate::common::AsCCharPtr;
2829
use crate::context::{CodegenCx, GenericCx, SCx, SimpleCx};
2930
use crate::llvm::AttributePlace::Function;
@@ -234,7 +235,9 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
234235
///
235236
/// Use this function when you intend to define a global without a name.
236237
pub(crate) fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
237-
unsafe { llvm::LLVMRustInsertPrivateGlobal(self.llmod(), ty) }
238+
let global = unsafe { llvm::LLVMAddGlobal(self.llmod(), ty, UNNAMED) };
239+
unsafe { llvm::LLVMSetLinkage(global, llvm::Linkage::PrivateLinkage) };
240+
global
238241
}
239242

240243
/// Gets declared value by name.

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1954,7 +1954,6 @@ unsafe extern "C" {
19541954
NameLen: size_t,
19551955
T: &'a Type,
19561956
) -> &'a Value;
1957-
pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
19581957
pub(crate) fn LLVMRustGetNamedValue(
19591958
M: &Module,
19601959
Name: *const c_char,

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,6 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
228228
return wrap(GV);
229229
}
230230

231-
extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
232-
LLVMTypeRef Ty) {
233-
return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
234-
GlobalValue::PrivateLinkage, nullptr));
235-
}
236-
237231
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
238232
enum class LLVMRustAttributeKind {
239233
AlwaysInline = 0,

0 commit comments

Comments
 (0)