Skip to content

Commit 7fcd433

Browse files
committed
Replace the AddressSpace::default() implementation with impl const AddressSpace::DATA
This makes a clearer disambiguation between data space and program space. The default address space '0' always was the data address space, but this naming convention makes what it actually represents clearer.
1 parent 05f3336 commit 7fcd433

File tree

14 files changed

+35
-40
lines changed

14 files changed

+35
-40
lines changed

Diff for: src/librustc_codegen_llvm/abi.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
324324
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_llvm_type(cx),
325325
PassMode::Cast(cast) => cast.llvm_type(cx),
326326
PassMode::Indirect(..) => {
327-
llargument_tys
328-
.push(cx.type_ptr_to(self.ret.memory_ty(cx), AddressSpace::default()));
327+
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx), AddressSpace::DATA));
329328
cx.type_void()
330329
}
331330
};
@@ -353,7 +352,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
353352
}
354353
PassMode::Cast(cast) => cast.llvm_type(cx),
355354
PassMode::Indirect(_, None) => {
356-
cx.type_ptr_to(arg.memory_ty(cx), AddressSpace::default())
355+
cx.type_ptr_to(arg.memory_ty(cx), AddressSpace::DATA)
357356
}
358357
};
359358
llargument_tys.push(llarg_ty);

Diff for: src/librustc_codegen_llvm/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
208208
self.const_cstr(s, false),
209209
self.type_ptr_to(
210210
self.layout_of(self.tcx.types.str_).llvm_type(self),
211-
AddressSpace::default(),
211+
AddressSpace::DATA,
212212
),
213213
);
214214
(cs, self.const_usize(len as u64))

