Skip to content

Commit a81217c

Browse files
committed
Make abi::Abi Copy and remove a *lot* of refs
fix fix Remove more refs and clones fix more fix
1 parent 9ad50a4 commit a81217c

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

src/abi/pass_mode.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
9292
fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> {
9393
match self.mode {
9494
PassMode::Ignore => smallvec![],
95-
PassMode::Direct(attrs) => match &self.layout.abi {
95+
PassMode::Direct(attrs) => match self.layout.abi {
9696
Abi::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param(
97-
AbiParam::new(scalar_to_clif_type(tcx, scalar.clone())),
97+
AbiParam::new(scalar_to_clif_type(tcx, scalar)),
9898
attrs
9999
)],
100100
Abi::Vector { .. } => {
@@ -103,10 +103,10 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
103103
}
104104
_ => unreachable!("{:?}", self.layout.abi),
105105
},
106-
PassMode::Pair(attrs_a, attrs_b) => match &self.layout.abi {
106+
PassMode::Pair(attrs_a, attrs_b) => match self.layout.abi {
107107
Abi::ScalarPair(a, b) => {
108-
let a = scalar_to_clif_type(tcx, a.clone());
109-
let b = scalar_to_clif_type(tcx, b.clone());
108+
let a = scalar_to_clif_type(tcx, a);
109+
let b = scalar_to_clif_type(tcx, b);
110110
smallvec![
111111
apply_arg_attrs_to_abi_param(AbiParam::new(a), attrs_a),
112112
apply_arg_attrs_to_abi_param(AbiParam::new(b), attrs_b),
@@ -139,20 +139,20 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
139139
fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option<AbiParam>, Vec<AbiParam>) {
140140
match self.mode {
141141
PassMode::Ignore => (None, vec![]),
142-
PassMode::Direct(_) => match &self.layout.abi {
142+
PassMode::Direct(_) => match self.layout.abi {
143143
Abi::Scalar(scalar) => {
144-
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar.clone()))])
144+
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))])
145145
}
146146
Abi::Vector { .. } => {
147147
let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout).unwrap();
148148
(None, vec![AbiParam::new(vector_ty)])
149149
}
150150
_ => unreachable!("{:?}", self.layout.abi),
151151
},
152-
PassMode::Pair(_, _) => match &self.layout.abi {
152+
PassMode::Pair(_, _) => match self.layout.abi {
153153
Abi::ScalarPair(a, b) => {
154-
let a = scalar_to_clif_type(tcx, a.clone());
155-
let b = scalar_to_clif_type(tcx, b.clone());
154+
let a = scalar_to_clif_type(tcx, a);
155+
let b = scalar_to_clif_type(tcx, b);
156156
(None, vec![AbiParam::new(a), AbiParam::new(b)])
157157
}
158158
_ => unreachable!("{:?}", self.layout.abi),

src/intrinsics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ macro validate_simd_type($fx:ident, $intrinsic:ident, $span:ident, $ty:expr) {
143143
}
144144

145145
pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option<Type> {
146-
let (element, count) = match &layout.abi {
147-
Abi::Vector { element, count } => (element.clone(), *count),
146+
let (element, count) = match layout.abi {
147+
Abi::Vector { element, count } => (element, count),
148148
_ => unreachable!(),
149149
};
150150

src/value_and_place.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ fn codegen_field<'tcx>(
4949
}
5050
}
5151

52-
fn scalar_pair_calculate_b_offset(
53-
tcx: TyCtxt<'_>,
54-
a_scalar: &Scalar,
55-
b_scalar: &Scalar,
56-
) -> Offset32 {
52+
fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 {
5753
let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi);
5854
Offset32::new(b_offset.bytes().try_into().unwrap())
5955
}
@@ -124,12 +120,10 @@ impl<'tcx> CValue<'tcx> {
124120
match self.0 {
125121
CValueInner::ByRef(ptr, None) => {
126122
let clif_ty = match layout.abi {
127-
Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.tcx, scalar.clone()),
128-
Abi::Vector { ref element, count } => {
129-
scalar_to_clif_type(fx.tcx, element.clone())
130-
.by(u16::try_from(count).unwrap())
131-
.unwrap()
132-
}
123+
Abi::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar),
124+
Abi::Vector { element, count } => scalar_to_clif_type(fx.tcx, element)
125+
.by(u16::try_from(count).unwrap())
126+
.unwrap(),
133127
_ => unreachable!("{:?}", layout.ty),
134128
};
135129
let mut flags = MemFlags::new();
@@ -147,13 +141,13 @@ impl<'tcx> CValue<'tcx> {
147141
let layout = self.1;
148142
match self.0 {
149143
CValueInner::ByRef(ptr, None) => {
150-
let (a_scalar, b_scalar) = match &layout.abi {
144+
let (a_scalar, b_scalar) = match layout.abi {
151145
Abi::ScalarPair(a, b) => (a, b),
152146
_ => unreachable!("load_scalar_pair({:?})", self),
153147
};
154148
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
155-
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar.clone());
156-
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar.clone());
149+
let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar);
150+
let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar);
157151
let mut flags = MemFlags::new();
158152
flags.set_notrap();
159153
let val1 = ptr.load(fx, clif_ty1, flags);
@@ -564,7 +558,7 @@ impl<'tcx> CPlace<'tcx> {
564558
to_ptr.store(fx, val, flags);
565559
return;
566560
}
567-
Abi::ScalarPair(ref a_scalar, ref b_scalar) => {
561+
Abi::ScalarPair(a_scalar, b_scalar) => {
568562
let (value, extra) = from.load_scalar_pair(fx);
569563
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
570564
to_ptr.store(fx, value, flags);

0 commit comments

Comments
 (0)