Skip to content

Commit 29591b5

Browse files
committed
Use the method form for CodegenCx everywhere
1 parent 9d0a506 commit 29591b5

File tree

12 files changed

+44
-45
lines changed

12 files changed

+44
-45
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
242242
base::call_memcpy(bx,
243243
bx.pointercast(dst.llval, Type::i8p(cx)),
244244
bx.pointercast(llscratch, Type::i8p(cx)),
245-
CodegenCx::c_usize(cx, self.layout.size.bytes()),
245+
cx.c_usize(self.layout.size.bytes()),
246246
self.layout.align.min(scratch_align),
247247
MemFlags::empty());
248248

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ pub fn codegen_inline_asm(
107107
let kind = llvm::LLVMGetMDKindIDInContext(bx.cx().llcx,
108108
key.as_ptr() as *const c_char, key.len() as c_uint);
109109

110-
let val: &'ll Value = CodegenCx::c_i32(bx.cx(), ia.ctxt.outer().as_u32() as i32);
110+
let val: &'ll Value = bx.cx().c_i32(ia.ctxt.outer().as_u32() as i32);
111111

112112
llvm::LLVMSetMetadata(r, kind,
113113
llvm::LLVMMDNodeInContext(bx.cx().llcx, &val, 1));

src/librustc_codegen_llvm/base.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ pub fn bin_op_to_fcmp_predicate(op: hir::BinOpKind) -> RealPredicate {
157157
}
158158
}
159159

160-
pub fn compare_simd_types(
161-
bx: &Builder<'a, 'll, 'tcx, &'ll Value>,
162-
lhs: &'ll Value,
163-
rhs: &'ll Value,
160+
pub fn compare_simd_types<'a, 'll:'a, 'tcx:'ll, Builder : BuilderMethods<'a, 'll, 'tcx>>(
161+
bx: &Builder,
162+
lhs: Builder::Value,
163+
rhs: Builder::Value,
164164
t: Ty<'tcx>,
165-
ret_ty: &'ll Type,
165+
ret_ty: Builder::Type,
166166
op: hir::BinOpKind
167-
) -> &'ll Value {
167+
) -> Builder::Value {
168168
let signed = match t.sty {
169169
ty::Float(_) => {
170170
let cmp = bin_op_to_fcmp_predicate(op);
@@ -198,7 +198,7 @@ pub fn unsized_info(
198198
let (source, target) = cx.tcx.struct_lockstep_tails(source, target);
199199
match (&source.sty, &target.sty) {
200200
(&ty::Array(_, len), &ty::Slice(_)) => {
201-
CodegenCx::c_usize(cx, len.unwrap_usize(cx.tcx))
201+
cx.c_usize(len.unwrap_usize(cx.tcx))
202202
}
203203
(&ty::Dynamic(..), &ty::Dynamic(..)) => {
204204
// For now, upcasts are limited to changes in marker
@@ -444,8 +444,8 @@ pub fn call_memcpy<'a, 'll: 'a, 'tcx: 'll>(
444444
let src_ptr = bx.pointercast(src, Type::i8p(cx));
445445
let dst_ptr = bx.pointercast(dst, Type::i8p(cx));
446446
let size = bx.intcast(n_bytes, cx.isize_ty, false);
447-
let align = CodegenCx::c_i32(cx, align.abi() as i32);
448-
let volatile = CodegenCx::c_bool(cx, flags.contains(MemFlags::VOLATILE));
447+
let align = cx.c_i32(align.abi() as i32);
448+
let volatile = cx.c_bool(flags.contains(MemFlags::VOLATILE));
449449
bx.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
450450
}
451451

@@ -462,7 +462,7 @@ pub fn memcpy_ty<'a, 'll: 'a, 'tcx: 'll>(
462462
return;
463463
}
464464

465-
call_memcpy(bx, dst, src, CodegenCx::c_usize(bx.cx(), size), align, flags);
465+
call_memcpy(bx, dst, src, bx.cx().c_usize(size), align, flags);
466466
}
467467

468468
pub fn call_memset(
@@ -476,7 +476,7 @@ pub fn call_memset(
476476
let ptr_width = &bx.cx().sess().target.target.target_pointer_width;
477477
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
478478
let llintrinsicfn = bx.cx().get_intrinsic(&intrinsic_key);
479-
let volatile = CodegenCx::c_bool(bx.cx(), volatile);
479+
let volatile = bx.cx().c_bool(volatile);
480480
bx.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None)
481481
}
482482

src/librustc_codegen_llvm/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
607607
// *always* point to a metadata value of the integer 1.
608608
//
609609
// [1]: http://llvm.org/docs/LangRef.html#store-instruction
610-
let one = CodegenCx::c_i32(self.cx, 1);
610+
let one = self.cx.c_i32(1);
611611
let node = llvm::LLVMMDNodeInContext(self.cx.llcx, &one, 1);
612612
llvm::LLVMSetMetadata(store, llvm::MD_nontemporal as c_uint, node);
613613
}
@@ -848,7 +848,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
848848
unsafe {
849849
let elt_ty = self.cx.val_ty(elt);
850850
let undef = llvm::LLVMGetUndef(type_::Type::vector(elt_ty, num_elts as u64));
851-
let vec = self.insert_element(undef, elt, CodegenCx::c_i32(self.cx, 0));
851+
let vec = self.insert_element(undef, elt, self.cx.c_i32(0));
852852
let vec_i32_ty = type_::Type::vector(type_::Type::i32(self.cx), num_elts as u64);
853853
self.shuffle_vector(vec, undef, self.cx.c_null(vec_i32_ty))
854854
}
@@ -1245,7 +1245,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
12451245
let lifetime_intrinsic = self.cx.get_intrinsic(intrinsic);
12461246

12471247
let ptr = self.pointercast(ptr, type_::Type::i8p(self.cx));
1248-
self.call(lifetime_intrinsic, &[CodegenCx::c_u64(self.cx, size), ptr], None);
1248+
self.call(lifetime_intrinsic, &[self.cx.c_u64(size), ptr], None);
12491249
}
12501250

12511251
fn call(&self, llfn: &'ll Value, args: &[&'ll Value],

src/librustc_codegen_llvm/debuginfo/gdb.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &Builder<'_, 'll
3030
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx.cx());
3131
// Load just the first byte as that's all that's necessary to force
3232
// LLVM to keep around the reference to the global.
33-
let indices = [CodegenCx::c_i32(bx.cx(), 0), CodegenCx::c_i32(bx.cx(), 0)];
33+
let indices = [bx.cx().c_i32(0), bx.cx().c_i32(0)];
3434
let element = bx.inbounds_gep(gdb_debug_scripts_section, &indices);
3535
let volative_load_instruction = bx.volatile_load(element);
3636
unsafe {
@@ -64,7 +64,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_, &'
6464
bug!("symbol `{}` is already defined", section_var_name)
6565
});
6666
llvm::LLVMSetSection(section_var, section_name.as_ptr() as *const _);
67-
llvm::LLVMSetInitializer(section_var, CodegenCx::c_bytes(cx, section_contents));
67+
llvm::LLVMSetInitializer(section_var, cx.c_bytes(section_contents));
6868
llvm::LLVMSetGlobalConstant(section_var, llvm::True);
6969
llvm::LLVMSetUnnamedAddr(section_var, llvm::True);
7070
llvm::LLVMRustSetLinkage(section_var, llvm::Linkage::LinkOnceODRLinkage);

