Skip to content

Commit 837eff9

Browse files
cg_ssa, cg_llvm: remove pointee types
1 parent 023b513 commit 837eff9

File tree

21 files changed

+143
-191
lines changed

21 files changed

+143
-191
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
226226
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
227227
let can_store_through_cast_ptr = false;
228228
if can_store_through_cast_ptr {
229-
let cast_ptr_llty = bx.type_ptr_to(cast.llvm_type(bx));
229+
let cast_ptr_llty = bx.type_ptr();
230230
let cast_dst = bx.pointercast(dst.llval, cast_ptr_llty);
231231
bx.store(val, cast_dst, self.layout.align.abi);
232232
} else {
@@ -346,7 +346,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
346346
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_llvm_type(cx),
347347
PassMode::Cast(cast, _) => cast.llvm_type(cx),
348348
PassMode::Indirect { .. } => {
349-
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
349+
llargument_tys.push(cx.type_ptr());
350350
cx.type_void()
351351
}
352352
};
@@ -374,9 +374,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
374374
}
375375
cast.llvm_type(cx)
376376
}
377-
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
378-
cx.type_ptr_to(arg.memory_ty(cx))
379-
}
377+
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => cx.type_ptr(),
380378
};
381379
llargument_tys.push(llarg_ty);
382380
}
@@ -389,12 +387,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
389387
}
390388

391389
fn ptr_to_llvm_type(&self, cx: &CodegenCx<'ll, 'tcx>) -> &'ll Type {
392-
unsafe {
393-
llvm::LLVMPointerType(
394-
self.llvm_type(cx),
395-
cx.data_layout().instruction_address_space.0 as c_uint,
396-
)
397-
}
390+
cx.type_ptr_in(cx.data_layout().instruction_address_space)
398391
}
399392

400393
fn llvm_cconv(&self) -> llvm::CallConv {

compiler/rustc_codegen_llvm/src/allocator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) unsafe fn codegen(
2626
tws => bug!("Unsupported target word size for int: {}", tws),
2727
};
2828
let i8 = llvm::LLVMInt8TypeInContext(llcx);
29-
let i8p = llvm::LLVMPointerType(i8, 0);
29+
let i8p = llvm::LLVMPointerTypeInContext(llcx, 0);
3030
let void = llvm::LLVMVoidTypeInContext(llcx);
3131

