Skip to content

Commit 55429fa

Browse files
committed
Prefixed type methods & removed trait impl for write::CodegenContext
1 parent 0c414d5 commit 55429fa

File tree

20 files changed

+262
-273
lines changed

20 files changed

+262
-273
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());
@@ -633,14 +633,14 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
633633
);
634634

635635
let llreturn_ty = match self.ret.mode {
636-
PassMode::Ignore => cx.void(),
636+
PassMode::Ignore => cx.type_void(),
637637
PassMode::Direct(_) | PassMode::Pair(..) => {
638638
self.ret.layout.immediate_llvm_type(cx)
639639
}
640640
PassMode::Cast(cast) => cast.llvm_type(cx),
641641
PassMode::Indirect(..) => {
642-
llargument_tys.push(cx.ptr_to(self.ret.memory_ty(cx)));
643-
cx.void()
642+
llargument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
643+
cx.type_void()
644644
}
645645
};
646646

@@ -666,15 +666,15 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
666666
continue;
667667
}
668668
PassMode::Cast(cast) => cast.llvm_type(cx),
669-
PassMode::Indirect(_, None) => cx.ptr_to(arg.memory_ty(cx)),
669+
PassMode::Indirect(_, None) => cx.type_ptr_to(arg.memory_ty(cx)),
670670
};
671671
llargument_tys.push(llarg_ty);
672672
}
673673

674674
if self.variadic {
675-
cx.variadic_func(&llargument_tys, llreturn_ty)
675+
cx.type_variadic_func(&llargument_tys, llreturn_ty)
676676
} else {
677-
cx.func(&llargument_tys, llreturn_ty)
677+
cx.type_func(&llargument_tys, llreturn_ty)
678678
}
679679
}
680680

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
@@ -24,7 +24,7 @@ use rustc::session::config::{self, OutputFilenames, OutputType, Passes, Sanitize
2424
use rustc::session::Session;
2525
use rustc::util::nodemap::FxHashMap;
2626
use time_graph::{self, TimeGraph, Timeline};
27-
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic, BasicBlock};
27+
use llvm::{self, DiagnosticInfo, PassManager, SMDiagnostic};
2828
use llvm_util;
2929
use {CodegenResults, ModuleCodegen, CompiledModule, ModuleKind, // ModuleLlvm,
3030
CachedModuleCodegen};
@@ -46,7 +46,6 @@ use syntax_pos::MultiSpan;
4646
use syntax_pos::symbol::Symbol;
4747
use type_::Type;
4848
use context::{is_pie_binary, get_reloc_model};
49-
use interfaces::{Backend, CommonWriteMethods};
5049
use common;
5150
use jobserver::{Client, Acquired};
5251
use rustc_demangle;
@@ -425,15 +424,8 @@ impl CodegenContext<'ll> {
425424
}
426425
}
427426

428-
impl<'ll> Backend for CodegenContext<'ll> {
429-
type Value = &'ll Value;
430-
type BasicBlock = &'ll BasicBlock;
431-
type Type = &'ll Type;
432-
type Context = &'ll llvm::Context;
433-
type TypeKind = llvm::TypeKind;
434-
}
435427

436-
impl CommonWriteMethods for CodegenContext<'ll> {
428+
impl CodegenContext<'ll> {
437429
fn val_ty(&self, v: &'ll Value) -> &'ll Type {
438430
common::val_ty(v)
439431
}
@@ -442,18 +434,7 @@ impl CommonWriteMethods for CodegenContext<'ll> {
442434
common::const_bytes_in_context(llcx, bytes)
443435
}
444436

