Skip to content

Commit 8e50ef3

Browse files
committed
Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee
Allow custom default address spaces and parse `p-` specifications in the datalayout string Some targets, such as CHERI, use as default an address space different from the "normal" default address space `0` (in the case of CHERI, [200 is used](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-877.pdf)). Currently, `rustc` does not allow to specify custom address spaces and does not take into consideration [`p-` specifications in the datalayout string](https://llvm.org/docs/LangRef.html#langref-datalayout). This patch tries to mitigate these problems by allowing targets to define a custom default address space (while keeping the default value to address space `0`) and adding the code to parse the `p-` specifications in `rustc_abi`. The main changes are that `TargetDataLayout` now uses functions to refer to pointer-related informations, instead of having specific fields for the size and alignment of pointers in the default address space; furthermore, the two `pointer_size` and `pointer_align` fields in `TargetDataLayout` are replaced with an `FxHashMap` that holds info for all the possible address spaces, as parsed by the `p-` specifications. The potential performance drawbacks of not having ad-hoc fields for the default address space will be tested in this PR's CI run. r? workingjubilee
2 parents 214311b + 303a795 commit 8e50ef3

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
162162
}
163163

164164
fn const_usize(&self, i: u64) -> RValue<'gcc> {
165-
let bit_size = self.data_layout().pointer_size.bits();
165+
let bit_size = self.data_layout().pointer_size().bits();
166166
if bit_size < 64 {
167167
// make sure it doesn't overflow
168168
assert!(i < (1 << bit_size));

src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
294294
let alloc = alloc.inner();
295295
let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);
296296
let dl = cx.data_layout();
297-
let pointer_size = dl.pointer_size.bytes() as usize;
297+
let pointer_size = dl.pointer_size().bytes() as usize;
298298

299299
let mut next_offset = 0;
300300
for &(offset, prov) in alloc.provenance().ptrs().iter() {
@@ -331,7 +331,7 @@ pub(crate) fn const_alloc_to_gcc_uncached<'gcc>(
331331
),
332332
abi::Scalar::Initialized {
333333
value: Primitive::Pointer(address_space),
334-
valid_range: WrappingRange::full(dl.pointer_size),
334+
valid_range: WrappingRange::full(dl.pointer_size()),
335335
},
336336
cx.type_i8p_ext(address_space),
337337
));

src/intrinsic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
541541
// For rusty ABIs, small aggregates are actually passed
542542
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
543543
// so we re-use that same threshold here.
544-
layout.size() <= self.data_layout().pointer_size * 2
544+
layout.size() <= self.data_layout().pointer_size() * 2
545545
}
546546
};
547547

src/intrinsic/simd.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
11841184
let lhs = args[0].immediate();
11851185
let rhs = args[1].immediate();
11861186
let is_add = name == sym::simd_saturating_add;
1187-
let ptr_bits = bx.tcx().data_layout.pointer_size.bits() as _;
1187+
let ptr_bits = bx.tcx().data_layout.pointer_size().bits() as _;
11881188
let (signed, elem_width, elem_ty) = match *in_elem.kind() {
11891189
ty::Int(i) => (true, i.bit_width().unwrap_or(ptr_bits) / 8, bx.cx.type_int_from_ty(i)),
11901190
ty::Uint(i) => {

0 commit comments

Comments
 (0)