diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index ce4f82bf73409..cd0928734a368 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -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() } }; @@ -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); diff --git a/src/librustc_codegen_llvm/common.rs b/src/librustc_codegen_llvm/common.rs index 5b71719483b1d..3e82a2db5c772 100644 --- a/src/librustc_codegen_llvm/common.rs +++ b/src/librustc_codegen_llvm/common.rs @@ -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)) } diff --git a/src/librustc_codegen_llvm/consts.rs b/src/librustc_codegen_llvm/consts.rs index 059b3dd1186a3..3379fce3beb96 100644 --- a/src/librustc_codegen_llvm/consts.rs +++ b/src/librustc_codegen_llvm/consts.rs @@ -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)? { diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 56356a0b53442..929aa229aee24 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -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(), ); @@ -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(); diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index f0c5b8b8f12b3..a26aa0005ec33 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -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)); @@ -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)); @@ -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); @@ -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) diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index b88420d281706..9bc4a1daf5f6f 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -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 { diff --git a/src/librustc_codegen_llvm/type_of.rs b/src/librustc_codegen_llvm/type_of.rs index e0fc05eb2b9bf..a854b89219ee8 100644 --- a/src/librustc_codegen_llvm/type_of.rs +++ b/src/librustc_codegen_llvm/type_of.rs @@ -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), @@ -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) } diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 8d4801ad4353c..fe545db7b7b26 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -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 { @@ -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) } } diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index eade0c4c94f94..3b8c7a20746ae 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -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(), ) @@ -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) } } diff --git a/src/librustc_codegen_ssa/meth.rs b/src/librustc_codegen_ssa/meth.rs index 7aa873f6c8f72..af441defad777 100644 --- a/src/librustc_codegen_ssa/meth.rs +++ b/src/librustc_codegen_ssa/meth.rs @@ -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)]); @@ -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); diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index 93a6fc7b0f47d..fe9a7bca3f6d4 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -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)) } @@ -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 { diff --git a/src/librustc_codegen_ssa/traits/type_.rs b/src/librustc_codegen_ssa/traits/type_.rs index aad1da9b38cfa..0631289cf9e98 100644 --- a/src/librustc_codegen_ssa/traits/type_.rs +++ b/src/librustc_codegen_ssa/traits/type_.rs @@ -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 } } } diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index c091a7575722b..e86f8622d8a56 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -2147,11 +2147,7 @@ where fn pointee_info_at(this: TyAndLayout<'tcx>, cx: &C, offset: Size) -> Option { 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 { @@ -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 } diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index fe25080dc287f..f3e1557e4f7e9 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -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, } } } @@ -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)]