445-
fn const_struct_in_context(
446-
&self,
447-
llcx: &'a llvm::Context,
448-
elts: &[&'a Value],
449-
packed: bool,
450-
) -> &'a Value {
451-
common::const_struct_in_context(llcx, elts, packed)
452-
}
453-
}
454-
455-
impl CodegenContext<'ll> {
456-
pub fn ptr_to(&self, ty: &'ll Type) -> &'ll Type {
437+
pub fn type_ptr_to(&self, ty: &'ll Type) -> &'ll Type {
457438
unsafe {
458439
llvm::LLVMPointerType(ty, 0)
459440
}

src/librustc_codegen_llvm/base.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ pub fn unsize_thin_ptr(
235235
(&ty::RawPtr(ty::TypeAndMut { ty: a, .. }),
236236
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
237237
assert!(bx.cx().type_is_sized(a));
238-
let ptr_ty = bx.cx().ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
238+
let ptr_ty = bx.cx().type_ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
239239
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx(), a, b, None))
240240
}
241241
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
242242
let (a, b) = (src_ty.boxed_ty(), dst_ty.boxed_ty());
243243
assert!(bx.cx().type_is_sized(a));
244-
let ptr_ty = bx.cx().ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
244+
let ptr_ty = bx.cx().type_ptr_to(bx.cx().layout_of(b).llvm_type(bx.cx()));
245245
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx(), a, b, None))
246246
}
247247
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
@@ -354,10 +354,10 @@ fn cast_shift_rhs<'ll, F, G>(bx: &Builder<'_, 'll, '_, &'ll Value>,
354354
if op.is_shift() {
355355
let mut rhs_llty = bx.cx().val_ty(rhs);
356356
let mut lhs_llty = bx.cx().val_ty(lhs);
357-
if bx.cx().kind(rhs_llty) == TypeKind::Vector {
357+
if bx.cx().type_kind(rhs_llty) == TypeKind::Vector {
358358
rhs_llty = bx.cx().element_type(rhs_llty)
359359
}
360-
if bx.cx().kind(lhs_llty) == TypeKind::Vector {
360+
if bx.cx().type_kind(lhs_llty) == TypeKind::Vector {
361361
lhs_llty = bx.cx().element_type(lhs_llty)
362362
}
363363
let rhs_sz = bx.cx().int_width(rhs_llty);
@@ -394,8 +394,8 @@ pub fn from_immediate<'a, 'll: 'a, 'tcx: 'll>(
394394
bx: &Builder<'_ ,'ll, '_, &'ll Value>,
395395
val: &'ll Value
396396
) -> &'ll Value {
397-
if bx.cx().val_ty(val) == bx.cx().i1() {
398-
bx.zext(val, bx.cx().i8())
397+
if bx.cx().val_ty(val) == bx.cx().type_i1() {
398+
bx.zext(val, bx.cx().type_i8())
399399
} else {
400400
val
401401
}
@@ -418,7 +418,7 @@ pub fn to_immediate_scalar(
418418
scalar: &layout::Scalar,
419419
) -> &'ll Value {
420420
if scalar.is_bool() {
421-
return bx.trunc(val, bx.cx().i1());
421+
return bx.trunc(val, bx.cx().type_i1());
422422
}
423423
val
424424
}
@@ -434,16 +434,16 @@ pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
434434
if flags.contains(MemFlags::NONTEMPORAL) {
435435
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
436436
let val = bx.load(src, align);
437-
let ptr = bx.pointercast(dst, bx.cx().ptr_to(bx.cx().val_ty(val)));
437+
let ptr = bx.pointercast(dst, bx.cx().type_ptr_to(bx.cx().val_ty(val)));
438438
bx.store_with_flags(val, ptr, align, flags);
439439
return;
440440
}
441441
let cx = bx.cx();
442442
let ptr_width = &cx.sess().target.target.target_pointer_width;
443443
let key = format!("llvm.memcpy.p0i8.p0i8.i{}", ptr_width);
444444
let memcpy = cx.get_intrinsic(&key);
445-
let src_ptr = bx.pointercast(src, cx.i8p());
446-
let dst_ptr = bx.pointercast(dst, cx.i8p());
445+
let src_ptr = bx.pointercast(src, cx.type_i8p());
446+
let dst_ptr = bx.pointercast(dst, cx.type_i8p());
447447
let size = bx.intcast(n_bytes, cx.isize_ty, false);
448448
let align = cx.const_i32(align.abi() as i32);
449449
let volatile = cx.const_bool(flags.contains(MemFlags::VOLATILE));
@@ -554,7 +554,7 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx<'ll, '_, &'ll Value>) {
554554
use_start_lang_item: bool,
555555
) {
556556
let llfty =
557-
cx.func(&[cx.t_int(), cx.ptr_to(cx.i8p())], cx.t_int());
557+
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int());
558558

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

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

@@ -1154,7 +1154,10 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11541154
if !cx.used_statics.borrow().is_empty() {
11551155
let name = const_cstr!("llvm.used");
11561156
let section = const_cstr!("llvm.metadata");
1157-
let array = cx.const_array(&cx.ptr_to(cx.i8()), &*cx.used_statics.borrow());
1157+
let array = cx.const_array(
1158+
&cx.type_ptr_to(cx.type_i8()),
1159+
&*cx.used_statics.borrow()
1160+
);
11581161

11591162
unsafe {
11601163
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
@@ -783,7 +783,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
783783
}).collect::<Vec<_>>();
784784

785785
debug!("Asm Output Type: {:?}", output);
786-
let fty = &self.cx().func(&argtys[..], output);
786+
let fty = &self.cx().type_func(&argtys[..], output);
787787
unsafe {
788788
// Ask LLVM to verify that the constraints are well-formed.
789789
let constraints_ok = llvm::LLVMRustInlineAsmVerify(fty, cons);
@@ -861,9 +861,9 @@ impl BuilderMethods<'a, 'll, 'tcx>
861861
fn vector_splat(&self, num_elts: usize, elt: &'ll Value) -> &'ll Value {
862862
unsafe {
863863
let elt_ty = self.cx.val_ty(elt);
864-
let undef = llvm::LLVMGetUndef(&self.cx().vector(elt_ty, num_elts as u64));
864+
let undef = llvm::LLVMGetUndef(&self.cx().type_vector(elt_ty, num_elts as u64));
865865
let vec = self.insert_element(undef, elt, self.cx.const_i32(0));
866-
let vec_i32_ty = &self.cx().vector(&self.cx().i32(), num_elts as u64);
866+
let vec_i32_ty = &self.cx().type_vector(&self.cx().type_i32(), num_elts as u64);
867867
self.shuffle_vector(vec, undef, self.cx().const_null(vec_i32_ty))
868868
}
869869
}
@@ -1173,9 +1173,9 @@ impl BuilderMethods<'a, 'll, 'tcx>
11731173
ptr: &'ll Value) -> &'ll Value {
11741174
let dest_ptr_ty = self.cx.val_ty(ptr);
11751175
let stored_ty = self.cx.val_ty(val);
1176-
let stored_ptr_ty = self.cx.ptr_to(stored_ty);
1176+
let stored_ptr_ty = self.cx.type_ptr_to(stored_ty);
11771177

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

11801180
if dest_ptr_ty == stored_ptr_ty {
11811181
ptr
@@ -1194,14 +1194,14 @@ impl BuilderMethods<'a, 'll, 'tcx>
11941194
args: &'b [&'ll Value]) -> Cow<'b, [&'ll Value]> {
11951195
let mut fn_ty = self.cx.val_ty(llfn);
11961196
// Strip off pointers
1197-
while self.cx.kind(fn_ty) == llvm::TypeKind::Pointer {
1197+
while self.cx.type_kind(fn_ty) == llvm::TypeKind::Pointer {
11981198
fn_ty = self.cx.element_type(fn_ty);
11991199
}
12001200

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

1204-
let param_tys = self.cx.func_params(fn_ty);
1204+
let param_tys = self.cx.func_params_types(fn_ty);
12051205

12061206
let all_args_match = param_tys.iter()
12071207
.zip(args.iter().map(|&v| self.cx().val_ty(v)))
@@ -1258,7 +1258,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
12581258

12591259
let lifetime_intrinsic = self.cx.get_intrinsic(intrinsic);
12601260

1261-
let ptr = self.pointercast(ptr, self.cx.i8p());
1261+
let ptr = self.pointercast(ptr, self.cx.type_i8p());
12621262
self.call(lifetime_intrinsic, &[self.cx.const_u64(size), ptr], None);
12631263
}
12641264

src/librustc_codegen_llvm/common.rs

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

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

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

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

250250
fn const_u64(&self, i: u64) -> &'ll Value {
251-
&self.const_uint(&self.i64(), i)
251+
&self.const_uint(&self.type_i64(), i)
252252
}
253253

254254
fn const_usize(&self, i: u64) -> &'ll Value {
@@ -262,7 +262,7 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
262262
}
263263

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

268268

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

@@ -505,7 +505,7 @@ pub fn shift_mask_val(
505505
mask_llty: &'ll Type,
506506
invert: bool
507507
) -> &'ll Value {
508-
let kind = bx.cx().kind(llty);
508+
let kind = bx.cx().type_kind(llty);
509509
match kind {
510510
TypeKind::Integer => {
511511
// i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.

0 commit comments

Comments
 (0)