Diff for: src/librustc_codegen_llvm/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn codegen_static_initializer(
8686
let address_space = if cx.tcx.type_of(def_id).is_fn() {
8787
cx.data_layout().instruction_address_space
8888
} else {
89-
AddressSpace::default()
89+
AddressSpace::DATA
9090
};
9191

9292
let alloc = match cx.tcx.const_eval_poly(def_id)? {

Diff for: src/librustc_codegen_llvm/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
395395
let name = const_cstr!("llvm.used");
396396
let section = const_cstr!("llvm.metadata");
397397
let array = self.const_array(
398-
&self.type_ptr_to(self.type_i8(), AddressSpace::default()),
398+
&self.type_ptr_to(self.type_i8(), AddressSpace::DATA),
399399
&*self.used_statics.borrow(),
400400
);
401401

@@ -456,7 +456,7 @@ impl CodegenCx<'b, 'tcx> {
456456
($($field_ty:expr),*) => (self.type_struct( &[$($field_ty),*], false))
457457
}
458458

459-
let i8p = self.type_i8p(AddressSpace::default());
459+
let i8p = self.type_i8p(AddressSpace::DATA);
460460
let void = self.type_void();
461461
let i1 = self.type_i1();
462462
let t_i8 = self.type_i8();

Diff for: src/librustc_codegen_llvm/intrinsic.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ fn codegen_msvc_try(
933933
//
934934
// More information can be found in libstd's seh.rs implementation.
935935
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
936-
let slot = bx.alloca(bx.type_i8p(AddressSpace::default()), ptr_align);
936+
let slot = bx.alloca(bx.type_i8p(AddressSpace::DATA), ptr_align);
937937
bx.invoke(try_func, &[data], normal.llbb(), catchswitch.llbb(), None);
938938

939939
normal.ret(bx.const_i32(0));
@@ -956,10 +956,10 @@ fn codegen_msvc_try(
956956
// When modifying, make sure that the type_name string exactly matches
957957
// the one used in src/libpanic_unwind/seh.rs.
958958
let type_info_vtable =
959-
bx.declare_global("??_7type_info@@6B@", bx.type_i8p(AddressSpace::default()));
959+
bx.declare_global("??_7type_info@@6B@", bx.type_i8p(AddressSpace::DATA));
960960
let type_name = bx.const_bytes(b"rust_panic\0");
961961
let type_info = bx.const_struct(
962-
&[type_info_vtable, bx.const_null(bx.type_i8p(AddressSpace::default())), type_name],
962+
&[type_info_vtable, bx.const_null(bx.type_i8p(AddressSpace::DATA)), type_name],
963963
false,
964964
);
965965
let tydesc = bx.declare_global("__rust_panic_type_info", bx.val_ty(type_info));
@@ -1041,14 +1041,14 @@ fn codegen_gnu_try(
10411041
// being thrown. The second value is a "selector" indicating which of
10421042
// the landing pad clauses the exception's type had been matched to.
10431043
// rust_try ignores the selector.
1044-
let lpad_ty = bx.type_struct(&[bx.type_i8p(AddressSpace::default()), bx.type_i32()], false);
1044+
let lpad_ty = bx.type_struct(&[bx.type_i8p(AddressSpace::DATA), bx.type_i32()], false);
10451045
let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 1);
10461046
let tydesc = match bx.tcx().lang_items().eh_catch_typeinfo() {
10471047
Some(tydesc) => {
10481048
let tydesc = bx.get_static(tydesc);
10491049
bx.bitcast(tydesc, bx.type_i8p(bx.cx().address_space_of_value(tydesc)))
10501050
}
1051-
None => bx.const_null(bx.type_i8p(AddressSpace::default())),
1051+
None => bx.const_null(bx.type_i8p(AddressSpace::DATA)),
10521052
};
10531053
catch.add_clause(vals, tydesc);
10541054
let ptr = catch.extract_value(vals, 0);
@@ -1540,7 +1540,7 @@ fn generic_simd_intrinsic(
15401540
_ => unreachable!(),
15411541
};
15421542
while no_pointers > 0 {
1543-
elem_ty = cx.type_ptr_to(elem_ty, AddressSpace::default());
1543+
elem_ty = cx.type_ptr_to(elem_ty, AddressSpace::DATA);
15441544
no_pointers -= 1;
15451545
}
15461546
cx.type_vector(elem_ty, vec_len)

Diff for: src/librustc_codegen_llvm/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl Type {
264264
}
265265

266266
pub fn i8p_llcx(llcx: &llvm::Context) -> &Type {
267-
Type::i8_llcx(llcx).ptr_to(AddressSpace::default())
267+
Type::i8_llcx(llcx).ptr_to(AddressSpace::DATA)
268268
}
269269

270270
fn ptr_to(&self, address_space: AddressSpace) -> &Type {

Diff for: src/librustc_codegen_llvm/type_of.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
238238
}
239239
let llty = match self.ty.kind {
240240
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
241-
cx.type_ptr_to(cx.layout_of(ty).llvm_type(cx), AddressSpace::default())
241+
cx.type_ptr_to(cx.layout_of(ty).llvm_type(cx), AddressSpace::DATA)
242242
}
243243
ty::Adt(def, _) if def.is_box() => cx.type_ptr_to(
244244
cx.layout_of(self.ty.boxed_ty()).llvm_type(cx),
245-
AddressSpace::default(),
245+
AddressSpace::DATA,
246246
),
247247
ty::FnPtr(sig) => cx.fn_ptr_backend_type(&FnAbi::of_fn_ptr(cx, sig, &[])),
248248
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO),
@@ -315,7 +315,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
315315
if let Some(pointee) = self.pointee_info_at(cx, offset) {
316316
(cx.type_pointee_for_align(pointee.align), pointee.address_space)
317317
} else {
318-
(cx.type_i8(), AddressSpace::default())
318+
(cx.type_i8(), AddressSpace::DATA)
319319
};
320320
cx.type_ptr_to(pointee, address_space)
321321
}

Diff for: src/librustc_codegen_llvm/va_arg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn emit_direct_ptr_va_arg(
3333
allow_higher_align: bool,
3434
) -> (&'ll Value, Align) {
3535
let va_list_ptr_ty =
36-
bx.cx().type_ptr_to(bx.cx.type_i8p(AddressSpace::default()), AddressSpace::default());
36+
bx.cx().type_ptr_to(bx.cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA);
3737
let va_list_addr = if list.layout.llvm_type(bx.cx) != va_list_ptr_ty {
3838
bx.bitcast(list.immediate(), va_list_ptr_ty)
3939
} else {
@@ -64,9 +64,9 @@ fn emit_direct_ptr_va_arg(
6464
if size.bytes() < slot_size.bytes() && &*bx.tcx().sess.target.target.target_endian == "big" {
6565
let adjusted_size = bx.cx().const_i32((slot_size.bytes() - size.bytes()) as i32);
6666
let adjusted = bx.inbounds_gep(addr, &[adjusted_size]);
67-
(bx.bitcast(adjusted, bx.cx().type_ptr_to(llty, AddressSpace::default())), addr_align)
67+
(bx.bitcast(adjusted, bx.cx().type_ptr_to(llty, AddressSpace::DATA)), addr_align)
6868
} else {
69-
(bx.bitcast(addr, bx.cx().type_ptr_to(llty, AddressSpace::default())), addr_align)
69+
(bx.bitcast(addr, bx.cx().type_ptr_to(llty, AddressSpace::DATA)), addr_align)
7070
}
7171
}
7272

Diff for: src/librustc_codegen_ssa/base.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
429429
cx.type_func(
430430
&[
431431
cx.type_int(),
432-
cx.type_ptr_to(cx.type_i8p(AddressSpace::default()), AddressSpace::default()),
432+
cx.type_ptr_to(cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA),
433433
],
434434
cx.type_int(),
435435
)
@@ -520,9 +520,8 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
520520
} else {
521521
// The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
522522
let arg_argc = bx.const_int(cx.type_int(), 0);
523-
let arg_argv = bx.const_null(
524-
cx.type_ptr_to(cx.type_i8p(AddressSpace::default()), AddressSpace::default()),
525-
);
523+
let arg_argv =
524+
bx.const_null(cx.type_ptr_to(cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA));
526525
(arg_argc, arg_argv)
527526
}
528527
}

Diff for: src/librustc_codegen_ssa/meth.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'a, 'tcx> VirtualIndex {
2727

2828
let llvtable = bx.pointercast(
2929
llvtable,
30-
bx.type_ptr_to(bx.fn_ptr_backend_type(fn_abi), AddressSpace::default()),
30+
bx.type_ptr_to(bx.fn_ptr_backend_type(fn_abi), AddressSpace::DATA),
3131
);
3232
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
3333
let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);
@@ -47,7 +47,7 @@ impl<'a, 'tcx> VirtualIndex {
4747
debug!("get_int({:?}, {:?})", llvtable, self);
4848

4949
let llvtable =
50-
bx.pointercast(llvtable, bx.type_ptr_to(bx.type_isize(), AddressSpace::default()));
50+
bx.pointercast(llvtable, bx.type_ptr_to(bx.type_isize(), AddressSpace::DATA));
5151
let usize_align = bx.tcx().data_layout.pointer_align.abi;
5252
let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);
5353
let ptr = bx.load(gep, usize_align);

Diff for: src/librustc_codegen_ssa/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
662662
let address_space = if fn_abi.ret.layout.ty.is_fn() {
663663
bx.cx().data_layout().instruction_address_space
664664
} else {
665-
AddressSpace::default()
665+
AddressSpace::DATA
666666
};
667667
bx.const_undef(bx.type_ptr_to(backend_type, address_space))
668668
}
@@ -1263,7 +1263,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12631263

12641264
fn landing_pad_type(&self) -> Bx::Type {
12651265
let cx = self.cx;
1266-
cx.type_struct(&[cx.type_i8p(AddressSpace::default()), cx.type_i32()], false)
1266+
cx.type_struct(&[cx.type_i8p(AddressSpace::DATA), cx.type_i32()], false)
12671267
}
12681268

12691269
fn unreachable_block(&mut self) -> Bx::BasicBlock {

Diff for: src/librustc_codegen_ssa/traits/type_.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
9898
}
9999

100100
fn default_address_space_of_type(&self, ty: Ty<'tcx>) -> AddressSpace {
101-
if ty.is_fn() {
102-
self.data_layout().instruction_address_space
103-
} else {
104-
AddressSpace::default()
105-
}
101+
if ty.is_fn() { self.data_layout().instruction_address_space } else { AddressSpace::DATA }
106102
}
107103
}
108104

