Skip to content

Commit b6cf0a6

Browse files
committed
Remove CPlace::inner and make CPlaceInner private
This makes it easier to add and remove variants as necessary
1 parent e564790 commit b6cf0a6

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

src/abi/comments.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use std::borrow::Cow;
66
use rustc_middle::mir;
77
use rustc_target::abi::call::PassMode;
88

9-
use cranelift_codegen::entity::EntityRef;
10-
119
use crate::prelude::*;
1210

1311
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, '_>) {
@@ -91,34 +89,7 @@ pub(super) fn add_local_place_comments<'tcx>(
9189
largest_niche: _,
9290
} = layout.0.0;
9391

94-
let (kind, extra) = match *place.inner() {
95-
CPlaceInner::Var(place_local, var) => {
96-
assert_eq!(local, place_local);
97-
("ssa", Cow::Owned(format!(",var={}", var.index())))
98-
}
99-
CPlaceInner::VarPair(place_local, var1, var2) => {
100-
assert_eq!(local, place_local);
101-
("ssa", Cow::Owned(format!("var=({}, {})", var1.index(), var2.index())))
102-
}
103-
CPlaceInner::Addr(ptr, meta) => {
104-
let meta = if let Some(meta) = meta {
105-
Cow::Owned(format!("meta={}", meta))
106-
} else {
107-
Cow::Borrowed("")
108-
};
109-
match ptr.debug_base_and_offset() {
110-
(crate::pointer::PointerBase::Addr(addr), offset) => {
111-
("reuse", format!("storage={}{}{}", addr, offset, meta).into())
112-
}
113-
(crate::pointer::PointerBase::Stack(stack_slot), offset) => {
114-
("stack", format!("storage={}{}{}", stack_slot, offset, meta).into())
115-
}
116-
(crate::pointer::PointerBase::Dangling(align), offset) => {
117-
("zst", format!("align={},offset={}", align.bytes(), offset).into())
118-
}
119-
}
120-
}
121-
};
92+
let (kind, extra) = place.debug_comment();
12293

12394
fx.add_global_comment(format!(
12495
"{:<5} {:5} {:30} {:4}b {}, {}{}{}",

src/abi/returning.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ pub(super) fn codegen_with_call_return_arg<'tcx>(
6363
let (ret_temp_place, return_ptr) = match ret_arg_abi.mode {
6464
PassMode::Ignore => (None, None),
6565
PassMode::Indirect { attrs: _, extra_attrs: None, on_stack: _ } => {
66-
if matches!(ret_place.inner(), CPlaceInner::Addr(_, None)) {
66+
if let Some(ret_ptr) = ret_place.try_to_ptr() {
6767
// This is an optimization to prevent unnecessary copies of the return value when
6868
// the return place is already a memory place as opposed to a register.
6969
// This match arm can be safely removed.
70-
(None, Some(ret_place.to_ptr().get_addr(fx)))
70+
(None, Some(ret_ptr.get_addr(fx)))
7171
} else {
7272
let place = CPlace::new_stack_slot(fx, ret_arg_abi.layout);
7373
(Some(place), Some(place.to_ptr().get_addr(fx)))

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ mod prelude {
110110
pub(crate) use crate::common::*;
111111
pub(crate) use crate::debuginfo::{DebugContext, UnwindContext};
112112
pub(crate) use crate::pointer::Pointer;
113-
pub(crate) use crate::value_and_place::{CPlace, CPlaceInner, CValue};
113+
pub(crate) use crate::value_and_place::{CPlace, CValue};
114114
}
115115

116116
struct PrintOnPanic<F: Fn() -> String>(F);

src/value_and_place.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::prelude::*;
44

5+
use cranelift_codegen::entity::EntityRef;
56
use cranelift_codegen::ir::immediates::Offset32;
67

78
fn codegen_field<'tcx>(
@@ -325,7 +326,7 @@ pub(crate) struct CPlace<'tcx> {
325326
}
326327

327328
#[derive(Debug, Copy, Clone)]
328-
pub(crate) enum CPlaceInner {
329+
enum CPlaceInner {
329330
Var(Local, Variable),
330331
VarPair(Local, Variable, Variable),
331332
Addr(Pointer, Option<Value>),
@@ -336,10 +337,6 @@ impl<'tcx> CPlace<'tcx> {
336337
self.layout
337338
}
338339

339-
pub(crate) fn inner(&self) -> &CPlaceInner {
340-
&self.inner
341-
}
342-
343340
pub(crate) fn new_stack_slot(
344341
fx: &mut FunctionCx<'_, '_, 'tcx>,
345342
layout: TyAndLayout<'tcx>,
@@ -431,6 +428,30 @@ impl<'tcx> CPlace<'tcx> {
431428
}
432429
}
433430

431+
pub(crate) fn debug_comment(self) -> (&'static str, String) {
432+
match self.inner {
433+
CPlaceInner::Var(_local, var) => ("ssa", format!("var={}", var.index())),
434+
CPlaceInner::VarPair(_local, var1, var2) => {
435+
("ssa", format!("var=({}, {})", var1.index(), var2.index()))
436+
}
437+
CPlaceInner::Addr(ptr, meta) => {
438+
let meta =
439+
if let Some(meta) = meta { format!(",meta={}", meta) } else { String::new() };
440+
match ptr.debug_base_and_offset() {
441+
(crate::pointer::PointerBase::Addr(addr), offset) => {
442+
("reuse", format!("storage={}{}{}", addr, offset, meta))
443+
}
444+
(crate::pointer::PointerBase::Stack(stack_slot), offset) => {
445+
("stack", format!("storage={}{}{}", stack_slot, offset, meta))
446+
}
447+
(crate::pointer::PointerBase::Dangling(align), offset) => {
448+
("zst", format!("align={},offset={}", align.bytes(), offset))
449+
}
450+
}
451+
}
452+
}
453+
}
454+
434455
#[track_caller]
435456
pub(crate) fn to_ptr(self) -> Pointer {
436457
match self.to_ptr_maybe_unsized() {
@@ -449,6 +470,14 @@ impl<'tcx> CPlace<'tcx> {
449470
}
450471
}
451472

473+
pub(crate) fn try_to_ptr(self) -> Option<Pointer> {
474+
match self.inner {
475+
CPlaceInner::Var(_, _) | CPlaceInner::VarPair(_, _, _) => None,
476+
CPlaceInner::Addr(ptr, None) => Some(ptr),
477+
CPlaceInner::Addr(_, Some(_)) => bug!("Expected sized cplace, found {:?}", self),
478+
}
479+
}
480+
452481
pub(crate) fn write_cvalue(self, fx: &mut FunctionCx<'_, '_, 'tcx>, from: CValue<'tcx>) {
453482
assert_assignable(fx, from.layout().ty, self.layout().ty, 16);
454483

@@ -527,7 +556,7 @@ impl<'tcx> CPlace<'tcx> {
527556
format!(
528557
"{}: {:?}: {:?} <- {:?}: {:?}",
529558
method,
530-
self.inner(),
559+
self.inner,
531560
self.layout().ty,
532561
from.0,
533562
from.layout().ty

0 commit comments

Comments
 (0)