Skip to content

Commit abfa77c

Browse files
committed
Added self argument for Codegen CommonMethod trait methods
1 parent d9bb295 commit abfa77c

File tree

11 files changed

+121
-120
lines changed

11 files changed

+121
-120
lines changed

src/librustc_codegen_llvm/builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ impl BuilderMethods<'a, 'll, 'tcx>
541541
unsafe {
542542
let llty = CodegenCx::val_ty(load);
543543
let v = [
544-
CodegenCx::c_uint_big(llty, range.start),
545-
CodegenCx::c_uint_big(llty, range.end)
544+
self.cx.c_uint_big(llty, range.start),
545+
self.cx.c_uint_big(llty, range.end)
546546
];
547547

548548
llvm::LLVMSetMetadata(load, llvm::MD_range as c_uint,
@@ -850,7 +850,7 @@ impl BuilderMethods<'a, 'll, 'tcx>
850850
let undef = llvm::LLVMGetUndef(type_::Type::vector(elt_ty, num_elts as u64));
851851
let vec = self.insert_element(undef, elt, CodegenCx::c_i32(self.cx, 0));
852852
let vec_i32_ty = type_::Type::vector(type_::Type::i32(self.cx), num_elts as u64);
853-
self.shuffle_vector(vec, undef, CodegenCx::c_null(vec_i32_ty))
853+
self.shuffle_vector(vec, undef, self.cx.c_null(vec_i32_ty))
854854
}
855855
}
856856

src/librustc_codegen_llvm/common.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,51 +210,51 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
210210
}
211211

