Skip to content

Commit 23562c1

Browse files
committed
Prefixed type methods & removed trait impl for write::CodegenContext
1 parent a64741c commit 23562c1

File tree

20 files changed

+266
-275
lines changed

20 files changed

+266
-275
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ pub trait LlvmType {
112112
impl LlvmType for Reg {
113113
fn llvm_type(&self, cx: &CodegenCx<'ll, '_, &'ll Value>) -> &'ll Type {
114114
match self.kind {
115-
RegKind::Integer => cx.ix(self.size.bits()),
115+
RegKind::Integer => cx.type_ix(self.size.bits()),
116116
RegKind::Float => {
117117
match self.size.bits() {
118-
32 => cx.f32(),
119-
64 => cx.f64(),
118+
32 => cx.type_f32(),
119+
64 => cx.type_f64(),
120120
_ => bug!("unsupported float: {:?}", self)
121121
}
122122
}
123123
RegKind::Vector => {
124-
cx.vector(cx.i8(), self.size.bytes())
124+
cx.type_vector(cx.type_i8(), self.size.bytes())
125125
}
126126
}
127127
}
@@ -145,7 +145,7 @@ impl LlvmType for CastTarget {
145145

146146
// Simplify to array when all chunks are the same size and type
147147
if rem_bytes == 0 {
148-
return cx.array(rest_ll_unit, rest_count);
148+
return cx.type_array(rest_ll_unit, rest_count);
149149
}
150150
}
151151

@@ -160,10 +160,10 @@ impl LlvmType for CastTarget {
160160
if rem_bytes != 0 {
161161
// Only integers can be really split further.
162162
assert_eq!(self.rest.unit.kind, RegKind::Integer);
163-
args.push(cx.ix(rem_bytes * 8));
163+
args.push(cx.type_ix(rem_bytes * 8));
164164
}
165165

166-
cx.struct_(&args, false)
166+
cx.type_struct(&args, false)
167167
}
168168
}
169169

@@ -212,7 +212,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
212212
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
213213
let can_store_through_cast_ptr = false;
214214
if can_store_through_cast_ptr {
215-
let cast_dst = bx.pointercast(dst.llval, cx.ptr_to(cast.llvm_type(cx)));
215+
let cast_dst = bx.pointercast(dst.llval, cx.type_ptr_to(cast.llvm_type(cx)));
216216
bx.store(val, cast_dst, self.layout.align);
217217
} else {
218218
// The actual return type is a struct, but the ABI
@@ -240,8 +240,8 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
240240

241241
// ...and then memcpy it to the intended destination.
242242
base::call_memcpy(bx,
243-
bx.pointercast(dst.llval, cx.i8p()),
244-
bx.pointercast(llscratch, cx.i8p()),
243+
bx.pointercast(dst.llval, cx.type_i8p()),
244+
bx.pointercast(llscratch, cx.type_i8p()),
245245
cx.const_usize(self.layout.size.bytes()),
246246
self.layout.align.min(scratch_align),
247247
MemFlags::empty());
@@ -605,14 +605,14 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
605605
);
606606

607607
let llreturn_ty = match self.ret.mode {
608-
PassMode::Ignore => cx.void(),
608+
PassMode::Ignore => cx.type_void(),
609609
PassMode::Direct(_) | PassMode::Pair(..) => {
610610
self.ret.layout.immediate_llvm_type(cx)
611611
}
612612
PassMode::Cast(cast) => cast.llvm_type(cx),
613613
PassMode::Indirect(..) => {
614-
llargument_tys.push(cx.ptr_to(self.ret.memory_ty(cx)));
615-
cx.void()
614+
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
615+
cx.type_void()
616616
}
617617
};
618618

@@ -638,15 +638,15 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
638638
continue;
639639
}
640640
PassMode::Cast(cast) => cast.llvm_type(cx),
641-
PassMode::Indirect(_, None) => cx.ptr_to(arg.memory_ty(cx)),
641+
PassMode::Indirect(_, None) => cx.type_ptr_to(arg.memory_ty(cx)),
642642
};
643643
llargument_tys.push(llarg_ty);
644644
}
645645

646646
if self.variadic {
647-
cx.variadic_func(&llargument_tys, llreturn_ty)
647+
cx.type_variadic_func(&llargument_tys, llreturn_ty)
648648
} else {
649-
cx.func(&llargument_tys, llreturn_ty)
649+
cx.type_func(&llargument_tys, llreturn_ty)
650650
}
651651
}
652652

