Skip to content

Commit

Permalink
Replace the AddressSpace::default() implementation with impl const Ad…
Browse files Browse the repository at this point in the history
…dressSpace::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.
  • Loading branch information
dylanmckay committed Jun 19, 2020
1 parent a440aec commit 336322c
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 44 deletions.
5 changes: 2 additions & 3 deletions src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_llvm_type(cx),
PassMode::Cast(cast) => cast.llvm_type(cx),
PassMode::Indirect(..) => {
llargument_tys
.push(cx.type_ptr_to(self.ret.memory_ty(cx), AddressSpace::default()));
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx), AddressSpace::DATA));
cx.type_void()
}
};
Expand Down Expand Up @@ -353,7 +352,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
}
PassMode::Cast(cast) => cast.llvm_type(cx),
PassMode::Indirect(_, None) => {
cx.type_ptr_to(arg.memory_ty(cx), AddressSpace::default())
cx.type_ptr_to(arg.memory_ty(cx), AddressSpace::DATA)
}
};
llargument_tys.push(llarg_ty);
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_codegen_llvm/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let len = s.as_str().len();
let cs = consts::ptrcast(
self.const_cstr(s, false),
self.type_ptr_to(
self.layout_of(self.tcx.mk_str()).llvm_type(self),
AddressSpace::default(),
),
self.type_ptr_to(self.layout_of(self.tcx.mk_str()).llvm_type(self), AddressSpace::DATA),
);
(cs, self.const_usize(len as u64))
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn codegen_static_initializer(
let address_space = if cx.tcx.type_of(def_id).is_fn() {
cx.data_layout().instruction_address_space
} else {
AddressSpace::default()
AddressSpace::DATA
};

let alloc = match cx.tcx.const_eval_poly(def_id)? {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_llvm/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
let name = const_cstr!("llvm.used");
let section = const_cstr!("llvm.metadata");
let array = self.const_array(
&self.type_ptr_to(self.type_i8(), AddressSpace::default()),
&self.type_ptr_to(self.type_i8(), AddressSpace::DATA),
&*self.used_statics.borrow(),
);

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

let i8p = self.type_i8p(AddressSpace::default());
let i8p = self.type_i8p(AddressSpace::DATA);
let void = self.type_void();
let i1 = self.type_i1();
let t_i8 = self.type_i8();
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ fn codegen_msvc_try(
//
// More information can be found in libstd's seh.rs implementation.
let ptr_align = bx.tcx().data_layout.pointer_align.abi;
let slot = bx.alloca(bx.type_i8p(AddressSpace::default()), ptr_align);
let slot = bx.alloca(bx.type_i8p(AddressSpace::DATA), ptr_align);
bx.invoke(try_func, &[data], normal.llbb(), catchswitch.llbb(), None);

normal.ret(bx.const_i32(0));
Expand All @@ -956,10 +956,10 @@ fn codegen_msvc_try(
// When modifying, make sure that the type_name string exactly matches
// the one used in src/libpanic_unwind/seh.rs.
let type_info_vtable =
bx.declare_global("??_7type_info@@6B@", bx.type_i8p(AddressSpace::default()));
bx.declare_global("??_7type_info@@6B@", bx.type_i8p(AddressSpace::DATA));
let type_name = bx.const_bytes(b"rust_panic\0");
let type_info = bx.const_struct(
&[type_info_vtable, bx.const_null(bx.type_i8p(AddressSpace::default())), type_name],
&[type_info_vtable, bx.const_null(bx.type_i8p(AddressSpace::DATA)), type_name],
false,
);
let tydesc = bx.declare_global("__rust_panic_type_info", bx.val_ty(type_info));
Expand Down Expand Up @@ -1041,14 +1041,14 @@ fn codegen_gnu_try(
// being thrown. The second value is a "selector" indicating which of
// the landing pad clauses the exception's type had been matched to.
// rust_try ignores the selector.
let lpad_ty = bx.type_struct(&[bx.type_i8p(AddressSpace::default()), bx.type_i32()], false);
let lpad_ty = bx.type_struct(&[bx.type_i8p(AddressSpace::DATA), bx.type_i32()], false);
let vals = catch.landing_pad(lpad_ty, bx.eh_personality(), 1);
let tydesc = match bx.tcx().lang_items().eh_catch_typeinfo() {
Some(tydesc) => {
let tydesc = bx.get_static(tydesc);
bx.bitcast(tydesc, bx.type_i8p(bx.cx().address_space_of_value(tydesc)))
}
None => bx.const_null(bx.type_i8p(AddressSpace::default())),
None => bx.const_null(bx.type_i8p(AddressSpace::DATA)),
};
catch.add_clause(vals, tydesc);
let ptr = catch.extract_value(vals, 0);
Expand Down Expand Up @@ -1540,7 +1540,7 @@ fn generic_simd_intrinsic(
_ => unreachable!(),
};
while no_pointers > 0 {
elem_ty = cx.type_ptr_to(elem_ty, AddressSpace::default());
elem_ty = cx.type_ptr_to(elem_ty, AddressSpace::DATA);
no_pointers -= 1;
}
cx.type_vector(elem_ty, vec_len)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ impl Type {
}

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

fn ptr_to(&self, address_space: AddressSpace) -> &Type {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,11 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
}
let llty = match self.ty.kind {
ty::Ref(_, ty, _) | ty::RawPtr(ty::TypeAndMut { ty, .. }) => {
cx.type_ptr_to(cx.layout_of(ty).llvm_type(cx), AddressSpace::default())
cx.type_ptr_to(cx.layout_of(ty).llvm_type(cx), AddressSpace::DATA)
}
ty::Adt(def, _) if def.is_box() => cx.type_ptr_to(
cx.layout_of(self.ty.boxed_ty()).llvm_type(cx),
AddressSpace::default(),
AddressSpace::DATA,
),
ty::FnPtr(sig) => cx.fn_ptr_backend_type(&FnAbi::of_fn_ptr(cx, sig, &[])),
_ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO),
Expand Down Expand Up @@ -315,7 +315,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
if let Some(pointee) = self.pointee_info_at(cx, offset) {
(cx.type_pointee_for_align(pointee.align), pointee.address_space)
} else {
(cx.type_i8(), AddressSpace::default())
(cx.type_i8(), AddressSpace::DATA)
};
cx.type_ptr_to(pointee, address_space)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_codegen_llvm/va_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn emit_direct_ptr_va_arg(
allow_higher_align: bool,
) -> (&'ll Value, Align) {
let va_list_ptr_ty =
bx.cx().type_ptr_to(bx.cx.type_i8p(AddressSpace::default()), AddressSpace::default());
bx.cx().type_ptr_to(bx.cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA);
let va_list_addr = if list.layout.llvm_type(bx.cx) != va_list_ptr_ty {
bx.bitcast(list.immediate(), va_list_ptr_ty)
} else {
Expand Down Expand Up @@ -64,9 +64,9 @@ fn emit_direct_ptr_va_arg(
if size.bytes() < slot_size.bytes() && &*bx.tcx().sess.target.target.target_endian == "big" {
let adjusted_size = bx.cx().const_i32((slot_size.bytes() - size.bytes()) as i32);
let adjusted = bx.inbounds_gep(addr, &[adjusted_size]);
(bx.bitcast(adjusted, bx.cx().type_ptr_to(llty, AddressSpace::default())), addr_align)
(bx.bitcast(adjusted, bx.cx().type_ptr_to(llty, AddressSpace::DATA)), addr_align)
} else {
(bx.bitcast(addr, bx.cx().type_ptr_to(llty, AddressSpace::default())), addr_align)
(bx.bitcast(addr, bx.cx().type_ptr_to(llty, AddressSpace::DATA)), addr_align)
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
cx.type_func(
&[
cx.type_int(),
cx.type_ptr_to(cx.type_i8p(AddressSpace::default()), AddressSpace::default()),
cx.type_ptr_to(cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA),
],
cx.type_int(),
)
Expand Down Expand Up @@ -520,9 +520,8 @@ fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
} else {
// The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
let arg_argc = bx.const_int(cx.type_int(), 0);
let arg_argv = bx.const_null(
cx.type_ptr_to(cx.type_i8p(AddressSpace::default()), AddressSpace::default()),
);
let arg_argv =
bx.const_null(cx.type_ptr_to(cx.type_i8p(AddressSpace::DATA), AddressSpace::DATA));
(arg_argc, arg_argv)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/meth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a, 'tcx> VirtualIndex {

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

let llvtable =
bx.pointercast(llvtable, bx.type_ptr_to(bx.type_isize(), AddressSpace::default()));
bx.pointercast(llvtable, bx.type_ptr_to(bx.type_isize(), AddressSpace::DATA));
let usize_align = bx.tcx().data_layout.pointer_align.abi;
let gep = bx.inbounds_gep(llvtable, &[bx.const_usize(self.0)]);
let ptr = bx.load(gep, usize_align);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let address_space = if fn_abi.ret.layout.ty.is_fn() {
bx.cx().data_layout().instruction_address_space
} else {
AddressSpace::default()
AddressSpace::DATA
};
bx.const_undef(bx.type_ptr_to(backend_type, address_space))
}
Expand Down Expand Up @@ -1263,7 +1263,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {

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

fn unreachable_block(&mut self) -> Bx::BasicBlock {
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_codegen_ssa/traits/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
}

fn default_address_space_of_type(&self, ty: Ty<'tcx>) -> AddressSpace {
if ty.is_fn() {
self.data_layout().instruction_address_space
} else {
AddressSpace::default()
}
if ty.is_fn() { self.data_layout().instruction_address_space } else { AddressSpace::DATA }
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,11 +2147,7 @@ where

fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option<PointeeInfo> {
let addr_space_of_ty = |ty: Ty<'tcx>| {
if ty.is_fn() {
cx.data_layout().instruction_address_space
} else {
AddressSpace::default()
}
if ty.is_fn() { cx.data_layout().instruction_address_space } else { AddressSpace::DATA }
};

let pointee_info = match this.ty.kind {
Expand Down Expand Up @@ -2282,7 +2278,10 @@ where
}
};

debug!("pointee_info_at (offset={:?}, type kind: {:?}) => {:?}", offset, this.ty.kind, pointee_info);
debug!(
"pointee_info_at (offset={:?}, type kind: {:?}) => {:?}",
offset, this.ty.kind, pointee_info
);

pointee_info
}
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_target/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Default for TargetDataLayout {
(Size::from_bits(64), AbiAndPrefAlign::new(align(64))),
(Size::from_bits(128), AbiAndPrefAlign::new(align(128))),
],
instruction_address_space: AddressSpace::default(),
instruction_address_space: AddressSpace::DATA,
}
}
}
Expand Down Expand Up @@ -752,9 +752,14 @@ impl FieldsShape {
/// An identifier that specifies the address space that some operation
/// should operate on. Special address spaces have an effect on code generation,
/// depending on the target and the address spaces it implements.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct AddressSpace(pub u32);

impl AddressSpace {
/// The default address space, corresponding to data space.
pub const DATA: Self = AddressSpace(0);
}

/// Describes how values of the type are passed by target ABIs,
/// in terms of categories of C types there are ABI rules for.
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
Expand Down

0 comments on commit 336322c

Please sign in to comment.