Skip to content

Commit d9bb295

Browse files
committed
Replaced Codegen field access by trait method
1 parent c2739a9 commit d9bb295

File tree

15 files changed

+246
-246
lines changed

15 files changed

+246
-246
lines changed

src/librustc_codegen_llvm/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
202202
if self.is_ignore() {
203203
return;
204204
}
205-
let cx = bx.cx;
205+
let cx = bx.cx();
206206
if self.is_sized_indirect() {
207207
OperandValue::Ref(val, None, self.layout.align).store(bx, dst)
208208
} else if self.is_unsized_indirect() {
@@ -720,7 +720,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
720720
// by the LLVM verifier.
721721
match scalar.value {
722722
layout::Int(..) if !scalar.is_bool() => {
723-
let range = scalar.valid_range_exclusive(bx.cx);
723+
let range = scalar.valid_range_exclusive(bx.cx());
724724
if range.start != range.end {
725725
bx.range_metadata(callsite, range);
726726
}

src/librustc_codegen_llvm/asm.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn codegen_inline_asm(
4444
if out.is_indirect {
4545
indirect_outputs.push(place.load(bx).immediate());
4646
} else {
47-
output_types.push(place.layout.llvm_type(bx.cx));
47+
output_types.push(place.layout.llvm_type(bx.cx()));
4848
}
4949
}
5050
if !indirect_outputs.is_empty() {
@@ -76,9 +76,9 @@ pub fn codegen_inline_asm(
7676
// Depending on how many outputs we have, the return type is different
7777
let num_outputs = output_types.len();
7878
let output_type = match num_outputs {
79-
0 => Type::void(bx.cx),
79+
0 => Type::void(bx.cx()),
8080
1 => output_types[0],
81-
_ => Type::struct_(bx.cx, &output_types, false)
81+
_ => Type::struct_(bx.cx(), &output_types, false)
8282
};
8383

8484
let asm = CString::new(ia.asm.as_str().as_bytes()).unwrap();
@@ -104,13 +104,13 @@ pub fn codegen_inline_asm(
104104
// back to source locations. See #17552.
105105
unsafe {
106106
let key = "srcloc";
107-
let kind = llvm::LLVMGetMDKindIDInContext(bx.cx.llcx,
107+
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 = CodegenCx::c_i32(bx.cx(), ia.ctxt.outer().as_u32() as i32);
111111

112112
llvm::LLVMSetMetadata(r, kind,
113-
llvm::LLVMMDNodeInContext(bx.cx.llcx, &val, 1));
113+
llvm::LLVMMDNodeInContext(bx.cx().llcx, &val, 1));
114114
}
115115
}
116116

src/librustc_codegen_llvm/base.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -233,40 +233,40 @@ pub fn unsize_thin_ptr(
233233
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) |
234234
(&ty::RawPtr(ty::TypeAndMut { ty: a, .. }),
235235
&ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
236-
assert!(bx.cx.type_is_sized(a));
237-
let ptr_ty = bx.cx.layout_of(b).llvm_type(bx.cx).ptr_to();
238-
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx, a, b, None))
236+
assert!(bx.cx().type_is_sized(a));
237+
let ptr_ty = bx.cx().layout_of(b).llvm_type(bx.cx()).ptr_to();
238+
(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());
242-
assert!(bx.cx.type_is_sized(a));
243-
let ptr_ty = bx.cx.layout_of(b).llvm_type(bx.cx).ptr_to();
244-
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx, a, b, None))
242+
assert!(bx.cx().type_is_sized(a));
243+
let ptr_ty = bx.cx().layout_of(b).llvm_type(bx.cx()).ptr_to();
244+
(bx.pointercast(src, ptr_ty), unsized_info(bx.cx(), a, b, None))
245245
}
246246
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
247247
assert_eq!(def_a, def_b);
248248

249-
let src_layout = bx.cx.layout_of(src_ty);
250-
let dst_layout = bx.cx.layout_of(dst_ty);
249+
let src_layout = bx.cx().layout_of(src_ty);
250+
let dst_layout = bx.cx().layout_of(dst_ty);
251251
let mut result = None;
252252
for i in 0..src_layout.fields.count() {
253-
let src_f = src_layout.field(bx.cx, i);
253+
let src_f = src_layout.field(bx.cx(), i);
254254
assert_eq!(src_layout.fields.offset(i).bytes(), 0);
255255
assert_eq!(dst_layout.fields.offset(i).bytes(), 0);
256256
if src_f.is_zst() {
257257
continue;
258258
}
259259
assert_eq!(src_layout.size, src_f.size);
260260

261-
let dst_f = dst_layout.field(bx.cx, i);
261+
let dst_f = dst_layout.field(bx.cx(), i);
262262
assert_ne!(src_f.ty, dst_f.ty);
263263
assert_eq!(result, None);
264264
result = Some(unsize_thin_ptr(bx, src, src_f.ty, dst_f.ty));
265265
}
266266
let (lldata, llextra) = result.unwrap();
267267
// HACK(eddyb) have to bitcast pointers until LLVM removes pointee types.
268-
(bx.bitcast(lldata, dst_layout.scalar_pair_element_llvm_type(bx.cx, 0, true)),
269-
bx.bitcast(llextra, dst_layout.scalar_pair_element_llvm_type(bx.cx, 1, true)))
268+
(bx.bitcast(lldata, dst_layout.scalar_pair_element_llvm_type(bx.cx(), 0, true)),
269+
bx.bitcast(llextra, dst_layout.scalar_pair_element_llvm_type(bx.cx(), 1, true)))
270270
}
271271
_ => bug!("unsize_thin_ptr: called on bad types"),
272272
}
@@ -288,8 +288,8 @@ pub fn coerce_unsized_into(
288288
// i.e. &'a fmt::Debug+Send => &'a fmt::Debug
289289
// So we need to pointercast the base to ensure
290290
// the types match up.
291-
let thin_ptr = dst.layout.field(bx.cx, abi::FAT_PTR_ADDR);
292-
(bx.pointercast(base, thin_ptr.llvm_type(bx.cx)), info)
291+
let thin_ptr = dst.layout.field(bx.cx(), abi::FAT_PTR_ADDR);
292+
(bx.pointercast(base, thin_ptr.llvm_type(bx.cx())), info)
293293
}
294294
OperandValue::Immediate(base) => {
295295
unsize_thin_ptr(bx, base, src_ty, dst_ty)
@@ -384,7 +384,7 @@ pub fn wants_msvc_seh(sess: &Session) -> bool {
384384
}
385385

386386
pub fn call_assume(bx: &Builder<'_, 'll, '_, &'ll Value>, val: &'ll Value) {
387-
let assume_intrinsic = bx.cx.get_intrinsic("llvm.assume");
387+
let assume_intrinsic = bx.cx().get_intrinsic("llvm.assume");
388388
bx.call(assume_intrinsic, &[val], None);
389389
}
390390

@@ -416,7 +416,7 @@ pub fn to_immediate_scalar(
416416
scalar: &layout::Scalar,
417417
) -> &'ll Value {
418418
if scalar.is_bool() {
419-
return bx.trunc(val, Type::i1(bx.cx));
419+
return bx.trunc(val, Type::i1(bx.cx()));
420420
}
421421
val
422422
}
@@ -472,10 +472,10 @@ pub fn call_memset(
472472
align: &'ll Value,
473473
volatile: bool,
474474
) -> &'ll Value {
475-
let ptr_width = &bx.cx.sess().target.target.target_pointer_width;
475+
let ptr_width = &bx.cx().sess().target.target.target_pointer_width;
476476
let intrinsic_key = format!("llvm.memset.p0i8.i{}", ptr_width);
477-
let llintrinsicfn = bx.cx.get_intrinsic(&intrinsic_key);
478-
let volatile = CodegenCx::c_bool(bx.cx, volatile);
477+
let llintrinsicfn = bx.cx().get_intrinsic(&intrinsic_key);
478+
let volatile = CodegenCx::c_bool(bx.cx(), volatile);
479479
bx.call(llintrinsicfn, &[ptr, fill_byte, size, align, volatile], None)
480480
}
481481