src/librustc_codegen_llvm/asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ pub fn codegen_inline_asm(
7575
// Depending on how many outputs we have, the return type is different
7676
let num_outputs = output_types.len();
7777
let output_type = match num_outputs {
78-
0 => bx.cx().void(),
78+
0 => bx.cx().type_void(),
7979
1 => output_types[0],
80-
_ => bx.cx().struct_(&output_types, false)
80+
_ => bx.cx().type_struct(&output_types, false)
8181
};
8282

8383
let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();

src/librustc_codegen_llvm/back/write.rs

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Sanitize
2626
use rustc::session::Session;
2727
use rustc::util::nodemap::FxHashMap;
2828
use time_graph::{self, TimeGraph, Timeline};
29-
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic, BasicBlock};
29+
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
3030
use llvm_util;
3131
use {CodegenResults, ModuleCodegen, CompiledModule, ModuleKind, // ModuleLlvm,
3232
CachedModuleCodegen};
@@ -45,7 +45,6 @@ use syntax_pos::MultiSpan;
4545
use syntax_pos::symbol::Symbol;
4646
use type_::Type;
4747
use context::{is_pie_binary, get_reloc_model};
48-
use interfaces::{Backend, CommonWriteMethods};
4948
use common;
5049
use jobserver::{Client, Acquired};
5150
use rustc_demangle;
@@ -420,15 +419,8 @@ impl CodegenContext<'ll> {
420419
}
421420
}
422421

423-
impl<'ll> Backend for CodegenContext<'ll> {
424-
type Value = &'ll Value;
425-
type BasicBlock = &'ll BasicBlock;
426-
type Type = &'ll Type;
427-
type Context = &'ll llvm::Context;
428-
type TypeKind = llvm::TypeKind;
429-
}
430422

431-
impl CommonWriteMethods for CodegenContext<'ll> {
423+
impl CodegenContext<'ll> {
432424
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
433425
common::val_ty(v)
434426
}
@@ -437,18 +429,7 @@ impl CommonWriteMethods for CodegenContext<'ll> {
437429
common::const_bytes_in_context(llcx, bytes)
438430
}
439431

440-
fn const_struct_in_context(
441-
&self,
442-
llcx: &'a llvm::Context,
443-
elts: &[&'a Value],
444-
packed: bool,
445-
) -> &'a Value {
446-
common::const_struct_in_context(llcx, elts, packed)
447-
}
448-
}
449-
450-
impl CodegenContext<'ll> {
451-
pub fn ptr_to(&self, ty: &'ll Type) -> &'ll Type {
432+
pub fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
452433
unsafe {
453434
llvm::LLVMPointerType(ty, 0)
454435
}

src/librustc_codegen_llvm/base.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ pub fn unsize_thin_ptr(
234234
(&ty::RawPtr(ty::TypeAndMut { ty: a, .. }),
235235
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
236236
assert!(bx.cx().type_is_sized(a));
237-
let ptr_ty = bx.cx().ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
237+
let ptr_ty = bx.cx().type_ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
238238
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx(), a, b, None))
239239
}
240240
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
241241
let (a, b) = (src_ty.boxed_ty(), dst_ty.boxed_ty());
242242
assert!(bx.cx().type_is_sized(a));
243-
let ptr_ty = bx.cx().ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
243+
let ptr_ty = bx.cx().type_ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
244244
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx(), a, b, None))
245245
}
246246
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
@@ -353,10 +353,10 @@ fn cast_shift_rhs<'ll, F, G>(bx: &Builder<'_, 'll, '_, &'ll Value>,
353353
if op.is_shift() {
354354
let mut rhs_llty = bx.cx().val_ty(rhs);
355355
let mut lhs_llty = bx.cx().val_ty(lhs);
356-
if bx.cx().kind(rhs_llty) == TypeKind::Vector {
356+
if bx.cx().type_kind(rhs_llty) == TypeKind::Vector {
357357
rhs_llty = bx.cx().element_type(rhs_llty)
358358
}
359-
if bx.cx().kind(lhs_llty) == TypeKind::Vector {
359+
if bx.cx().type_kind(lhs_llty) == TypeKind::Vector {
360360
lhs_llty = bx.cx().element_type(lhs_llty)
361361
}
362362
let rhs_sz = bx.cx().int_width(rhs_llty);
@@ -393,8 +393,8 @@ pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll>(
393393
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
394394
val: &'ll Value
395395
) -> &'ll Value {
396-
if bx.cx().val_ty(val) == bx.cx().i1() {
397-
bx.zext(val, bx.cx().i8())
396+
if bx.cx().val_ty(val) == bx.cx().type_i1() {
397+
bx.zext(val, bx.cx().type_i8())
398398
} else {
399399
val
400400
}
@@ -417,7 +417,7 @@ pub fn to_immediate_scalar(
417417
scalar: &layout::Scalar,
418418
) -> &'ll Value {
419419
if scalar.is_bool() {
420-
return bx.trunc(val, bx.cx().i1());
420+
return bx.trunc(val, bx.cx().type_i1());
421421
}
422422
val
423423
}
@@ -433,16 +433,16 @@ pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
433433
if flags.contains(MemFlags::NONTEMPORAL) {
434434
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
435435
let val = bx.load(src, align);
436-
let ptr = bx.pointercast(dst, bx.cx().ptr_to(bx.cx().val_ty(val)));
436+
let ptr = bx.pointercast(dst, bx.cx().type_ptr_to(bx.cx().val_ty(val)));
437437
bx.store_with_flags(val, ptr, align, flags);
438438
return;
439439
}
440440
let cx = bx.cx();
441441
let ptr_width = &cx.sess().target.target.target_pointer_width;
442442
let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
443443
let memcpy = cx.get_intrinsic(&key);
444-
let src_ptr = bx.pointercast(src, cx.i8p());
445-
let dst_ptr = bx.pointercast(dst, cx.i8p());
444+
let src_ptr = bx.pointercast(src, cx.type_i8p());
445+
let dst_ptr = bx.pointercast(dst, cx.type_i8p());
446446
let size = bx.intcast(n_bytes, cx.isize_ty, false);
447447
let align = cx.const_i32(align.abi() as i32);
448448
let volatile = cx.const_bool(flags.contains(MemFlags::VOLATILE));
@@ -556,7 +556,7 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx<'ll, '_, &'ll Value>) {
556556
use_start_lang_item: bool,
557557
) {
558558
let llfty =
559-
cx.func(&[cx.t_int(), cx.ptr_to(cx.i8p())], cx.t_int());
559+
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int());
560560

561561
let main_ret_ty = cx.tcx.fn_sig(rust_main_def_id).output();
562562
// Given that `main()` has no arguments,
@@ -599,15 +599,15 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx<'ll, '_, &'ll Value>) {
599599
start_def_id,
600600
cx.tcx.intern_substs(&[main_ret_ty.into()]),
601601
);
602-
(start_fn, vec![bx.pointercast(rust_main, cx.ptr_to(cx.i8p())),
602+
(start_fn, vec![bx.pointercast(rust_main, cx.type_ptr_to(cx.type_i8p())),
603603
arg_argc, arg_argv])
604604
} else {
605605
debug!("using user-defined start fn");
606606
(rust_main, vec![arg_argc, arg_argv])
607607
};
608608

609609
let result = bx.call(start_fn, &args, None);
610-
bx.ret(bx.intcast(result, cx.t_int(), true));
610+
bx.ret(bx.intcast(result, cx.type_int(), true));
611611
}
612612
}
613613

