Reuse address-space computation from global alloc
This commit is contained in:
parent
18a029cfe8
commit
cfa52e48ae
1 changed files with 8 additions and 8 deletions
|
@ -4,8 +4,8 @@ use std::borrow::Borrow;
|
||||||
|
|
||||||
use libc::{c_char, c_uint};
|
use libc::{c_char, c_uint};
|
||||||
use rustc_abi as abi;
|
use rustc_abi as abi;
|
||||||
|
use rustc_abi::HasDataLayout;
|
||||||
use rustc_abi::Primitive::Pointer;
|
use rustc_abi::Primitive::Pointer;
|
||||||
use rustc_abi::{AddressSpace, HasDataLayout};
|
|
||||||
use rustc_ast::Mutability;
|
use rustc_ast::Mutability;
|
||||||
use rustc_codegen_ssa::common::TypeKind;
|
use rustc_codegen_ssa::common::TypeKind;
|
||||||
use rustc_codegen_ssa::traits::*;
|
use rustc_codegen_ssa::traits::*;
|
||||||
|
@ -269,7 +269,8 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
|
||||||
}
|
}
|
||||||
Scalar::Ptr(ptr, _size) => {
|
Scalar::Ptr(ptr, _size) => {
|
||||||
let (prov, offset) = ptr.into_parts();
|
let (prov, offset) = ptr.into_parts();
|
||||||
let (base_addr, base_addr_space) = match self.tcx.global_alloc(prov.alloc_id()) {
|
let global_alloc = self.tcx.global_alloc(prov.alloc_id());
|
||||||
|
let base_addr = match global_alloc {
|
||||||
GlobalAlloc::Memory(alloc) => {
|
GlobalAlloc::Memory(alloc) => {
|
||||||
// For ZSTs directly codegen an aligned pointer.
|
// For ZSTs directly codegen an aligned pointer.
|
||||||
// This avoids generating a zero-sized constant value and actually needing a
|
// This avoids generating a zero-sized constant value and actually needing a
|
||||||
|
@ -301,12 +302,10 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
|
||||||
format!("alloc_{hash:032x}").as_bytes(),
|
format!("alloc_{hash:032x}").as_bytes(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(value, AddressSpace::DATA)
|
value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalAlloc::Function { instance, .. } => {
|
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance),
|
||||||
(self.get_fn_addr(instance), self.data_layout().instruction_address_space)
|
|
||||||
}
|
|
||||||
GlobalAlloc::VTable(ty, dyn_ty) => {
|
GlobalAlloc::VTable(ty, dyn_ty) => {
|
||||||
let alloc = self
|
let alloc = self
|
||||||
.tcx
|
.tcx
|
||||||
|
@ -319,14 +318,15 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
|
||||||
.unwrap_memory();
|
.unwrap_memory();
|
||||||
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
|
let init = const_alloc_to_llvm(self, alloc, /*static*/ false);
|
||||||
let value = self.static_addr_of_impl(init, alloc.inner().align, None);
|
let value = self.static_addr_of_impl(init, alloc.inner().align, None);
|
||||||
(value, AddressSpace::DATA)
|
value
|
||||||
}
|
}
|
||||||
GlobalAlloc::Static(def_id) => {
|
GlobalAlloc::Static(def_id) => {
|
||||||
assert!(self.tcx.is_static(def_id));
|
assert!(self.tcx.is_static(def_id));
|
||||||
assert!(!self.tcx.is_thread_local_static(def_id));
|
assert!(!self.tcx.is_thread_local_static(def_id));
|
||||||
(self.get_static(def_id), AddressSpace::DATA)
|
self.get_static(def_id)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let base_addr_space = global_alloc.address_space(self);
|
||||||
let llval = unsafe {
|
let llval = unsafe {
|
||||||
llvm::LLVMConstInBoundsGEP2(
|
llvm::LLVMConstInBoundsGEP2(
|
||||||
self.type_i8(),
|
self.type_i8(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue