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.
This commit is contained in:
@@ -240,11 +240,13 @@ impl<'ll> CodegenCx<'ll, '_> {
|
|||||||
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
|
let gv = self.define_global(&name, self.val_ty(cv)).unwrap_or_else(|| {
|
||||||
bug!("symbol `{}` is already defined", name);
|
bug!("symbol `{}` is already defined", name);
|
||||||
});
|
});
|
||||||
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
|
|
||||||
gv
|
gv
|
||||||
}
|
}
|
||||||
_ => self.define_private_global(self.val_ty(cv)),
|
_ => self.define_global("", self.val_ty(cv)).unwrap_or_else(|| {
|
||||||
|
bug!("anonymous global symbol is already defined");
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
|
llvm::set_linkage(gv, llvm::Linkage::PrivateLinkage);
|
||||||
llvm::set_initializer(gv, cv);
|
llvm::set_initializer(gv, cv);
|
||||||
set_global_alignment(self, gv, align);
|
set_global_alignment(self, gv, align);
|
||||||
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);
|
llvm::set_unnamed_address(gv, llvm::UnnamedAddr::Global);
|
||||||
|
|||||||
@@ -230,13 +230,6 @@ impl<'ll, CX: Borrow<SCx<'ll>>> GenericCx<'ll, CX> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Declare a private global
|
|
||||||
///
|
|
||||||
/// Use this function when you intend to define a global without a name.
|
|
||||||
pub(crate) fn define_private_global(&self, ty: &'ll Type) -> &'ll Value {
|
|
||||||
unsafe { llvm::LLVMRustInsertPrivateGlobal(self.llmod(), ty) }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets declared value by name.
|
/// Gets declared value by name.
|
||||||
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
|
pub(crate) fn get_declared_value(&self, name: &str) -> Option<&'ll Value> {
|
||||||
debug!("get_declared_value(name={:?})", name);
|
debug!("get_declared_value(name={:?})", name);
|
||||||
|
|||||||
@@ -1954,7 +1954,6 @@ unsafe extern "C" {
|
|||||||
NameLen: size_t,
|
NameLen: size_t,
|
||||||
T: &'a Type,
|
T: &'a Type,
|
||||||
) -> &'a Value;
|
) -> &'a Value;
|
||||||
pub(crate) fn LLVMRustInsertPrivateGlobal<'a>(M: &'a Module, T: &'a Type) -> &'a Value;
|
|
||||||
pub(crate) fn LLVMRustGetNamedValue(
|
pub(crate) fn LLVMRustGetNamedValue(
|
||||||
M: &Module,
|
M: &Module,
|
||||||
Name: *const c_char,
|
Name: *const c_char,
|
||||||
|
|||||||
@@ -228,12 +228,6 @@ extern "C" LLVMValueRef LLVMRustGetOrInsertGlobal(LLVMModuleRef M,
|
|||||||
return wrap(GV);
|
return wrap(GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" LLVMValueRef LLVMRustInsertPrivateGlobal(LLVMModuleRef M,
|
|
||||||
LLVMTypeRef Ty) {
|
|
||||||
return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
|
|
||||||
GlobalValue::PrivateLinkage, nullptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
|
// Must match the layout of `rustc_codegen_llvm::llvm::ffi::AttributeKind`.
|
||||||
enum class LLVMRustAttributeKind {
|
enum class LLVMRustAttributeKind {
|
||||||
AlwaysInline = 0,
|
AlwaysInline = 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user