Skip to content

Commit

Permalink
Move codegen_static function body to an inherent method in preparat…
Browse files Browse the repository at this point in the history
…ion of splitting it.

This should make the diff easier to read, as this commit does no functional changes at all.
  • Loading branch information
oli-obk committed Mar 12, 2024
1 parent d4b30aa commit 6719a8e
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,30 +343,8 @@ impl<'ll> CodegenCx<'ll, '_> {
self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g);
g
}
}

impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
unsafe {
// Upgrade the alignment in cases where the same constant is used with different
// alignment requirements
let llalign = align.bytes() as u32;
if llalign > llvm::LLVMGetAlignment(gv) {
llvm::LLVMSetAlignment(gv, llalign);
}
}
return gv;
}
let gv = self.static_addr_of_mut(cv, align, kind);
unsafe {
llvm::LLVMSetGlobalConstant(gv, True);
}
self.const_globals.borrow_mut().insert(cv, gv);
gv
}

fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
fn codegen_static_item(&self, def_id: DefId, is_mutable: bool) {
unsafe {
let attrs = self.tcx.codegen_fn_attrs(def_id);

Expand Down Expand Up @@ -550,6 +528,32 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
}
}
}
}

impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
fn static_addr_of(&self, cv: &'ll Value, align: Align, kind: Option<&str>) -> &'ll Value {
if let Some(&gv) = self.const_globals.borrow().get(&cv) {
unsafe {
// Upgrade the alignment in cases where the same constant is used with different
// alignment requirements
let llalign = align.bytes() as u32;
if llalign > llvm::LLVMGetAlignment(gv) {
llvm::LLVMSetAlignment(gv, llalign);
}
}
return gv;
}
let gv = self.static_addr_of_mut(cv, align, kind);
unsafe {
llvm::LLVMSetGlobalConstant(gv, True);
}
self.const_globals.borrow_mut().insert(cv, gv);
gv
}

fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
self.codegen_static_item(def_id, is_mutable)
}

/// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr.
fn add_used_global(&self, global: &'ll Value) {
Expand Down

0 comments on commit 6719a8e

Please sign in to comment.