3232
for method in ALLOCATOR_METHODS {

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ fn create_msvc_imps(
927927
let prefix = if cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" };
928928

929929
unsafe {
930-
let i8p_ty = Type::i8p_llcx(llcx);
930+
let ptr_ty = Type::ptr_llcx(llcx);
931931
let globals = base::iter_globals(llmod)
932932
.filter(|&val| {
933933
llvm::LLVMRustGetLinkage(val) == llvm::Linkage::ExternalLinkage
@@ -947,8 +947,8 @@ fn create_msvc_imps(
947947
.collect::<Vec<_>>();
948948

949949
for (imp_name, val) in globals {
950-
let imp = llvm::LLVMAddGlobal(llmod, i8p_ty, imp_name.as_ptr().cast());
951-
llvm::LLVMSetInitializer(imp, consts::ptrcast(val, i8p_ty));
950+
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr().cast());
951+
llvm::LLVMSetInitializer(imp, consts::ptrcast(val, ptr_ty));
952952
llvm::LLVMRustSetLinkage(imp, llvm::Linkage::ExternalLinkage);
953953
}
954954
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
641641
flags: MemFlags,
642642
) -> &'ll Value {
643643
debug!("Store {:?} -> {:?} ({:?})", val, ptr, flags);
644-
let ptr = self.check_store(val, ptr);
644+
let ptr = self.check_store(ptr);
645645
unsafe {
646646
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
647647
let align =
@@ -671,7 +671,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
671671
size: Size,
672672
) {
673673
debug!("Store {:?} -> {:?}", val, ptr);
674-
let ptr = self.check_store(val, ptr);
674+
let ptr = self.check_store(ptr);
675675
unsafe {
676676
let store = llvm::LLVMRustBuildAtomicStore(
677677
self.llbuilder,
@@ -854,8 +854,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
854854
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memcpy not supported");
855855
let size = self.intcast(size, self.type_isize(), false);
856856
let is_volatile = flags.contains(MemFlags::VOLATILE);
857-
let dst = self.pointercast(dst, self.type_i8p());
858-
let src = self.pointercast(src, self.type_i8p());
857+
let dst = self.pointercast(dst, self.type_ptr());
858+
let src = self.pointercast(src, self.type_ptr());
859859
unsafe {
860860
llvm::LLVMRustBuildMemCpy(
861861
self.llbuilder,
@@ -881,8 +881,8 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
881881
assert!(!flags.contains(MemFlags::NONTEMPORAL), "non-temporal memmove not supported");
882882
let size = self.intcast(size, self.type_isize(), false);
883883
let is_volatile = flags.contains(MemFlags::VOLATILE);
884-
let dst = self.pointercast(dst, self.type_i8p());
885-
let src = self.pointercast(src, self.type_i8p());
884+
let dst = self.pointercast(dst, self.type_ptr());
885+
let src = self.pointercast(src, self.type_ptr());
886886
unsafe {
887887
llvm::LLVMRustBuildMemMove(
888888
self.llbuilder,
@@ -905,7 +905,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
905905
flags: MemFlags,
906906
) {
907907
let is_volatile = flags.contains(MemFlags::VOLATILE);
908-
let ptr = self.pointercast(ptr, self.type_i8p());
908+
let ptr = self.pointercast(ptr, self.type_ptr());
909909
unsafe {
910910
llvm::LLVMRustBuildMemSet(
911911
self.llbuilder,
@@ -1130,7 +1130,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
11301130

11311131
let llfn = unsafe { llvm::LLVMRustGetInstrProfIncrementIntrinsic(self.cx().llmod) };
11321132
let llty = self.cx.type_func(
1133-
&[self.cx.type_i8p(), self.cx.type_i64(), self.cx.type_i32(), self.cx.type_i32()],
1133+
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32(), self.cx.type_i32()],
11341134
self.cx.type_void(),
11351135
);
11361136
let args = &[fn_name, hash, num_counters, index];
@@ -1340,10 +1340,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
13401340
ret.expect("LLVM does not have support for catchret")
13411341
}
13421342

1343-
fn check_store(&mut self, val: &'ll Value, ptr: &'ll Value) -> &'ll Value {
1343+
fn check_store(&mut self, ptr: &'ll Value) -> &'ll Value {
13441344
let dest_ptr_ty = self.cx.val_ty(ptr);
1345-
let stored_ty = self.cx.val_ty(val);
1346-
let stored_ptr_ty = self.cx.type_ptr_to(stored_ty);
1345+
let stored_ptr_ty = self.cx.type_ptr();
13471346

13481347
assert_eq!(self.cx.type_kind(dest_ptr_ty), TypeKind::Pointer);
13491348

@@ -1421,7 +1420,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
14211420
return;
14221421
}
14231422

1424-
let ptr = self.pointercast(ptr, self.cx.type_i8p());
1423+
let ptr = self.pointercast(ptr, self.cx.type_ptr());
14251424
self.call_intrinsic(intrinsic, &[self.cx.const_u64(size), ptr]);
14261425
}
14271426

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::consts::{self, const_alloc_to_llvm};
44
pub use crate::context::CodegenCx;
55
use crate::llvm::{self, BasicBlock, Bool, ConstantInt, False, OperandBundleDef, True};
66
use crate::type_::Type;
7-
use crate::type_of::LayoutLlvmExt;
87
use crate::value::Value;
98

109
use rustc_ast::Mutability;
@@ -13,7 +12,7 @@ use rustc_codegen_ssa::traits::*;
1312
use rustc_hir::def_id::DefId;
1413
use rustc_middle::bug;
1514
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
16-
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
15+
use rustc_middle::ty::layout::TyAndLayout;
1716
use rustc_middle::ty::TyCtxt;
1817
use rustc_session::cstore::{DllCallingConvention, DllImport, PeImportNameType};
1918
use rustc_target::abi::{self, AddressSpace, HasDataLayout, Pointer, Size};
@@ -203,10 +202,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
203202
})
204203
.1;
205204
let len = s.len();
206-
let cs = consts::ptrcast(
207-
str_global,
208-
self.type_ptr_to(self.layout_of(self.tcx.types.str_).llvm_type(self)),
209-
);
205+
let cs = consts::ptrcast(str_global, self.type_ptr());
210206
(cs, self.const_usize(len as u64))
211207
}
212208

@@ -279,7 +275,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
279275
let llval = unsafe {
280276
llvm::LLVMRustConstInBoundsGEP2(
281277
self.type_i8(),
282-
self.const_bitcast(base_addr, self.type_i8p_ext(base_addr_space)),
278+
self.const_bitcast(base_addr, self.type_ptr_in(base_addr_space)),
283279
&self.const_usize(offset.bytes()),
284280
1,
285281
)
@@ -305,7 +301,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
305301
) -> PlaceRef<'tcx, &'ll Value> {
306302
let alloc_align = alloc.inner().align;
307303
assert_eq!(alloc_align, layout.align.abi);
308-
let llty = self.type_ptr_to(layout.llvm_type(self));
304+
let llty = self.type_ptr();
309305
let llval = if layout.size == Size::ZERO {
310306
let llval = self.const_usize(alloc_align.bytes());
311307
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
@@ -316,7 +312,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
316312
let llval = unsafe {
317313
llvm::LLVMRustConstInBoundsGEP2(
318314
self.type_i8(),
319-
self.const_bitcast(base_addr, self.type_i8p()),
315+
self.const_bitcast(base_addr, self.type_ptr()),
320316
&self.const_usize(offset.bytes()),
321317
1,
322318
)

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<
114114
value: Primitive::Pointer,
115115
valid_range: WrappingRange::full(dl.pointer_size),
116116
},
117-
cx.type_i8p_ext(address_space),
117+
cx.type_ptr_in(address_space),
118118
));
119119
next_offset = offset + pointer_size;
120120
}
@@ -267,7 +267,7 @@ impl<'ll> CodegenCx<'ll, '_> {
267267
let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
268268
let llty = self.layout_of(ty).llvm_type(self);
269269
if let Some(g) = self.get_declared_value(sym) {
270-
if self.val_ty(g) != self.type_ptr_to(llty) {
270+
if self.val_ty(g) != self.type_ptr() {
271271
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
272272
}
273273
}
@@ -570,16 +570,16 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
570570
}
571571
}
572572

573-
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of i8*.
573+
/// Add a global value to a list to be stored in the `llvm.used` variable, an array of ptr.
574574
fn add_used_global(&self, global: &'ll Value) {
575-
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
575+
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_ptr()) };
576576
self.used_statics.borrow_mut().push(cast);
577577
}
578578

579579
/// Add a global value to a list to be stored in the `llvm.compiler.used` variable,
580-
/// an array of i8*.
580+
/// an array of ptr.
581581
fn add_compiler_used_global(&self, global: &'ll Value) {
582-
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_i8p()) };
582+
let cast = unsafe { llvm::LLVMConstPointerCast(global, self.type_ptr()) };
583583
self.compiler_used_statics.borrow_mut().push(cast);
584584
}
585585
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
466466

467467
pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) {
468468
let section = cstr!("llvm.metadata");
469-
let array = self.const_array(self.type_ptr_to(self.type_i8()), values);
469+
let array = self.const_array(self.type_ptr(), values);
470470

471471
unsafe {
472472
let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
@@ -640,7 +640,7 @@ impl<'ll> CodegenCx<'ll, '_> {
640640
($($field_ty:expr),*) => (self.type_struct( &[$($field_ty),*], false))
641641
}
642642

643-
let i8p = self.type_i8p();
643+
let ptr = self.type_ptr();
644644
let void = self.type_void();
645645
let i1 = self.type_i1();
646646
let t_i8 = self.type_i8();
@@ -686,7 +686,7 @@ impl<'ll> CodegenCx<'ll, '_> {
686686

687687
ifn!("llvm.trap", fn() -> void);
688688
ifn!("llvm.debugtrap", fn() -> void);
689-
ifn!("llvm.frameaddress", fn(t_i32) -> i8p);
689+
ifn!("llvm.frameaddress", fn(t_i32) -> ptr);
690690

691691
ifn!("llvm.powi.f32", fn(t_f32, t_i32) -> t_f32);
692692
ifn!("llvm.powi.f64", fn(t_f64, t_i32) -> t_f64);
@@ -849,43 +849,43 @@ impl<'ll> CodegenCx<'ll, '_> {
849849
ifn!("llvm.usub.sat.i64", fn(t_i64, t_i64) -> t_i64);
850850
ifn!("llvm.usub.sat.i128", fn(t_i128, t_i128) -> t_i128);
851851

852-
ifn!("llvm.lifetime.start.p0i8", fn(t_i64, i8p) -> void);
853-
ifn!("llvm.lifetime.end.p0i8", fn(t_i64, i8p) -> void);
852+
ifn!("llvm.lifetime.start.p0i8", fn(t_i64, ptr) -> void);
853+
ifn!("llvm.lifetime.end.p0i8", fn(t_i64, ptr) -> void);
854854

855855
ifn!("llvm.expect.i1", fn(i1, i1) -> i1);
856-
ifn!("llvm.eh.typeid.for", fn(i8p) -> t_i32);
856+
ifn!("llvm.eh.typeid.for", fn(ptr) -> t_i32);
857857
ifn!("llvm.localescape", fn(...) -> void);
858-
ifn!("llvm.localrecover", fn(i8p, i8p, t_i32) -> i8p);
859-
ifn!("llvm.x86.seh.recoverfp", fn(i8p, i8p) -> i8p);
858+
ifn!("llvm.localrecover", fn(ptr, ptr, t_i32) -> ptr);
859+
ifn!("llvm.x86.seh.recoverfp", fn(ptr, ptr) -> ptr);
860860

861861
ifn!("llvm.assume", fn(i1) -> void);
862-
ifn!("llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
862+
ifn!("llvm.prefetch", fn(ptr, t_i32, t_i32, t_i32) -> void);
863863

864864
// This isn't an "LLVM intrinsic", but LLVM's optimization passes
865865
// recognize it like one and we assume it exists in `core::slice::cmp`
866866
match self.sess().target.arch.as_ref() {
867-
"avr" | "msp430" => ifn!("memcmp", fn(i8p, i8p, t_isize) -> t_i16),
868-
_ => ifn!("memcmp", fn(i8p, i8p, t_isize) -> t_i32),
867+
"avr" | "msp430" => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i16),
868+
_ => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i32),
869869
}
870870

871871
// variadic intrinsics
872-
ifn!("llvm.va_start", fn(i8p) -> void);
873-
ifn!("llvm.va_end", fn(i8p) -> void);
874-
ifn!("llvm.va_copy", fn(i8p, i8p) -> void);
872+
ifn!("llvm.va_start", fn(ptr) -> void);
873+
ifn!("llvm.va_end", fn(ptr) -> void);
874+
ifn!("llvm.va_copy", fn(ptr, ptr) -> void);
875875

876876
if self.sess().instrument_coverage() {
877-
ifn!("llvm.instrprof.increment", fn(i8p, t_i64, t_i32, t_i32) -> void);
877+
ifn!("llvm.instrprof.increment", fn(ptr, t_i64, t_i32, t_i32) -> void);
878878
}
879879

880-
ifn!("llvm.type.test", fn(i8p, t_metadata) -> i1);
881-
ifn!("llvm.type.checked.load", fn(i8p, t_i32, t_metadata) -> mk_struct! {i8p, i1});
880+
ifn!("llvm.type.test", fn(ptr, t_metadata) -> i1);
881+
ifn!("llvm.type.checked.load", fn(ptr, t_i32, t_metadata) -> mk_struct! {ptr, i1});
882882

883883
if self.sess().opts.debuginfo != DebugInfo::None {
884884
ifn!("llvm.dbg.declare", fn(t_metadata, t_metadata) -> void);
885885
ifn!("llvm.dbg.value", fn(t_metadata, t_i64, t_metadata) -> void);
886886
}
887887

888-
ifn!("llvm.ptrmask", fn(i8p, t_isize) -> i8p);
888+
ifn!("llvm.ptrmask", fn(ptr, t_isize) -> ptr);
889889

890890
None
891891
}
@@ -899,12 +899,11 @@ impl<'ll> CodegenCx<'ll, '_> {
899899
let eh_catch_typeinfo = match tcx.lang_items().eh_catch_typeinfo() {
900900
Some(def_id) => self.get_static(def_id),
901901
_ => {
902-
let ty = self
903-
.type_struct(&[self.type_ptr_to(self.type_isize()), self.type_i8p()], false);
902+
let ty = self.type_struct(&[self.type_ptr(), self.type_ptr()], false);
904903
self.declare_global("rust_eh_catch_typeinfo", ty)
905904
}
906905
};
907-
let eh_catch_typeinfo = self.const_bitcast(eh_catch_typeinfo, self.type_i8p());
906+
let eh_catch_typeinfo = self.const_bitcast(eh_catch_typeinfo, self.type_ptr());
908907
self.eh_catch_typeinfo.set(Some(eh_catch_typeinfo));
909908
eh_catch_typeinfo
910909
}

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::DebuggerVisualizerType;
1919
pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &mut Builder<'_, '_, '_>) {
2020
if needs_gdb_debug_scripts_section(bx) {
2121
let gdb_debug_scripts_section =
22-
bx.const_bitcast(get_or_insert_gdb_debug_scripts_section_global(bx), bx.type_i8p());
22+
bx.const_bitcast(get_or_insert_gdb_debug_scripts_section_global(bx), bx.type_ptr());
2323
// Load just the first byte as that's all that's necessary to force
2424
// LLVM to keep around the reference to the global.
2525
let volative_load_instruction = bx.volatile_load(bx.type_i8(), gdb_debug_scripts_section);

0 commit comments

Comments
 (0)