Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename mir::Rvalue to Op. #70928

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
fn visit_assign(
&mut self,
place: &mir::Place<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
rvalue: &mir::Op<'tcx>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the next thing to do here would be to rename rvalue variables.

location: Location,
) {
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Including debug messages, heh.

Expand Down
70 changes: 35 additions & 35 deletions src/librustc_codegen_ssa/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self,
mut bx: Bx,
dest: PlaceRef<'tcx, Bx::Value>,
rvalue: &mir::Rvalue<'tcx>,
rvalue: &mir::Op<'tcx>,
) -> Bx {
debug!("codegen_rvalue(dest.llval={:?}, rvalue={:?})", dest.llval, rvalue);

match *rvalue {
mir::Rvalue::Use(ref operand) => {
mir::Op::Use(ref operand) => {
let cg_operand = self.codegen_operand(&mut bx, operand);
// FIXME: consider not copying constants through stack. (Fixable by codegen'ing
// constants into `OperandValue::Ref`; why don’t we do that yet if we don’t?)
cg_operand.val.store(&mut bx, dest);
bx
}

mir::Rvalue::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref source, _) => {
mir::Op::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref source, _) => {
// The destination necessarily contains a fat pointer, so if
// it's a scalar pair, it's a fat pointer or newtype thereof.
if bx.cx().is_backend_scalar_pair(dest.layout) {
Expand Down Expand Up @@ -77,7 +77,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx
}

mir::Rvalue::Repeat(ref elem, count) => {
mir::Op::Repeat(ref elem, count) => {
let cg_elem = self.codegen_operand(&mut bx, elem);

// Do not generate the loop for zero-sized elements or empty arrays.
Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.write_operand_repeatedly(cg_elem, count, dest)
}

mir::Rvalue::Aggregate(ref kind, ref operands) => {
mir::Op::Aggregate(ref kind, ref operands) => {
let (dest, active_field_index) = match **kind {
mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => {
dest.codegen_set_discr(&mut bx, variant_index);
Expand Down Expand Up @@ -148,28 +148,28 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self,
mut bx: Bx,
indirect_dest: PlaceRef<'tcx, Bx::Value>,
rvalue: &mir::Rvalue<'tcx>,
rvalue: &mir::Op<'tcx>,
) -> Bx {
debug!(
"codegen_rvalue_unsized(indirect_dest.llval={:?}, rvalue={:?})",
indirect_dest.llval, rvalue
);

match *rvalue {
mir::Rvalue::Use(ref operand) => {
mir::Op::Use(ref operand) => {
let cg_operand = self.codegen_operand(&mut bx, operand);
cg_operand.val.store_unsized(&mut bx, indirect_dest);
bx
}

_ => bug!("unsized assignment other than `Rvalue::Use`"),
_ => bug!("unsized assignment other than `Op::Use`"),
}
}

pub fn codegen_rvalue_operand(
&mut self,
mut bx: Bx,
rvalue: &mir::Rvalue<'tcx>,
rvalue: &mir::Op<'tcx>,
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
assert!(
self.rvalue_creates_operand(rvalue, DUMMY_SP),
Expand All @@ -178,7 +178,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
);

match *rvalue {
mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => {
mir::Op::Cast(ref kind, ref source, mir_cast_ty) => {
let operand = self.codegen_operand(&mut bx, source);
debug!("cast operand is {:?}", operand);
let cast = bx.cx().layout_of(self.monomorphize(&mir_cast_ty));
Expand Down Expand Up @@ -382,7 +382,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, OperandRef { val, layout: cast })
}

mir::Rvalue::Ref(_, bk, place) => {
mir::Op::Ref(_, bk, place) => {
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ref(
tcx.lifetimes.re_erased,
Expand All @@ -392,14 +392,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
self.codegen_place_to_pointer(bx, place, mk_ref)
}

mir::Rvalue::AddressOf(mutability, place) => {
mir::Op::AddressOf(mutability, place) => {
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
};
self.codegen_place_to_pointer(bx, place, mk_ptr)
}

mir::Rvalue::Len(place) => {
mir::Op::Len(place) => {
let size = self.evaluate_array_len(&mut bx, place);
let operand = OperandRef {
val: OperandValue::Immediate(size),
Expand All @@ -408,7 +408,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, operand)
}

mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
mir::Op::BinaryOp(op, ref lhs, ref rhs) => {
let lhs = self.codegen_operand(&mut bx, lhs);
let rhs = self.codegen_operand(&mut bx, rhs);
let llresult = match (lhs.val, rhs.val) {
Expand Down Expand Up @@ -437,7 +437,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
};
(bx, operand)
}
mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
mir::Op::CheckedBinaryOp(op, ref lhs, ref rhs) => {
let lhs = self.codegen_operand(&mut bx, lhs);
let rhs = self.codegen_operand(&mut bx, rhs);
let result = self.codegen_scalar_checked_binop(
Expand All @@ -454,7 +454,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, operand)
}

mir::Rvalue::UnaryOp(op, ref operand) => {
mir::Op::UnaryOp(op, ref operand) => {
let operand = self.codegen_operand(&mut bx, operand);
let lloperand = operand.immediate();
let is_float = operand.layout.ty.is_floating_point();
Expand All @@ -471,7 +471,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
(bx, OperandRef { val: OperandValue::Immediate(llval), layout: operand.layout })
}

mir::Rvalue::Discriminant(ref place) => {
mir::Op::Discriminant(ref place) => {
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
let discr = self
.codegen_place(&mut bx, place.as_ref())
Expand All @@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
)
}

mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => {
mir::Op::NullaryOp(mir::NullOp::SizeOf, ty) => {
assert!(bx.cx().type_is_sized(ty));
let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes());
let tcx = self.cx.tcx();
Expand All @@ -498,7 +498,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
)
}

mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => {
mir::Op::NullaryOp(mir::NullOp::Box, content_ty) => {
let content_ty = self.monomorphize(&content_ty);
let content_layout = bx.cx().layout_of(content_ty);
let llsize = bx.cx().const_usize(content_layout.size.bytes());
Expand All @@ -521,11 +521,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout };
(bx, operand)
}
mir::Rvalue::Use(ref operand) => {
mir::Op::Use(ref operand) => {
let operand = self.codegen_operand(&mut bx, operand);
(bx, operand)
}
mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => {
mir::Op::Repeat(..) | mir::Op::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(*self.mir, self.cx.tcx());
Expand All @@ -552,7 +552,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
cg_value.len(bx.cx())
}

/// Codegen an `Rvalue::AddressOf` or `Rvalue::Ref`
/// Codegen an `Op::AddressOf` or `Op::Ref`
fn codegen_place_to_pointer(
&mut self,
mut bx: Bx,
Expand Down Expand Up @@ -733,21 +733,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
}

impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool {
pub fn rvalue_creates_operand(&self, rvalue: &mir::Op<'tcx>, span: Span) -> bool {
match *rvalue {
mir::Rvalue::Ref(..) |
mir::Rvalue::AddressOf(..) |
mir::Rvalue::Len(..) |
mir::Rvalue::Cast(..) | // (*)
mir::Rvalue::BinaryOp(..) |
mir::Rvalue::CheckedBinaryOp(..) |
mir::Rvalue::UnaryOp(..) |
mir::Rvalue::Discriminant(..) |
mir::Rvalue::NullaryOp(..) |
mir::Rvalue::Use(..) => // (*)
mir::Op::Ref(..) |
mir::Op::AddressOf(..) |
mir::Op::Len(..) |
mir::Op::Cast(..) | // (*)
mir::Op::BinaryOp(..) |
mir::Op::CheckedBinaryOp(..) |
mir::Op::UnaryOp(..) |
mir::Op::Discriminant(..) |
mir::Op::NullaryOp(..) |
mir::Op::Use(..) => // (*)
true,
mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => {
mir::Op::Repeat(..) |
mir::Op::Aggregate(..) => {
let ty = rvalue.ty(*self.mir, self.cx.tcx());
let ty = self.monomorphize(&ty);
self.cx.spanned_layout_of(ty, span).is_zst()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/traits/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub trait BuilderMethods<'a, 'tcx>:
fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>)
-> OperandRef<'tcx, Self::Value>;

/// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset.
/// Called for Op::Repeat when the elem is neither a ZST nor optimizable using memset.
fn write_operand_repeatedly(
self,
elem: OperandRef<'tcx, Self::Value>,
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,8 +1561,8 @@ impl Statement<'_> {

#[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
pub enum StatementKind<'tcx> {
/// Write the RHS Rvalue to the LHS Place.
Assign(Box<(Place<'tcx>, Rvalue<'tcx>)>),
/// Write the RHS Op to the LHS Place.
Assign(Box<(Place<'tcx>, Op<'tcx>)>),

/// This represents all the reading that a pattern match may do
/// (e.g., inspecting constants and discriminant values), and the
Expand Down Expand Up @@ -2042,7 +2042,7 @@ impl<'tcx> Operand<'tcx> {
/// Rvalues
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation should also be adjusted


#[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)]
pub enum Rvalue<'tcx> {
pub enum Op<'tcx> {
/// x (either a move or copy, depending on type of x)
Use(Operand<'tcx>),

Expand Down Expand Up @@ -2169,9 +2169,9 @@ pub enum UnOp {
Neg,
}

impl<'tcx> Debug for Rvalue<'tcx> {
impl<'tcx> Debug for Op<'tcx> {
fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result {
use self::Rvalue::*;
use self::Op::*;

match *self {
Use(ref place) => write!(fmt, "{:?}", place),
Expand Down
32 changes: 16 additions & 16 deletions src/librustc_middle/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,41 +142,41 @@ pub enum RvalueInitializationState {
Deep,
}

impl<'tcx> Rvalue<'tcx> {
impl<'tcx> Op<'tcx> {
pub fn ty<D>(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx>
where
D: HasLocalDecls<'tcx>,
{
match *self {
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
Rvalue::Repeat(ref operand, count) => {
Op::Use(ref operand) => operand.ty(local_decls, tcx),
Op::Repeat(ref operand, count) => {
tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count))
}
Rvalue::Ref(reg, bk, ref place) => {
Op::Ref(reg, bk, ref place) => {
let place_ty = place.ty(local_decls, tcx).ty;
tcx.mk_ref(reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() })
}
Rvalue::AddressOf(mutability, ref place) => {
Op::AddressOf(mutability, ref place) => {
let place_ty = place.ty(local_decls, tcx).ty;
tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability })
}
Rvalue::Len(..) => tcx.types.usize,
Rvalue::Cast(.., ty) => ty,
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
Op::Len(..) => tcx.types.usize,
Op::Cast(.., ty) => ty,
Op::BinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx);
op.ty(tcx, lhs_ty, rhs_ty)
}
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
Op::CheckedBinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx);
let ty = op.ty(tcx, lhs_ty, rhs_ty);
tcx.intern_tup(&[ty, tcx.types.bool])
}
Rvalue::UnaryOp(UnOp::Not, ref operand) | Rvalue::UnaryOp(UnOp::Neg, ref operand) => {
Op::UnaryOp(UnOp::Not, ref operand) | Op::UnaryOp(UnOp::Neg, ref operand) => {
operand.ty(local_decls, tcx)
}
Rvalue::Discriminant(ref place) => {
Op::Discriminant(ref place) => {
let ty = place.ty(local_decls, tcx).ty;
match ty.kind {
ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx),
Expand All @@ -187,9 +187,9 @@ impl<'tcx> Rvalue<'tcx> {
}
}
}
Rvalue::NullaryOp(NullOp::Box, t) => tcx.mk_box(t),
Rvalue::NullaryOp(NullOp::SizeOf, _) => tcx.types.usize,
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
Op::NullaryOp(NullOp::Box, t) => tcx.mk_box(t),
Op::NullaryOp(NullOp::SizeOf, _) => tcx.types.usize,
Op::Aggregate(ref ak, ref ops) => match **ak {
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))),
AggregateKind::Adt(def, _, substs, _, _) => tcx.type_of(def.did).subst(tcx, substs),
Expand All @@ -203,10 +203,10 @@ impl<'tcx> Rvalue<'tcx> {

#[inline]
/// Returns `true` if this rvalue is deeply initialized (most rvalues) or
/// whether its only shallowly initialized (`Rvalue::Box`).
/// whether its only shallowly initialized (`Op::Box`).
pub fn initialization_state(&self) -> RvalueInitializationState {
match *self {
Rvalue::NullaryOp(NullOp::Box, _) => RvalueInitializationState::Shallow,
Op::NullaryOp(NullOp::Box, _) => RvalueInitializationState::Shallow,
_ => RvalueInitializationState::Deep,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_middle/mir/type_foldable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<PlaceElem<'tcx>> {
}
}

impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for Op<'tcx> {
fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
use crate::mir::Rvalue::*;
use crate::mir::Op::*;
match *self {
Use(ref op) => Use(op.fold_with(folder)),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
Expand Down Expand Up @@ -208,7 +208,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
}

fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
use crate::mir::Rvalue::*;
use crate::mir::Op::*;
match *self {
Use(ref op) => op.visit_with(visitor),
Repeat(ref op, _) => op.visit_with(visitor),
Expand Down
Loading