@@ -1258,7 +1258,10 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12581258
if !cx.used_statics.borrow().is_empty() {
12591259
let name = const_cstr!("llvm.used");
12601260
let section = const_cstr!("llvm.metadata");
1261-
let array = cx.const_array(&cx.ptr_to(cx.i8()), &*cx.used_statics.borrow());
1261+
let array = cx.const_array(
1262+
&cx.type_ptr_to(cx.type_i8()),
1263+
&*cx.used_statics.borrow()
1264+
);
12621265

12631266
unsafe {
12641267
let g = llvm::LLVMAddGlobal(cx.llmod,

src/librustc_codegen_llvm/builder.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
778778
}).collect::<Vec<_>>();
779779

780780
debug!("Asm Output Type: {:?}", output);
781-
let fty = &self.cx().func(&argtys[..], output);
781+
let fty = &self.cx().type_func(&argtys[..], output);
782782
unsafe {
783783
let v = llvm::LLVMRustInlineAsm(
784784
fty, asm, cons, volatile, alignstack, AsmDialect::from_generic(dia));
@@ -848,9 +848,9 @@ impl BuilderMethods<'a, 'll, 'tcx>
848848
fn vector_splat(&self, num_elts: usize, elt: &'ll Value) -> &'ll Value {
849849
unsafe {
850850
let elt_ty = self.cx.val_ty(elt);
851-
let undef = llvm::LLVMGetUndef(&self.cx().vector(elt_ty, num_elts as u64));
851+
let undef = llvm::LLVMGetUndef(&self.cx().type_vector(elt_ty, num_elts as u64));
852852
let vec = self.insert_element(undef, elt, self.cx.const_i32(0));
853-
let vec_i32_ty = &self.cx().vector(&self.cx().i32(), num_elts as u64);
853+
let vec_i32_ty = &self.cx().type_vector(&self.cx().type_i32(), num_elts as u64);
854854
self.shuffle_vector(vec, undef, self.cx().const_null(vec_i32_ty))
855855
}
856856
}
@@ -1160,9 +1160,9 @@ impl BuilderMethods<'a, 'll, 'tcx>
11601160
ptr: &'ll Value) -> &'ll Value {
11611161
let dest_ptr_ty = self.cx.val_ty(ptr);
11621162
let stored_ty = self.cx.val_ty(val);
1163-
let stored_ptr_ty = self.cx.ptr_to(stored_ty);
1163+
let stored_ptr_ty = self.cx.type_ptr_to(stored_ty);
11641164

1165-
assert_eq!(self.cx.kind(dest_ptr_ty), llvm::TypeKind::Pointer);
1165+
assert_eq!(self.cx.type_kind(dest_ptr_ty), llvm::TypeKind::Pointer);
11661166

11671167
if dest_ptr_ty == stored_ptr_ty {
11681168
ptr
@@ -1181,14 +1181,14 @@ impl BuilderMethods<'a, 'll, 'tcx>
11811181
args: &'b [&'ll Value]) -> Cow<'b, [&'ll Value]> {
11821182
let mut fn_ty = self.cx.val_ty(llfn);
11831183
// Strip off pointers
1184-
while self.cx.kind(fn_ty) == llvm::TypeKind::Pointer {
1184+
while self.cx.type_kind(fn_ty) == llvm::TypeKind::Pointer {
11851185
fn_ty = self.cx.element_type(fn_ty);
11861186
}
11871187

1188-
assert!(self.cx.kind(fn_ty) == llvm::TypeKind::Function,
1188+
assert!(self.cx.type_kind(fn_ty) == llvm::TypeKind::Function,
11891189
"builder::{} not passed a function, but {:?}", typ, fn_ty);
11901190

1191-
let param_tys = self.cx.func_params(fn_ty);
1191+
let param_tys = self.cx.func_params_types(fn_ty);
11921192

11931193
let all_args_match = param_tys.iter()
11941194
.zip(args.iter().map(|&v| self.cx().val_ty(v)))
@@ -1245,7 +1245,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
12451245

12461246
let lifetime_intrinsic = self.cx.get_intrinsic(intrinsic);
12471247

1248-
let ptr = self.pointercast(ptr, self.cx.i8p());
1248+
let ptr = self.pointercast(ptr, self.cx.type_i8p());
12491249
self.call(lifetime_intrinsic, &[self.cx.const_u64(size), ptr], None);
12501250
}
12511251

src/librustc_codegen_llvm/common.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,19 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
238238
}
239239

240240
fn const_bool(&self, val: bool) -> &'ll Value {
241-
&self.const_uint(&self.i1(), val as u64)
241+
&self.const_uint(&self.type_i1(), val as u64)
242242
}
243243

244244
fn const_i32(&self, i: i32) -> &'ll Value {
245-
&self.const_int(&self.i32(), i as i64)
245+
&self.const_int(&self.type_i32(), i as i64)
246246
}
247247

248248
fn const_u32(&self, i: u32) -> &'ll Value {
249-
&self.const_uint(&self.i32(), i as u64)
249+
&self.const_uint(&self.type_i32(), i as u64)
250250
}
251251

