Skip to content

Commit cec0cf5

Browse files
committed
Use Builder instead of CodegenCx for OperandRef and LocalRef
1 parent 86104b4 commit cec0cf5

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
let backend_type = bx.cx().immediate_backend_type(arg.layout);

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 {
@@ -81,10 +81,10 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
8181
layout::Abi::Scalar(ref x) => x,
8282
_ => bug!("from_const: invalid ByVal layout: {:#?}", layout)
8383
};
84-
let llval = bx.cx().scalar_to_backend(
84+
let llval = bx.scalar_to_backend(
8585
x,
8686
scalar,
87-
bx.cx().immediate_backend_type(layout),
87+
bx.immediate_backend_type(layout),
8888
);
8989
OperandValue::Immediate(llval)
9090
},
@@ -93,16 +93,16 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
9393
layout::Abi::ScalarPair(ref a, _) => a,
9494
_ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout)
9595
};
96-
let a_llval = bx.cx().scalar_to_backend(
96+
let a_llval = bx.scalar_to_backend(
9797
a,
9898
a_scalar,
99-
bx.cx().scalar_pair_element_backend_type(layout, 0, true),
99+
bx.scalar_pair_element_backend_type(layout, 0, true),
100100
);
101-
let b_llval = bx.cx().const_usize(b);
101+
let b_llval = bx.const_usize(b);
102102
OperandValue::Pair(a_llval, b_llval)
103103
},
104104
ConstValue::ByRef(ptr, alloc) => {
105-
return Ok(bx.load_operand(bx.cx().from_const_alloc(layout, alloc, ptr.offset)));
105+
return Ok(bx.load_operand(bx.from_const_alloc(layout, alloc, ptr.offset)));
106106
},
107107
};
108108

@@ -121,7 +121,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
121121
}
122122
}
123123

124-
pub fn deref<Cx: CodegenMethods<'tcx, Value = V>>(
124+
pub fn deref<Cx: LayoutTypeMethods<'tcx>>(
125125
self,
126126
cx: &Cx
127127
) -> PlaceRef<'tcx, V> {
@@ -196,7 +196,7 @@ impl<'a, 'tcx: 'a, V: CodegenObject> OperandRef<'tcx, V> {
196196
let mut val = match (self.val, &self.layout.abi) {
197197
// If the field is ZST, it has no data.
198198
_ if field.is_zst() => {
199-
return OperandRef::new_zst(bx.cx(), field);
199+
return OperandRef::new_zst(bx, field);
200200
}
201201

202202
// Newtype of a scalar, scalar pair or vector.
@@ -406,7 +406,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
406406
// checks in `codegen_consume` and `extract_field`.
407407
let elem = o.layout.field(bx.cx(), 0);
408408
if elem.is_zst() {
409-
return Some(OperandRef::new_zst(bx.cx(), elem));
409+
return Some(OperandRef::new_zst(bx, elem));
410410
}
411411
}
412412
_ => {}
@@ -429,7 +429,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
429429

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

435435
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
@@ -521,8 +521,11 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
521521
// According to `rvalue_creates_operand`, only ZST
522522
// aggregate rvalues are allowed to be operands.
523523
let ty = rvalue.ty(self.mir, self.cx.tcx());
524-
(bx, OperandRef::new_zst(self.cx,
525-
self.cx.layout_of(self.monomorphize(&ty))))
524+
let operand = OperandRef::new_zst(
525+
&mut bx,
526+
self.cx.layout_of(self.monomorphize(&ty)),
527+
);
528+
(bx, operand)
526529
}
527530
}
528531
}

0 commit comments

Comments
 (0)