Skip to content

Commit d522e38

Browse files
committed
Add load/store helpers that take PlaceValue
1 parent b63f8b6 commit d522e38

File tree

6 files changed

+18
-11
lines changed

6 files changed

+18
-11
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
264264
llvm::LLVMSetAlignment(load, align);
265265
}
266266
if !result.layout.is_zst() {
267-
self.store(load, result.val.llval, result.val.align);
267+
self.store_to_place(load, result.val);
268268
}
269269
return Ok(());
270270
}

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
456456
PassMode::Direct(_) | PassMode::Pair(..) => {
457457
let op = self.codegen_consume(bx, mir::Place::return_place().as_ref());
458458
if let Ref(place_val) = op.val {
459-
bx.load(bx.backend_type(op.layout), place_val.llval, place_val.align)
459+
bx.load_from_place(bx.backend_type(op.layout), place_val)
460460
} else {
461461
op.immediate_or_packed_pair(bx)
462462
}

compiler/rustc_codegen_ssa/src/mir/debuginfo.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
420420
bx.set_var_name(alloca.val.llval, &(var.name.to_string() + ".dbg.spill"));
421421

422422
// Write the pointer to the variable
423-
bx.store(place.val.llval, alloca.val.llval, alloca.val.align);
423+
bx.store_to_place(place.val.llval, alloca.val);
424424

425425
// Point the debug info to `*alloca` for the current variable
426426
bx.dbg_var_addr(

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
387387
let success = bx.from_immediate(success);
388388

389389
let dest = result.project_field(bx, 0);
390-
bx.store(val, dest.val.llval, dest.val.align);
390+
bx.store_to_place(val, dest.val);
391391
let dest = result.project_field(bx, 1);
392-
bx.store(success, dest.val.llval, dest.val.align);
392+
bx.store_to_place(success, dest.val);
393393
} else {
394394
invalid_monomorphization(ty);
395395
}
@@ -511,7 +511,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
511511

512512
if !fn_abi.ret.is_ignore() {
513513
if let PassMode::Cast { .. } = &fn_abi.ret.mode {
514-
bx.store(llval, result.val.llval, result.val.align);
514+
bx.store_to_place(llval, result.val);
515515
} else {
516516
OperandRef::from_immediate_or_packed_pair(bx, llval, result.layout)
517517
.val

compiler/rustc_codegen_ssa/src/mir/place.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
343343
let ptr = self.project_field(bx, tag_field);
344344
let to =
345345
self.layout.ty.discriminant_for_variant(bx.tcx(), variant_index).unwrap().val;
346-
bx.store(
346+
bx.store_to_place(
347347
bx.cx().const_uint_big(bx.cx().backend_type(ptr.layout), to),
348-
ptr.val.llval,
349-
ptr.val.align,
348+
ptr.val,
350349
);
351350
}
352351
Variants::Multiple {

compiler/rustc_codegen_ssa/src/traits/builder.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::common::{
1212
AtomicOrdering, AtomicRmwBinOp, IntPredicate, RealPredicate, SynchronizationScope, TypeKind,
1313
};
1414
use crate::mir::operand::{OperandRef, OperandValue};
15-
use crate::mir::place::PlaceRef;
15+
use crate::mir::place::{PlaceRef, PlaceValue};
1616
use crate::MemFlags;
1717

1818
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -156,6 +156,10 @@ pub trait BuilderMethods<'a, 'tcx>:
156156
order: AtomicOrdering,
157157
size: Size,
158158
) -> Self::Value;
159+
fn load_from_place(&mut self, ty: Self::Type, place: PlaceValue<Self::Value>) -> Self::Value {
160+
debug_assert_eq!(place.llextra, None);
161+
self.load(ty, place.llval, place.align)
162+
}
159163
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
160164
-> OperandRef<'tcx, Self::Value>;
161165

@@ -171,6 +175,10 @@ pub trait BuilderMethods<'a, 'tcx>:
171175
fn nonnull_metadata(&mut self, load: Self::Value);
172176

173177
fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value;
178+
fn store_to_place(&mut self, val: Self::Value, place: PlaceValue<Self::Value>) -> Self::Value {
179+
debug_assert_eq!(place.llextra, None);
180+
self.store(val, place.llval, place.align)
181+
}
174182
fn store_with_flags(
175183
&mut self,
176184
val: Self::Value,
@@ -296,7 +304,7 @@ pub trait BuilderMethods<'a, 'tcx>:
296304
if flags.contains(MemFlags::NONTEMPORAL) {
297305
// HACK(nox): This is inefficient but there is no nontemporal memcpy.
298306
let ty = self.backend_type(dst.layout);
299-
let val = self.load(ty, src.val.llval, src.val.align);
307+
let val = self.load_from_place(ty, src.val);
300308
self.store_with_flags(val, dst.val.llval, dst.val.align, flags);
301309
} else if self.sess().opts.optimize == OptLevel::No && self.is_backend_immediate(dst.layout)
302310
{

0 commit comments

Comments
 (0)