252252
fn const_u64(&self, i: u64) -> &'ll Value {
253-
&self.const_uint(&self.i64(), i)
253+
&self.const_uint(&self.type_i64(), i)
254254
}
255255

256256
fn const_usize(&self, i: u64) -> &'ll Value {
@@ -264,7 +264,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
264264
}
265265

266266
fn const_u8(&self, i: u8) -> &'ll Value {
267-
&self.const_uint(&self.i8(), i as u64)
267+
&self.const_uint(&self.type_i8(), i as u64)
268268
}
269269

270270

@@ -302,7 +302,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
302302
fn const_str_slice(&self, s: LocalInternedString) -> &'ll Value {
303303
let len = s.len();
304304
let cs = consts::ptrcast(&self.const_cstr(s, false),
305-
&self.ptr_to(&self.layout_of(&self.tcx.mk_str()).llvm_type(&self)));
305+
&self.type_ptr_to(&self.layout_of(&self.tcx.mk_str()).llvm_type(&self)));
306306
&self.const_fat_ptr(cs, &self.const_usize(len as u64))
307307
}
308308

@@ -510,7 +510,7 @@ pub fn shift_mask_val(
510510
mask_llty: &'ll Type,
511511
invert: bool
512512
) -> &'ll Value {
513-
let kind = bx.cx().kind(llty);
513+
let kind = bx.cx().type_kind(llty);
514514
match kind {
515515
TypeKind::Integer => {
516516
// i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.

0 commit comments

Comments
 (0)