src/librustc_codegen_llvm/debuginfo/gdb.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use syntax::attr;
2626
/// Inserts a side-effect free instruction sequence that makes sure that the
2727
/// .debug_gdb_scripts global is referenced, so it isn't removed by the linker.
2828
pub fn insert_reference_to_gdb_debug_scripts_section_global(bx: &Builder<'_, 'll, '_, &'ll Value>) {
29-
if needs_gdb_debug_scripts_section(bx.cx) {
30-
let gdb_debug_scripts_section = get_or_insert_gdb_debug_scripts_section_global(bx.cx);
29+
if needs_gdb_debug_scripts_section(bx.cx()) {
30+
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 = [CodegenCx::c_i32(bx.cx(), 0), CodegenCx::c_i32(bx.cx(), 0)];
3434
let element = bx.inbounds_gep(gdb_debug_scripts_section, &indices);
3535
let volative_load_instruction = bx.volatile_load(element);
3636
unsafe {

src/librustc_codegen_llvm/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub fn declare_local(
496496
span: Span,
497497
) {
498498
assert!(!dbg_context.get_ref(span).source_locations_enabled.get());
499-
let cx = bx.cx;
499+
let cx = bx.cx();
500500

501501
let file = span_start(cx, span).file;
502502
let file_metadata = file_metadata(cx,

src/librustc_codegen_llvm/debuginfo/source_loc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn set_source_location(
4343

4444
let dbg_loc = if function_debug_context.source_locations_enabled.get() {
4545
debug!("set_source_location: {}", bx.sess().source_map().span_to_string(span));
46-
let loc = span_start(bx.cx, span);
46+
let loc = span_start(bx.cx(), span);
4747
InternalDebugLocation::new(scope.unwrap(), loc.line, loc.col.to_usize())
4848
} else {
4949
UnknownLocation
@@ -92,7 +92,7 @@ pub fn set_debug_location(
9292
// For MSVC, set the column number to zero.
9393
// Otherwise, emit it. This mimics clang behaviour.
9494
// See discussion in https://github.com/rust-lang/rust/issues/42921
95-
let col_used = if bx.cx.sess().target.target.options.is_like_msvc {
95+
let col_used = if bx.cx().sess().target.target.options.is_like_msvc {
9696
UNKNOWN_COLUMN_NUMBER
9797
} else {
9898
col as c_uint
@@ -101,7 +101,7 @@ pub fn set_debug_location(
101101

102102
unsafe {
103103
Some(llvm::LLVMRustDIBuilderCreateDebugLocation(
104-
debug_context(bx.cx).llcontext,
104+
debug_context(bx.cx()).llcontext,
105105
line as c_uint,
106106
col_used,
107107
scope,

src/librustc_codegen_llvm/glue.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ pub fn size_and_align_of_dst(
3030
) -> (&'ll Value, &'ll Value) {
3131
debug!("calculate size of DST: {}; with lost info: {:?}",
3232
t, info);
33-
if bx.cx.type_is_sized(t) {
34-
let (size, align) = bx.cx.size_and_align_of(t);
33+
if bx.cx().type_is_sized(t) {
34+
let (size, align) = bx.cx().size_and_align_of(t);
3535
debug!("size_and_align_of_dst t={} info={:?} size: {:?} align: {:?}",
3636
t, info, size, align);
37-
let size = CodegenCx::c_usize(bx.cx, size.bytes());
38-
let align = CodegenCx::c_usize(bx.cx, align.abi());
37+
let size = CodegenCx::c_usize(bx.cx(), size.bytes());
38+
let align = CodegenCx::c_usize(bx.cx(), align.abi());
3939
return (size, align);
4040
}
4141
match t.sty {
@@ -48,12 +48,12 @@ pub fn size_and_align_of_dst(
4848
let unit = t.sequence_element_type(bx.tcx());
4949
// The info in this case is the length of the str, so the size is that
5050
// times the unit size.
51-
let (size, align) = bx.cx.size_and_align_of(unit);
52-
(bx.mul(info.unwrap(), CodegenCx::c_usize(bx.cx, size.bytes())),
53-
CodegenCx::c_usize(bx.cx, align.abi()))
51+
let (size, align) = bx.cx().size_and_align_of(unit);
52+
(bx.mul(info.unwrap(), CodegenCx::c_usize(bx.cx(), size.bytes())),
53+
CodegenCx::c_usize(bx.cx(), align.abi()))
5454
}
5555
_ => {
56-
let cx = bx.cx;
56+
let cx = bx.cx();
5757
// First get the size of all statically known fields.
5858
// Don't use size_of because it also rounds up to alignment, which we
5959
// want to avoid, as the unsized field's alignment could be smaller.
@@ -116,7 +116,7 @@ pub fn size_and_align_of_dst(
116116
//
117117
// `(size + (align-1)) & -align`
118118

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

122122
(size, align)

0 commit comments

Comments
 (0)