Diff for: src/librustc_middle/ty/layout.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2149,11 +2149,7 @@ where
21492149

21502150
fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> {
21512151
let addr_space_of_ty = |ty: Ty<'tcx>| {
2152-
if ty.is_fn() {
2153-
cx.data_layout().instruction_address_space
2154-
} else {
2155-
AddressSpace::default()
2156-
}
2152+
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA }
21572153
};
21582154

21592155
let pointee_info = match this.ty.kind {

Diff for: src/librustc_target/abi/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Default for TargetDataLayout {
5656
(Size::from_bits(64), AbiAndPrefAlign::new(align(64))),
5757
(Size::from_bits(128), AbiAndPrefAlign::new(align(128))),
5858
],
59-
instruction_address_space: AddressSpace::default(),
59+
instruction_address_space: AddressSpace::DATA,
6060
}
6161
}
6262
}
@@ -752,9 +752,14 @@ impl FieldsShape {
752752
/// An identifier that specifies the address space that some operation
753753
/// should operate on. Special address spaces have an effect on code generation,
754754
/// depending on the target and the address spaces it implements.
755-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
755+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
756756
pub struct AddressSpace(pub u32);
757757

758+
impl AddressSpace {
759+
/// The default address space, corresponding to data space.
760+
pub const DATA: Self = AddressSpace(0);
761+
}
762+
758763
/// Describes how values of the type are passed by target ABIs,
759764
/// in terms of categories of C types there are ABI rules for.
760765
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]

0 commit comments

Comments
 (0)