Skip to content

Commit 93f1201

Browse files
committed
compiler: Parse p- specs in datalayout string, allow definition of custom default data address space
1 parent 733b47e commit 93f1201

File tree

58 files changed

+416
-170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+416
-170
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 259 additions & 36 deletions
Large diffs are not rendered by default.

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
5555
/// Get the maximum value of int_ty. It is platform-dependent due to the byte size of isize
5656
fn int_ty_max(&self, int_ty: IntTy) -> u128 {
5757
match int_ty {
58-
IntTy::Isize => self.tcx.data_layout.pointer_size.signed_int_max() as u128,
58+
IntTy::Isize => self.tcx.data_layout.pointer_size().signed_int_max() as u128,
5959
IntTy::I8 => i8::MAX as u128,
6060
IntTy::I16 => i16::MAX as u128,
6161
IntTy::I32 => i32::MAX as u128,
@@ -67,7 +67,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
6767
/// Get the maximum value of uint_ty. It is platform-dependent due to the byte size of usize
6868
fn uint_ty_max(&self, uint_ty: UintTy) -> u128 {
6969
match uint_ty {
70-
UintTy::Usize => self.tcx.data_layout.pointer_size.unsigned_int_max(),
70+
UintTy::Usize => self.tcx.data_layout.pointer_size().unsigned_int_max(),
7171
UintTy::U8 => u8::MAX as u128,
7272
UintTy::U16 => u16::MAX as u128,
7373
UintTy::U32 => u32::MAX as u128,

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ pub(crate) fn codegen_drop<'tcx>(
786786

787787
pub(crate) fn lib_call_arg_param(tcx: TyCtxt<'_>, ty: Type, is_signed: bool) -> AbiParam {
788788
let param = AbiParam::new(ty);
789-
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size.bits() {
789+
if ty.is_int() && u64::from(ty.bits()) < tcx.data_layout.pointer_size().bits() {
790790
match (&*tcx.sess.target.arch, &*tcx.sess.target.vendor) {
791791
("x86_64", _) | ("aarch64", "apple") => match (ty, is_signed) {
792792
(types::I8 | types::I16, true) => param.sext(),

compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
127127
PassMode::Indirect { attrs, meta_attrs: None, on_stack } => {
128128
if on_stack {
129129
// Abi requires aligning struct size to pointer size
130-
let size = self.layout.size.align_to(tcx.data_layout.pointer_align.abi);
130+
let size = self.layout.size.align_to(tcx.data_layout.pointer_align().abi);
131131
let size = u32::try_from(size.bytes()).unwrap();
132132
smallvec![apply_attrs_to_abi_param(
133133
AbiParam::special(pointer_ty(tcx), ArgumentPurpose::StructArgument(size),),

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::debuginfo::FunctionDebugContext;
1515
use crate::prelude::*;
1616

1717
pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type {
18-
match tcx.data_layout.pointer_size.bits() {
18+
match tcx.data_layout.pointer_size().bits() {
1919
16 => types::I16,
2020
32 => types::I32,
2121
64 => types::I64,

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
443443
let addend = {
444444
let endianness = tcx.data_layout.endian;
445445
let offset = offset.bytes() as usize;
446-
let ptr_size = tcx.data_layout.pointer_size;
446+
let ptr_size = tcx.data_layout.pointer_size();
447447
let bytes = &alloc.inspect_with_uninit_and_ptr_outside_interpreter(
448448
offset..offset + ptr_size.bytes() as usize,
449449
);

compiler/rustc_codegen_gcc/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));

compiler/rustc_codegen_gcc/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
));

compiler/rustc_codegen_gcc/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

compiler/rustc_codegen_gcc/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) => {

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
175175
}
176176

177177
fn const_usize(&self, i: u64) -> &'ll Value {
178-
let bit_size = self.data_layout().pointer_size.bits();
178+
let bit_size = self.data_layout().pointer_size().bits();
179179
if bit_size < 64 {
180180
// make sure it doesn't overflow
181181
assert!(i < (1 << bit_size));

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
4343
}
4444
let mut llvals = Vec::with_capacity(alloc.provenance().ptrs().len() + 1);
4545
let dl = cx.data_layout();
46-
let pointer_size = dl.pointer_size.bytes() as usize;
46+
let pointer_size = dl.pointer_size();
47+
let pointer_size_bytes = pointer_size.bytes() as usize;
4748

4849
// Note: this function may call `inspect_with_uninit_and_ptr_outside_interpreter`, so `range`
4950
// must be within the bounds of `alloc` and not contain or overlap a pointer provenance.
@@ -100,7 +101,9 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
100101
// This `inspect` is okay since it is within the bounds of the allocation, it doesn't
101102
// affect interpreter execution (we inspect the result after interpreter execution),
102103
// and we properly interpret the provenance as a relocation pointer offset.
103-
alloc.inspect_with_uninit_and_ptr_outside_interpreter(offset..(offset + pointer_size)),
104+
alloc.inspect_with_uninit_and_ptr_outside_interpreter(
105+
offset..(offset + pointer_size_bytes),
106+
),
104107
)
105108
.expect("const_alloc_to_llvm: could not read relocation pointer")
106109
as u64;
@@ -111,11 +114,11 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
111114
InterpScalar::from_pointer(Pointer::new(prov, Size::from_bytes(ptr_offset)), &cx.tcx),
112115
Scalar::Initialized {
113116
value: Primitive::Pointer(address_space),
114-
valid_range: WrappingRange::full(dl.pointer_size),
117+
valid_range: WrappingRange::full(pointer_size),
115118
},
116119
cx.type_ptr_ext(address_space),
117120
));
118-
next_offset = offset + pointer_size;
121+
next_offset = offset + pointer_size_bytes;
119122
}
120123
if alloc.len() >= next_offset {
121124
let range = next_offset..alloc.len();

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
605605
GenericCx(
606606
FullCx {
607607
tcx,
608-
scx: SimpleCx::new(llmod, llcx, tcx.data_layout.pointer_size),
608+
scx: SimpleCx::new(llmod, llcx, tcx.data_layout.pointer_size()),
609609
use_dll_storage_attrs,
610610
tls_model,
611611
codegen_unit,

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
159159
return_if_di_node_created_in_meantime!(cx, unique_type_id);
160160

161161
let data_layout = &cx.tcx.data_layout;
162+
let pointer_size = data_layout.pointer_size();
163+
let pointer_align = data_layout.pointer_align();
162164
let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true);
163165

164166
match wide_pointer_kind(cx, pointee_type) {
165167
None => {
166168
// This is a thin pointer. Create a regular pointer type and give it the correct name.
167169
assert_eq!(
168-
(data_layout.pointer_size, data_layout.pointer_align.abi),
170+
(pointer_size, pointer_align.abi),
169171
cx.size_and_align_of(ptr_type),
170172
"ptr_type={ptr_type}, pointee_type={pointee_type}",
171173
);
@@ -174,8 +176,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
174176
llvm::LLVMRustDIBuilderCreatePointerType(
175177
DIB(cx),
176178
pointee_type_di_node,
177-
data_layout.pointer_size.bits(),
178-
data_layout.pointer_align.abi.bits() as u32,
179+
pointer_size.bits(),
180+
pointer_align.abi.bits() as u32,
179181
0, // Ignore DWARF address space.
180182
ptr_type_debuginfo_name.as_c_char_ptr(),
181183
ptr_type_debuginfo_name.len(),
@@ -319,7 +321,9 @@ fn build_subroutine_type_di_node<'ll, 'tcx>(
319321
let name = compute_debuginfo_type_name(cx.tcx, fn_ty, false);
320322
let (size, align) = match fn_ty.kind() {
321323
ty::FnDef(..) => (Size::ZERO, Align::ONE),
322-
ty::FnPtr(..) => (cx.tcx.data_layout.pointer_size, cx.tcx.data_layout.pointer_align.abi),
324+
ty::FnPtr(..) => {
325+
(cx.tcx.data_layout.pointer_size(), cx.tcx.data_layout.pointer_align().abi)
326+
}
323327
_ => unreachable!(),
324328
};
325329
let di_node = unsafe {
@@ -504,7 +508,7 @@ fn recursion_marker_type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) -> &'ll D
504508
create_basic_type(
505509
cx,
506510
"<recur_type>",
507-
cx.tcx.data_layout.pointer_size,
511+
cx.tcx.data_layout.pointer_size(),
508512
dwarf_const::DW_ATE_unsigned,
509513
)
510514
})

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
458458
// For rusty ABIs, small aggregates are actually passed
459459
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
460460
// so we re-use that same threshold here.
461-
layout.size() <= self.data_layout().pointer_size * 2
461+
layout.size() <= self.data_layout().pointer_size() * 2
462462
}
463463
};
464464

@@ -758,8 +758,8 @@ fn codegen_msvc_try<'ll, 'tcx>(
758758
// }
759759
//
760760
// More information can be found in libstd's seh.rs implementation.
761-
let ptr_size = bx.tcx().data_layout.pointer_size;
762-
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
761+
let ptr_size = bx.tcx().data_layout.pointer_size();
762+
let ptr_align = bx.tcx().data_layout.pointer_align().abi;
763763
let slot = bx.alloca(ptr_size, ptr_align);
764764
let try_func_ty = bx.type_func(&[bx.type_ptr()], bx.type_void());
765765
bx.invoke(try_func_ty, None, None, try_func, &[data], normal, catchswitch, None, None);
@@ -1031,8 +1031,8 @@ fn codegen_emcc_try<'ll, 'tcx>(
10311031

10321032
// We need to pass two values to catch_func (ptr and is_rust_panic), so
10331033
// create an alloca and pass a pointer to that.
1034-
let ptr_size = bx.tcx().data_layout.pointer_size;
1035-
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
1034+
let ptr_size = bx.tcx().data_layout.pointer_size();
1035+
let ptr_align = bx.tcx().data_layout.pointer_align().abi;
10361036
let i8_align = bx.tcx().data_layout.i8_align.abi;
10371037
// Required in order for there to be no padding between the fields.
10381038
assert!(i8_align <= ptr_align);
@@ -1158,9 +1158,11 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
11581158
macro_rules! require_int_or_uint_ty {
11591159
($ty: expr, $diag: expr) => {
11601160
match $ty {
1161-
ty::Int(i) => i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size.bits()),
1161+
ty::Int(i) => {
1162+
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size().bits())
1163+
}
11621164
ty::Uint(i) => {
1163-
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size.bits())
1165+
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size().bits())
11641166
}
11651167
_ => {
11661168
return_error!($diag);
@@ -2014,10 +2016,10 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
20142016
} else {
20152017
let bitwidth = match in_elem.kind() {
20162018
ty::Int(i) => {
2017-
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size.bits())
2019+
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size().bits())
20182020
}
20192021
ty::Uint(i) => {
2020-
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size.bits())
2022+
i.bit_width().unwrap_or_else(|| bx.data_layout().pointer_size().bits())
20212023
}
20222024
_ => return_error!(InvalidMonomorphization::UnsupportedSymbol {
20232025
span,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
113113
) -> ModuleLlvm {
114114
let module_llvm = ModuleLlvm::new_metadata(tcx, module_name);
115115
let cx =
116-
SimpleCx::new(module_llvm.llmod(), &module_llvm.llcx, tcx.data_layout.pointer_size);
116+
SimpleCx::new(module_llvm.llmod(), &module_llvm.llcx, tcx.data_layout.pointer_size());
117117
unsafe {
118118
allocator::codegen(tcx, cx, module_name, kind, alloc_error_handler_kind);
119119
}

compiler/rustc_codegen_llvm/src/type_.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'ll, CX: Borrow<SCx<'ll>>> BaseTypeCodegenMethods for GenericCx<'ll, CX> {
208208
}
209209

210210
fn type_ptr(&self) -> &'ll Type {
211-
self.type_ptr_ext(AddressSpace::DATA)
211+
self.type_ptr_ext(AddressSpace::ZERO)
212212
}
213213

214214
fn type_ptr_ext(&self, address_space: AddressSpace) -> &'ll Type {
@@ -258,7 +258,7 @@ impl Type {
258258
}
259259

260260
pub(crate) fn ptr_llcx(llcx: &llvm::Context) -> &Type {
261-
unsafe { llvm::LLVMPointerTypeInContext(llcx, AddressSpace::DATA.0) }
261+
unsafe { llvm::LLVMPointerTypeInContext(llcx, AddressSpace::ZERO.0) }
262262
}
263263
}
264264

0 commit comments

Comments
 (0)