src/librustc_codegen_llvm/glue.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std;
1616

1717
use builder::Builder;
1818
use common::*;
19-
use context::CodegenCx;
2019
use meth;
2120
use rustc::ty::layout::LayoutOf;
2221
use rustc::ty::{self, Ty};
@@ -66,8 +65,8 @@ pub fn size_and_align_of_dst(
6665
let sized_align = layout.align.abi();
6766
debug!("DST {} statically sized prefix size: {} align: {}",
6867
t, sized_size, sized_align);
69-
let sized_size = CodegenCx::c_usize(cx, sized_size);
70-
let sized_align = CodegenCx::c_usize(cx, sized_align);
68+
let sized_size = cx.c_usize(sized_size);
69+
let sized_align = cx.c_usize(sized_align);
7170

7271
// Recurse to get the size of the dynamically sized field (must be
7372
// the last field).
@@ -98,7 +97,7 @@ pub fn size_and_align_of_dst(
9897
(Some(sized_align), Some(unsized_align)) => {
9998
// If both alignments are constant, (the sized_align should always be), then
10099
// pick the correct alignment statically.
101-
CodegenCx::c_usize(cx, std::cmp::max(sized_align, unsized_align) as u64)
100+
cx.c_usize(std::cmp::max(sized_align, unsized_align) as u64)
102101
}
103102
_ => bx.select(bx.icmp(IntPredicate::IntUGT, sized_align, unsized_align),
104103
sized_align,
@@ -116,7 +115,7 @@ pub fn size_and_align_of_dst(
116115
//
117116
// `(size + (align-1)) & -align`
118117

119-
let addend = bx.sub(align, CodegenCx::c_usize(bx.cx(), 1));
118+
let addend = bx.sub(align, bx.cx().c_usize(1));
120119
let size = bx.and(bx.add(size, addend), bx.neg(align));
121120

122121
(size, align)

src/librustc_codegen_llvm/interfaces/backend.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::fmt::Debug;
12+
1113
pub trait Backend {
12-
type Value;
14+
type Value : Debug + PartialEq;
1315
type BasicBlock;
1416
type Type;
1517
type Context;

src/librustc_codegen_llvm/interfaces/common.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ pub trait CommonMethods : Backend + CommonWriteMethods {
4747
fn const_get_elt(&self, v: Self::Value, idx: u64) -> Self::Value;
4848
fn const_get_real(&self, v: Self::Value) -> Option<(f64, bool)>;
4949
fn const_to_uint(&self, v: Self::Value) -> u64;
50+
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
51+
5052
fn is_const_integral(&self, v: Self::Value) -> bool;
5153
fn is_const_real(&self, v: Self::Value) -> bool;
52-
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
5354
}
5455

5556
pub trait CommonWriteMethods : Backend {

src/librustc_codegen_llvm/meth.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a, 'tcx> VirtualIndex {
4444
let llvtable = bx.pointercast(llvtable, fn_ty.llvm_type(bx.cx()).ptr_to().ptr_to());
4545
let ptr_align = bx.tcx().data_layout.pointer_align;
4646
let ptr = bx.load(
47-
bx.inbounds_gep(llvtable, &[CodegenCx::c_usize(bx.cx(), self.0)]),
47+
bx.inbounds_gep(llvtable, &[bx.cx().c_usize(self.0)]),
4848
ptr_align
4949
);
5050
bx.nonnull_metadata(ptr);
@@ -64,7 +64,7 @@ impl<'a, 'tcx> VirtualIndex {
6464
let llvtable = bx.pointercast(llvtable, Type::isize(bx.cx()).ptr_to());
6565
let usize_align = bx.tcx().data_layout.pointer_align;
6666
let ptr = bx.load(
67-
bx.inbounds_gep(llvtable, &[CodegenCx::c_usize(bx.cx(), self.0)]),
67+
bx.inbounds_gep(llvtable, &[bx.cx().c_usize(self.0)]),
6868
usize_align
6969
);
7070
// Vtable loads are invariant
@@ -101,8 +101,8 @@ pub fn get_vtable(
101101
let (size, align) = cx.size_and_align_of(ty);
102102
let mut components: Vec<_> = [
103103
callee::get_fn(cx, monomorphize::resolve_drop_in_place(cx.tcx, ty)),
104-
CodegenCx::c_usize(cx, size.bytes()),
105-
CodegenCx::c_usize(cx, align.abi())
104+
cx.c_usize(size.bytes()),
105+
cx.c_usize(align.abi())
106106
].iter().cloned().collect();
107107

108108
if let Some(trait_ref) = trait_ref {
@@ -116,7 +116,7 @@ pub fn get_vtable(
116116
components.extend(methods);
117117
}
118118

119-
let vtable_const = CodegenCx::c_struct(cx, &components, false);
119+
let vtable_const = cx.c_struct(&components, false);
120120
let align = cx.data_layout().pointer_align;
121121
let vtable = consts::addr_of(cx, vtable_const, align, Some("vtable"));
122122

src/librustc_codegen_llvm/mir/block.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use base;
1919
use callee;
2020
use builder::{Builder, MemFlags};
2121
use common::{self, IntPredicate};
22-
use context::CodegenCx;
2322
use consts;
2423
use meth;
2524
use monomorphize;
@@ -347,7 +346,7 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
347346

348347
// Pass the condition through llvm.expect for branch hinting.
349348
let expect = bx.cx().get_intrinsic(&"llvm.expect.i1");
350-
let cond = bx.call(expect, &[cond, CodegenCx::c_bool(bx.cx(), expected)], None);
349+
let cond = bx.call(expect, &[cond, bx.cx().c_bool(expected)], None);
351350

352351
// Create the failure block and the conditional branch to it.
353352
let lltarget = llblock(self, target);
@@ -365,9 +364,9 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
365364
// Get the location information.
366365
let loc = bx.sess().source_map().lookup_char_pos(span.lo());
367366
let filename = Symbol::intern(&loc.file.name.to_string()).as_str();
368-
let filename = CodegenCx::c_str_slice(bx.cx(), filename);
369-
let line = CodegenCx::c_u32(bx.cx(), loc.line as u32);
370-
let col = CodegenCx::c_u32(bx.cx(), loc.col.to_usize() as u32 + 1);
367+
let filename = bx.cx().c_str_slice(filename);
368+
let line = bx.cx().c_u32(loc.line as u32);
369+
let col = bx.cx().c_u32(loc.col.to_usize() as u32 + 1);
371370
let align = tcx.data_layout.aggregate_align
372371
.max(tcx.data_layout.i32_align)
373372
.max(tcx.data_layout.pointer_align);
@@ -378,8 +377,7 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
378377
let len = self.codegen_operand(&mut bx, len).immediate();
379378
let index = self.codegen_operand(&mut bx, index).immediate();
380379

381-
let file_line_col = CodegenCx::c_struct(bx.cx(),
382-
&[filename, line, col], false);
380+
let file_line_col = bx.cx().c_struct( &[filename, line, col], false);
383381
let file_line_col = consts::addr_of(bx.cx(),
384382
file_line_col,
385383
align,
@@ -390,9 +388,8 @@ impl FunctionCx<'a, 'll, 'tcx, &'ll Value> {
390388
_ => {
391389
let str = msg.description();
392390
let msg_str = Symbol::intern(str).as_str();
393-
let msg_str = CodegenCx::c_str_slice(bx.cx(), msg_str);
394-
let msg_file_line_col = CodegenCx::c_struct(bx.cx(),
395-
&[msg_str, filename, line, col],
391+
let msg_str = bx.cx().c_str_slice(msg_str);
392+
let msg_file_line_col = bx.cx().c_struct( &[msg_str, filename, line, col],
396393
false);
397394
let msg_file_line_col = consts::addr_of(bx.cx(),
398395
msg_file_line_col,

0 commit comments

Comments
 (0)