Skip to content

Commit 83e80a7

Browse files
committed
Use Builder instead of CodegenCx for OperandRef and LocalRef
1 parent a0c2ca1 commit 83e80a7

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

src/librustc_codegen_llvm/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
616616
assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
617617

618618
if place.layout.is_zst() {
619-
return OperandRef::new_zst(self.cx(), place.layout);
619+
return OperandRef::new_zst(self, place.layout);
620620
}
621621

622622
fn scalar_load_metadata<'a, 'll, 'tcx>(

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ enum LocalRef<'tcx, V> {
178178
Operand(Option<OperandRef<'tcx, V>>),
179179
}
180180

181-
impl<'tcx, V: CodegenObject> LocalRef<'tcx, V> {
182-
fn new_operand<Cx: CodegenMethods<'tcx, Value = V>>(
183-
cx: &Cx,
181+
impl<'a, 'tcx: 'a, V: CodegenObject> LocalRef<'tcx, V> {
182+
fn new_operand<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
183+
bx: &mut Bx,
184184
layout: TyLayout<'tcx>,
185185
) -> LocalRef<'tcx, V> {
186186
if layout.is_zst() {
187187
// Zero-size temporaries aren't always initialized, which
188188
// doesn't matter because they don't contain data, but
189189
// we need something in the operand.
190-
LocalRef::Operand(Some(OperandRef::new_zst(cx, layout)))
190+
LocalRef::Operand(Some(OperandRef::new_zst(bx, layout)))
191191
} else {
192192
LocalRef::Operand(None)
193193
}
@@ -275,7 +275,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
275275

276276
if !memory_locals.contains(local) && !dbg {
277277
debug!("alloc: {:?} ({}) -> operand", local, name);
278-
return LocalRef::new_operand(bx.cx(), layout);
278+
return LocalRef::new_operand(&mut bx, layout);
279279
}
280280

281281
debug!("alloc: {:?} ({}) -> place", local, name);
@@ -320,7 +320,7 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
320320
// alloca in advance. Instead we wait until we see the
321321
// definition and update the operand there.
322322
debug!("alloc: {:?} -> operand", local);
323-
LocalRef::new_operand(bx.cx(), layout)
323+
LocalRef::new_operand(&mut bx, layout)
324324
}
325325
}
326326
};
@@ -529,7 +529,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
529529
let local = |op| LocalRef::Operand(Some(op));
530530
match arg.mode {
531531
PassMode::Ignore(IgnoreMode::Zst) => {
532-
return local(OperandRef::new_zst(bx.cx(), arg.layout));
532+
return local(OperandRef::new_zst(bx, arg.layout));
533533
}
534534
PassMode::Ignore(IgnoreMode::CVarArgs) => {}
535535
PassMode::Direct(_) => {

src/librustc_codegen_ssa/mir/operand.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ impl<V: CodegenObject> fmt::Debug for OperandRef<'tcx, V> {
5454
}
5555

5656
impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
57-
pub fn new_zst<Cx: CodegenMethods<'tcx, Value = V>>(
58-
cx: &Cx,
57+
pub fn new_zst<Bx: BuilderMethods<'a, 'tcx, Value = V>>(
58+
bx: &mut Bx,
5959
layout: TyLayout<'tcx>
6060
) -> OperandRef<'tcx, V> {
6161
assert!(layout.is_zst());
6262
OperandRef {
63-
val: OperandValue::Immediate(cx.const_undef(cx.immediate_backend_type(layout))),
63+
val: OperandValue::Immediate(bx.const_undef(bx.immediate_backend_type(layout))),
6464
layout
6565
}
6666
}
@@ -69,10 +69,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
6969
bx: &mut Bx,
7070
val: ty::Const<'tcx>
7171
) -> Result<Self, ErrorHandled> {
72-
let layout = bx.cx().layout_of(val.ty);
72+
let layout = bx.layout_of(val.ty);
7373

7474
if layout.is_zst() {
75-
return Ok(OperandRef::new_zst(bx.cx(), layout));
75+
return Ok(OperandRef::new_zst(bx, layout));
7676
}
7777

7878
let val = match val.val {
@@ -84,10 +84,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
8484
layout::Abi::Scalar(ref x) => x,
8585
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
8686
};
87-
let llval = bx.cx().scalar_to_backend(
87+
let llval = bx.scalar_to_backend(
8888
x,
8989
scalar,
90-
bx.cx().immediate_backend_type(layout),
90+
bx.immediate_backend_type(layout),
9191
);
9292
OperandValue::Immediate(llval)
9393
},
@@ -96,16 +96,16 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
9696
layout::Abi::ScalarPair(ref a, _) => a,
9797
_ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout)
9898
};
99-
let a_llval = bx.cx().scalar_to_backend(
99+
let a_llval = bx.scalar_to_backend(
100100
a,
101101
a_scalar,
102-
bx.cx().scalar_pair_element_backend_type(layout, 0, true),
102+
bx.scalar_pair_element_backend_type(layout, 0, true),
103103
);
104-
let b_llval = bx.cx().const_usize(b);
104+
let b_llval = bx.const_usize(b);
105105
OperandValue::Pair(a_llval, b_llval)
106106
},
107107
ConstValue::ByRef(ptr, alloc) => {
108-
return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, ptr.offset)));
108+
return Ok(bx.load_operand(bx.from_const_alloc(layout, alloc, ptr.offset)));
109109
},
110110
};
111111

@@ -124,7 +124,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
124124
}
125125
}
126126

127-
pub fn deref<Cx: CodegenMethods<'tcx, Value = V>>(
127+
pub fn deref<Cx: LayoutTypeMethods<'tcx>>(
128128
self,
129129
cx: &Cx
130130
) -> PlaceRef<'tcx, V> {
@@ -199,7 +199,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
199199
let mut val = match (self.val, &self.layout.abi) {
200200
// If the field is ZST, it has no data.
201201
_ if field.is_zst() => {
202-
return OperandRef::new_zst(bx.cx(), field);
202+
return OperandRef::new_zst(bx, field);
203203
}
204204

205205
// Newtype of a scalar, scalar pair or vector.
@@ -409,7 +409,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
409409
// checks in `codegen_consume` and `extract_field`.
410410
let elem = o.layout.field(bx.cx(), 0);
411411
if elem.is_zst() {
412-
return Some(OperandRef::new_zst(bx.cx(), elem));
412+
return Some(OperandRef::new_zst(bx, elem));
413413
}
414414
}
415415
_ => {}
@@ -432,7 +432,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
432432

433433
// ZSTs don't require any actual memory access.
434434
if layout.is_zst() {
435-
return OperandRef::new_zst(bx.cx(), layout);
435+
return OperandRef::new_zst(bx, layout);
436436
}
437437

438438
if let Some(o) = self.maybe_codegen_consume_direct(bx, place) {

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,11 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
523523
// According to `rvalue_creates_operand`, only ZST
524524
// aggregate rvalues are allowed to be operands.
525525
let ty = rvalue.ty(self.mir, self.cx.tcx());
526-
(bx, OperandRef::new_zst(self.cx,
527-
self.cx.layout_of(self.monomorphize(&ty))))
526+
let operand = OperandRef::new_zst(
527+
&mut bx,
528+
self.cx.layout_of(self.monomorphize(&ty)),
529+
);
530+
(bx, operand)
528531
}
529532
}
530533
}

0 commit comments

Comments
 (0)