212212
// LLVM constant constructors.
213-
fn c_null(t: &'ll Type) -> &'ll Value {
213+
fn c_null(&self, t: &'ll Type) -> &'ll Value {
214214
unsafe {
215215
llvm::LLVMConstNull(t)
216216
}
217217
}
218218

219-
fn c_undef(t: &'ll Type) -> &'ll Value {
219+
fn c_undef(&self, t: &'ll Type) -> &'ll Value {
220220
unsafe {
221221
llvm::LLVMGetUndef(t)
222222
}
223223
}
224224

225-
fn c_int(t: &'ll Type, i: i64) -> &'ll Value {
225+
fn c_int(&self, t: &'ll Type, i: i64) -> &'ll Value {
226226
unsafe {
227227
llvm::LLVMConstInt(t, i as u64, True)
228228
}
229229
}
230230

231-
fn c_uint(t: &'ll Type, i: u64) -> &'ll Value {
231+
fn c_uint(&self, t: &'ll Type, i: u64) -> &'ll Value {
232232
unsafe {
233233
llvm::LLVMConstInt(t, i, False)
234234
}
235235
}
236236

237-
fn c_uint_big(t: &'ll Type, u: u128) -> &'ll Value {
237+
fn c_uint_big(&self, t: &'ll Type, u: u128) -> &'ll Value {
238238
unsafe {
239239
let words = [u as u64, (u >> 64) as u64];
240240
llvm::LLVMConstIntOfArbitraryPrecision(t, 2, words.as_ptr())
241241
}
242242
}
243243

244244
fn c_bool(&self, val: bool) -> &'ll Value {
245-
Self::c_uint(Type::i1(&self), val as u64)
245+
&self.c_uint(Type::i1(&self), val as u64)
246246
}
247247

248248
fn c_i32(&self, i: i32) -> &'ll Value {
249-
Self::c_int(Type::i32(&self), i as i64)
249+
&self.c_int(Type::i32(&self), i as i64)
250250
}
251251

252252
fn c_u32(&self, i: u32) -> &'ll Value {
253-
Self::c_uint(Type::i32(&self), i as u64)
253+
&self.c_uint(Type::i32(&self), i as u64)
254254
}
255255

256256
fn c_u64(&self, i: u64) -> &'ll Value {
257-
Self::c_uint(Type::i64(&self), i)
257+
&self.c_uint(Type::i64(&self), i)
258258
}
259259

260260
fn c_usize(&self, i: u64) -> &'ll Value {
@@ -264,11 +264,11 @@ impl<'ll, 'tcx : 'll> CommonMethods for CodegenCx<'ll, 'tcx, &'ll Value> {
264264
assert!(i < (1<<bit_size));
265265
}
266266

267-
Self::c_uint(&self.isize_ty, i)
267+
&self.c_uint(&self.isize_ty, i)
268268
}
269269

270270
fn c_u8(&self, i: u8) -> &'ll Value {
271-
Self::c_uint(Type::i8(&self), i as u64)
271+
&self.c_uint(Type::i8(&self), i as u64)
272272
}
273273

274274

@@ -494,9 +494,9 @@ pub fn shift_mask_val(
494494
// i8/u8 can shift by at most 7, i16/u16 by at most 15, etc.
495495
let val = llty.int_width() - 1;
496496
if invert {
497-
CodegenCx::c_int(mask_llty, !val as i64)
497+
bx.cx.c_int(mask_llty, !val as i64)
498498
} else {
499-
CodegenCx::c_uint(mask_llty, val)
499+
bx.cx.c_uint(mask_llty, val)
500500
}
501501
},
502502
TypeKind::Vector => {

src/librustc_codegen_llvm/interfaces/common.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ pub trait CommonMethods : Backend {
1515
fn val_ty(v: Self::Value) -> Self::Type;
1616

1717
// Constant constructors
18-
fn c_null(t: Self::Type) -> Self::Value;
19-
fn c_undef(t: Self::Type) -> Self::Value;
20-
fn c_int(t: Self::Type, i: i64) -> Self::Value;
21-
fn c_uint(t: Self::Type, i: u64) -> Self::Value;
22-
fn c_uint_big(t: Self::Type, u: u128) -> Self::Value;
18+
fn c_null(&self, t: Self::Type) -> Self::Value;
19+
fn c_undef(&self, t: Self::Type) -> Self::Value;
20+
fn c_int(&self, t: Self::Type, i: i64) -> Self::Value;
21+
fn c_uint(&self, t: Self::Type, i: u64) -> Self::Value;
22+
fn c_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
2323
fn c_bool(&self, val: bool) -> Self::Value;
2424
fn c_i32(&self, i: i32) -> Self::Value;
2525
fn c_u32(&self, i: u32) -> Self::Value;

src/librustc_codegen_llvm/intrinsic.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ pub fn codegen_intrinsic_call(
126126
},
127127
"likely" => {
128128
let expect = cx.get_intrinsic(&("llvm.expect.i1"));
129-
bx.call(expect, &[args[0].immediate(), CodegenCx::c_bool(cx, true)], None)
129+
bx.call(expect, &[args[0].immediate(), bx.cx().c_bool(true)], None)
130130
}
131131
"unlikely" => {
132132
let expect = cx.get_intrinsic(&("llvm.expect.i1"));
133-
bx.call(expect, &[args[0].immediate(), CodegenCx::c_bool(cx, false)], None)
133+
bx.call(expect, &[args[0].immediate(), bx.cx().c_bool(false)], None)
134134
}
135135
"try" => {
136136
try_intrinsic(bx, cx,
@@ -146,7 +146,7 @@ pub fn codegen_intrinsic_call(
146146
}
147147
"size_of" => {
148148
let tp_ty = substs.type_at(0);
149-
CodegenCx::c_usize(cx, cx.size_of(tp_ty).bytes())
149+
cx.c_usize(cx.size_of(tp_ty).bytes())
150150
}
151151
"size_of_val" => {
152152
let tp_ty = substs.type_at(0);
@@ -155,12 +155,12 @@ pub fn codegen_intrinsic_call(
155155
glue::size_and_align_of_dst(bx, tp_ty, Some(meta));
156156
llsize
157157
} else {
158-
CodegenCx::c_usize(cx, cx.size_of(tp_ty).bytes())
158+
cx.c_usize(cx.size_of(tp_ty).bytes())
159159
}
160160
}
161161
"min_align_of" => {
162162
let tp_ty = substs.type_at(0);
163-
CodegenCx::c_usize(cx, cx.align_of(tp_ty).abi())
163+
cx.c_usize(cx.align_of(tp_ty).abi())
164164
}
165165
"min_align_of_val" => {
166166
let tp_ty = substs.type_at(0);
@@ -169,20 +169,20 @@ pub fn codegen_intrinsic_call(
169169
glue::size_and_align_of_dst(bx, tp_ty, Some(meta));
170170
llalign
171171
} else {
172-
CodegenCx::c_usize(cx, cx.align_of(tp_ty).abi())
172+
cx.c_usize(cx.align_of(tp_ty).abi())
173173
}
174174
}
175175
"pref_align_of" => {
176176
let tp_ty = substs.type_at(0);
177-
CodegenCx::c_usize(cx, cx.align_of(tp_ty).pref())
177+
cx.c_usize(cx.align_of(tp_ty).pref())
178178
}
179179
"type_name" => {
180180
let tp_ty = substs.type_at(0);
181181
let ty_name = Symbol::intern(&tp_ty.to_string()).as_str();
182-
CodegenCx::c_str_slice(cx, ty_name)
182+
cx.c_str_slice(ty_name)
183183
}
184184
"type_id" => {
185-
CodegenCx::c_u64(cx, cx.tcx.type_id_hash(substs.type_at(0)))
185+
cx.c_u64(cx.tcx.type_id_hash(substs.type_at(0)))
186186
}
187187
"init" => {
188188
let ty = substs.type_at(0);
@@ -196,8 +196,8 @@ pub fn codegen_intrinsic_call(
196196
false,
197197
ty,
198198
llresult,
199-
CodegenCx::c_u8(cx, 0),
200-
CodegenCx::c_usize(cx, 1)
199+
cx.c_u8(0),
200+
cx.c_usize(1)
201201
);
202202
}
203203
return;
@@ -209,7 +209,7 @@ pub fn codegen_intrinsic_call(
209209
"needs_drop" => {
210210
let tp_ty = substs.type_at(0);
211211

212-
CodegenCx::c_bool(cx, bx.cx().type_needs_drop(tp_ty))
212+
cx.c_bool(bx.cx().type_needs_drop(tp_ty))
213213
}
214214
"offset" => {
215215
let ptr = args[0].immediate();
@@ -286,9 +286,9 @@ pub fn codegen_intrinsic_call(
286286
};
287287
bx.call(expect, &[
288288
args[0].immediate(),
289-
CodegenCx::c_i32(cx, rw),
289+
cx.c_i32(rw),
290290
args[1].immediate(),
291-
CodegenCx::c_i32(cx, cache_type)
291+
cx.c_i32(cache_type)
292292
], None)
293293
},
294294
"ctlz" | "ctlz_nonzero" | "cttz" | "cttz_nonzero" | "ctpop" | "bswap" |
@@ -300,12 +300,12 @@ pub fn codegen_intrinsic_call(
300300
Some((width, signed)) =>
301301
match name {
302302
"ctlz" | "cttz" => {
303-
let y = CodegenCx::c_bool(bx.cx(), false);
303+
let y = cx.c_bool(false);
304304
let llfn = cx.get_intrinsic(&format!("llvm.{}.i{}", name, width));
305305
bx.call(llfn, &[args[0].immediate(), y], None)
306306
}
307307
"ctlz_nonzero" | "cttz_nonzero" => {
308-
let y = CodegenCx::c_bool(bx.cx(), true);
308+
let y = cx.c_bool(true);
309309
let llvm_name = &format!("llvm.{}.i{}", &name[..4], width);
310310
let llfn = cx.get_intrinsic(llvm_name);
311311
bx.call(llfn, &[args[0].immediate(), y], None)
@@ -707,8 +707,8 @@ fn copy_intrinsic(
707707
) -> &'ll Value {
708708
let cx = bx.cx();
709709
let (size, align) = cx.size_and_align_of(ty);
710-
let size = CodegenCx::c_usize(cx, size.bytes());
711-
let align = CodegenCx::c_i32(cx, align.abi() as i32);
710+
let size = cx.c_usize(size.bytes());
711+
let align = cx.c_i32(align.abi() as i32);
712712

713713
let operation = if allow_overlap {
714714
"memmove"
@@ -728,7 +728,7 @@ fn copy_intrinsic(
728728
src_ptr,
729729
bx.mul(size, count),
730730
align,
731-
CodegenCx::c_bool(cx, volatile)],
731+
cx.c_bool(volatile)],
732732
None)
733733
}
734734

@@ -742,8 +742,8 @@ fn memset_intrinsic(
742742
) -> &'ll Value {
743743
let cx = bx.cx();
744744
let (size, align) = cx.size_and_align_of(ty);
745-
let size = CodegenCx::c_usize(cx, size.bytes());
746-
let align = CodegenCx::c_i32(cx, align.abi() as i32);
745+
let size = cx.c_usize(size.bytes());
746+
let align = cx.c_i32(align.abi() as i32);
747747
let dst = bx.pointercast(dst, Type::i8p(cx));
748748
call_memset(bx, dst, val, bx.mul(size, count), align, volatile)
749749
}
@@ -759,7 +759,7 @@ fn try_intrinsic(
759759
if bx.sess().no_landing_pads() {
760760
bx.call(func, &[data], None);
761761
let ptr_align = bx.tcx().data_layout.pointer_align;
762-
bx.store(CodegenCx::c_null(Type::i8p(&bx.cx())), dest, ptr_align);
762+
bx.store(bx.cx().c_null(Type::i8p(&bx.cx())), dest, ptr_align);
763763
} else if wants_msvc_seh(bx.sess()) {
764764
codegen_msvc_try(bx, cx, func, data, local_ptr, dest);
765765
} else {
@@ -841,7 +841,7 @@ fn codegen_msvc_try(
841841
bx.invoke(func, &[data], normal.llbb(), catchswitch.llbb(),
842842
None);
843843

844-
normal.ret(CodegenCx::c_i32(cx, 0));
844+
normal.ret(cx.c_i32(0));
845845

846846
let cs = catchswitch.catch_switch(None, None, 1);
847847
catchswitch.add_handler(cs, catchpad.llbb());
@@ -851,19 +851,19 @@ fn codegen_msvc_try(
851851
Some(did) => ::consts::get_static(cx, did),
852852
None => bug!("msvc_try_filter not defined"),
853853
};
854-
let tok = catchpad.catch_pad(cs, &[tydesc, CodegenCx::c_i32(cx, 0), slot]);
854+
let tok = catchpad.catch_pad(cs, &[tydesc, cx.c_i32(0), slot]);
855855
let addr = catchpad.load(slot, ptr_align);
856856

857857
let i64_align = bx.tcx().data_layout.i64_align;
858858
let arg1 = catchpad.load(addr, i64_align);
859-
let val1 = CodegenCx::c_i32(cx, 1);
859+
let val1 = cx.c_i32(1);
860860
let arg2 = catchpad.load(catchpad.inbounds_gep(addr, &[val1]), i64_align);
861861
let local_ptr = catchpad.bitcast(local_ptr, i64p);
862862
catchpad.store(arg1, local_ptr, i64_align);
863863
catchpad.store(arg2, catchpad.inbounds_gep(local_ptr, &[val1]), i64_align);
864864
catchpad.catch_ret(tok, caught.llbb());
865865

866-
caught.ret(CodegenCx::c_i32(cx, 1));
866+
caught.ret(cx.c_i32(1));
867867
});
868868

869869
// Note that no invoke is used here because by definition this function
@@ -919,7 +919,7 @@ fn codegen_gnu_try(
919919
let data = llvm::get_param(bx.llfn(), 1);
920920
let local_ptr = llvm::get_param(bx.llfn(), 2);
921921
bx.invoke(func, &[data], then.llbb(), catch.llbb(), None);
922-
then.ret(CodegenCx::c_i32(cx, 0));
922+
then.ret(cx.c_i32(0));
923923

924924
// Type indicator for the exception being thrown.
925925
//
@@ -930,11 +930,11 @@ fn codegen_gnu_try(
930930
let lpad_ty = Type::struct_(cx, &[Type::i8p(cx), Type::i32(cx)],
931931
false);
932932
let vals = catch.landing_pad(lpad_ty, bx.cx().eh_personality(), 1);
933-
catch.add_clause(vals, CodegenCx::c_null(Type::i8p(cx)));
933+
catch.add_clause(vals, bx.cx().c_null(Type::i8p(cx)));
934934
let ptr = catch.extract_value(vals, 0);
935935
let ptr_align = bx.tcx().data_layout.pointer_align;
936936
catch.store(ptr, catch.bitcast(local_ptr, Type::i8p(cx).ptr_to()), ptr_align);
937-
catch.ret(CodegenCx::c_i32(cx, 1));
937+
catch.ret(cx.c_i32(1));
938938
});
939939

940940
// Note that no invoke is used here because by definition this function
@@ -1127,13 +1127,13 @@ fn generic_simd_intrinsic(
11271127
arg_idx, total_len);
11281128
None
11291129
}
1130-
Some(idx) => Some(CodegenCx::c_i32(bx.cx(), idx as i32)),
1130+
Some(idx) => Some(bx.cx().c_i32(idx as i32)),
11311131
}
11321132
})
11331133
.collect();
11341134
let indices = match indices {
11351135
Some(i) => i,
1136-
None => return Ok(CodegenCx::c_null(llret_ty))
1136+
None => return Ok(bx.cx().c_null(llret_ty))
11371137
};
11381138

11391139
return Ok(bx.shuffle_vector(args[0].immediate(),
@@ -1402,7 +1402,7 @@ fn generic_simd_intrinsic(
14021402

14031403
// Alignment of T, must be a constant integer value:
14041404
let alignment_ty = Type::i32(bx.cx());
1405-
let alignment = CodegenCx::c_i32(bx.cx(), bx.cx().align_of(in_elem).abi() as i32);
1405+
let alignment = bx.cx().c_i32(bx.cx().align_of(in_elem).abi() as i32);
14061406

14071407
// Truncate the mask vector to a vector of i1s:
14081408
let (mask, mask_ty) = {
@@ -1502,7 +1502,7 @@ fn generic_simd_intrinsic(
15021502

15031503
// Alignment of T, must be a constant integer value:
15041504
let alignment_ty = Type::i32(bx.cx());
1505-
let alignment = CodegenCx::c_i32(bx.cx(), bx.cx().align_of(in_elem).abi() as i32);
1505+
let alignment = bx.cx().c_i32(bx.cx().align_of(in_elem).abi() as i32);
15061506

15071507
// Truncate the mask vector to a vector of i1s:
15081508
let (mask, mask_ty) = {
@@ -1580,8 +1580,8 @@ fn generic_simd_intrinsic(
15801580
} else {
15811581
// unordered arithmetic reductions do not:
15821582
match f.bit_width() {
1583-
32 => CodegenCx::c_undef(Type::f32(bx.cx())),
1584-
64 => CodegenCx::c_undef(Type::f64(bx.cx())),
1583+
32 => bx.cx().c_undef(Type::f32(bx.cx())),
1584+
64 => bx.cx().c_undef(Type::f64(bx.cx())),
15851585
v => {
15861586
return_error!(r#"
15871587
unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,

src/librustc_codegen_llvm/meth.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub fn get_vtable(
9696
}
9797

9898
// Not in the cache. Build it.
99-
let nullptr = CodegenCx::c_null(Type::i8p(cx));
99+
let nullptr = cx.c_null(Type::i8p(cx));
100100

101101
let (size, align) = cx.size_and_align_of(ty);
102102
let mut components: Vec<_> = [

0 commit comments

Comments
 (0)