Skip to content

Commit fb1ab40

Browse files
authored
Unrolled build for #147488
Rollup merge of #147488 - AMS21:remove_llvm_rust_insert_private_global, r=nikic 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. Work towards #46437
2 parents bd34871 + 036ab3a commit fb1ab40

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
@@ -1955,7 +1955,6 @@ unsafe extern "C" {
19551955
NameLen: size_t,
19561956
T: &'a Type,
19571957
) -> &'a Value;
1958-
pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
19591958
pub(crate) fn LLVMRustGetNamedValue(
19601959
M: &Module,
19611960
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
@@ -205,12 +205,6 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
205205
return wrap(GV);
206206
}
207207

208-
extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
209-
LLVMTypeRef Ty) {
210-
return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
211-
GlobalValue::PrivateLinkage, nullptr));
212-
}
213-
214208
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
215209
enum class LLVMRustAttributeKind {
216210
AlwaysInline = 0,

0 commit comments

Comments
 (0)