Skip to content

Commit 036ab3a

Browse files
committed
refactor: Remove LLVMRustInsertPrivateGlobal and define_private_global
Since it can easily be implemented using the existing LLVM C API in terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global` was only used in one place.
1 parent 5767910 commit 036ab3a

File tree

4 files changed

+4
-16
lines changed

4 files changed

+4
-16
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,13 @@ impl<'ll> CodegenCx<'ll, '_> {
240240
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
241241
bug!("symbol `{}` is already defined", name);
242242
});
243-
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
244243
gv
245244
}
246-
_ => self.define_private_global(self.val_ty(cv)),
245+
_ => self.define_global("", self.val_ty(cv)).unwrap_or_else(|| {
246+
bug!("anonymous global symbol is already defined");
247+
}),
247248
};
249+
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
248250
llvm::set_initializer(gv, cv);
249251
set_global_alignment(self, gv, align);
250252
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);

compiler/rustc_codegen_llvm/src/declare.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
230230
}
231231
}
232232

233-
/// Declare a private global
234-
///
235-
/// Use this function when you intend to define a global without a name.
236-
pub(crate) fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
237-
unsafe { llvm::LLVMRustInsertPrivateGlobal(self.llmod(), ty) }
238-
}
239-
240233
/// Gets declared value by name.
241234
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
242235
debug!("get_declared_value(name={:?})", 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)