Skip to content

Commit e3c1547

Browse files
cg_clif: rustc_abi::Abi => BackendRepr
1 parent 988f49d commit e3c1547

File tree

8 files changed

+62
-53
lines changed

8 files changed

+62
-53
lines changed

src/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn make_local_place<'tcx>(
193193
);
194194
}
195195
let place = if is_ssa {
196-
if let rustc_target::abi::Abi::ScalarPair(_, _) = layout.abi {
196+
if let BackendRepr::ScalarPair(_, _) = layout.backend_repr {
197197
CPlace::new_var_pair(fx, local, layout)
198198
} else {
199199
CPlace::new_var(fx, local, layout)

src/abi/pass_mode.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,27 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
7878
fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> {
7979
match self.mode {
8080
PassMode::Ignore => smallvec![],
81-
PassMode::Direct(attrs) => match self.layout.abi {
82-
Abi::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param(
81+
PassMode::Direct(attrs) => match self.layout.backend_repr {
82+
BackendRepr::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param(
8383
AbiParam::new(scalar_to_clif_type(tcx, scalar)),
8484
attrs
8585
)],
86-
Abi::Vector { .. } => {
86+
BackendRepr::Vector { .. } => {
8787
let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout);
8888
smallvec![AbiParam::new(vector_ty)]
8989
}
90-
_ => unreachable!("{:?}", self.layout.abi),
90+
_ => unreachable!("{:?}", self.layout.backend_repr),
9191
},
92-
PassMode::Pair(attrs_a, attrs_b) => match self.layout.abi {
93-
Abi::ScalarPair(a, b) => {
92+
PassMode::Pair(attrs_a, attrs_b) => match self.layout.backend_repr {
93+
BackendRepr::ScalarPair(a, b) => {
9494
let a = scalar_to_clif_type(tcx, a);
9595
let b = scalar_to_clif_type(tcx, b);
9696
smallvec![
9797
apply_arg_attrs_to_abi_param(AbiParam::new(a), attrs_a),
9898
apply_arg_attrs_to_abi_param(AbiParam::new(b), attrs_b),
9999
]
100100
}
101-
_ => unreachable!("{:?}", self.layout.abi),
101+
_ => unreachable!("{:?}", self.layout.backend_repr),
102102
},
103103
PassMode::Cast { ref cast, pad_i32 } => {
104104
assert!(!pad_i32, "padding support not yet implemented");
@@ -130,23 +130,23 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
130130
fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option<AbiParam>, Vec<AbiParam>) {
131131
match self.mode {
132132
PassMode::Ignore => (None, vec![]),
133-
PassMode::Direct(_) => match self.layout.abi {
134-
Abi::Scalar(scalar) => {
133+
PassMode::Direct(_) => match self.layout.backend_repr {
134+
BackendRepr::Scalar(scalar) => {
135135
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))])
136136
}
137-
Abi::Vector { .. } => {
137+
BackendRepr::Vector { .. } => {
138138
let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout);
139139
(None, vec![AbiParam::new(vector_ty)])
140140
}
141-
_ => unreachable!("{:?}", self.layout.abi),
141+
_ => unreachable!("{:?}", self.layout.backend_repr),
142142
},
143-
PassMode::Pair(_, _) => match self.layout.abi {
144-
Abi::ScalarPair(a, b) => {
143+
PassMode::Pair(_, _) => match self.layout.backend_repr {
144+
BackendRepr::ScalarPair(a, b) => {
145145
let a = scalar_to_clif_type(tcx, a);
146146
let b = scalar_to_clif_type(tcx, b);
147147
(None, vec![AbiParam::new(a), AbiParam::new(b)])
148148
}
149-
_ => unreachable!("{:?}", self.layout.abi),
149+
_ => unreachable!("{:?}", self.layout.backend_repr),
150150
},
151151
PassMode::Cast { ref cast, .. } => {
152152
(None, cast_target_to_abi_params(cast).into_iter().collect())

src/base.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
290290
let arg_uninhabited = fx
291291
.mir
292292
.args_iter()
293-
.any(|arg| fx.layout_of(fx.monomorphize(fx.mir.local_decls[arg].ty)).abi.is_uninhabited());
293+
.any(|arg| fx.layout_of(fx.monomorphize(fx.mir.local_decls[arg].ty)).is_uninhabited());
294294
if arg_uninhabited {
295295
fx.bcx.append_block_params_for_function_params(fx.block_map[START_BLOCK]);
296296
fx.bcx.switch_to_block(fx.block_map[START_BLOCK]);
@@ -644,9 +644,9 @@ fn codegen_stmt<'tcx>(
644644
_ => unreachable!("un op Neg for {:?}", layout.ty),
645645
}
646646
}
647-
UnOp::PtrMetadata => match layout.abi {
648-
Abi::Scalar(_) => CValue::zst(dest_layout),
649-
Abi::ScalarPair(_, _) => {
647+
UnOp::PtrMetadata => match layout.backend_repr {
648+
BackendRepr::Scalar(_) => CValue::zst(dest_layout),
649+
BackendRepr::ScalarPair(_, _) => {
650650
CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout)
651651
}
652652
_ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"),

src/discriminant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
1414
variant_index: VariantIdx,
1515
) {
1616
let layout = place.layout();
17-
if layout.for_variant(fx, variant_index).abi.is_uninhabited() {
17+
if layout.for_variant(fx, variant_index).is_uninhabited() {
1818
return;
1919
}
2020
match layout.variants {
@@ -80,7 +80,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
8080
) {
8181
let layout = value.layout();
8282

83-
if layout.abi.is_uninhabited() {
83+
if layout.is_uninhabited() {
8484
return;
8585
}
8686

src/intrinsics/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ fn report_atomic_type_validation_error<'tcx>(
5151
}
5252

5353
pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type {
54-
let (element, count) = match layout.abi {
55-
Abi::Vector { element, count } => (element, count),
54+
let (element, count) = match layout.backend_repr {
55+
BackendRepr::Vector { element, count } => (element, count),
5656
_ => unreachable!(),
5757
};
5858

@@ -505,7 +505,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
505505
let layout = fx.layout_of(generic_args.type_at(0));
506506
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
507507
// branch
508-
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
508+
let meta = if let BackendRepr::ScalarPair(_, _) = ptr.layout().backend_repr {
509509
Some(ptr.load_scalar_pair(fx).1)
510510
} else {
511511
None
@@ -519,7 +519,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
519519
let layout = fx.layout_of(generic_args.type_at(0));
520520
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
521521
// branch
522-
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
522+
let meta = if let BackendRepr::ScalarPair(_, _) = ptr.layout().backend_repr {
523523
Some(ptr.load_scalar_pair(fx).1)
524524
} else {
525525
None
@@ -693,7 +693,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
693693
let layout = fx.layout_of(ty);
694694
let msg_str = with_no_visible_paths!({
695695
with_no_trimmed_paths!({
696-
if layout.abi.is_uninhabited() {
696+
if layout.is_uninhabited() {
697697
// Use this error even for the other intrinsics as it is more precise.
698698
format!("attempted to instantiate uninhabited type `{}`", ty)
699699
} else if intrinsic == sym::assert_zero_valid {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ mod prelude {
9292
StackSlotData, StackSlotKind, TrapCode, Type, Value, types,
9393
};
9494
pub(crate) use cranelift_module::{self, DataDescription, FuncId, Linkage, Module};
95+
pub(crate) use rustc_abi::{BackendRepr, FIRST_VARIANT, FieldIdx, Scalar, Size, VariantIdx};
9596
pub(crate) use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
9697
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
9798
pub(crate) use rustc_index::Idx;
@@ -101,7 +102,6 @@ mod prelude {
101102
self, FloatTy, Instance, InstanceKind, IntTy, ParamEnv, Ty, TyCtxt, UintTy,
102103
};
103104
pub(crate) use rustc_span::Span;
104-
pub(crate) use rustc_target::abi::{Abi, FIRST_VARIANT, FieldIdx, Scalar, Size, VariantIdx};
105105

106106
pub(crate) use crate::abi::*;
107107
pub(crate) use crate::base::{codegen_operand, codegen_place};

src/value_and_place.rs

+33-24
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ impl<'tcx> CValue<'tcx> {
131131

132132
match self.0 {
133133
CValueInner::ByRef(ptr, None) => {
134-
let (a_scalar, b_scalar) = match self.1.abi {
135-
Abi::ScalarPair(a, b) => (a, b),
134+
let (a_scalar, b_scalar) = match self.1.backend_repr {
135+
BackendRepr::ScalarPair(a, b) => (a, b),
136136
_ => unreachable!("dyn_star_force_data_on_stack({:?})", self),
137137
};
138138
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
@@ -164,15 +164,15 @@ impl<'tcx> CValue<'tcx> {
164164
}
165165
}
166166

167-
/// Load a value with layout.abi of scalar
167+
/// Load a value with layout.backend_repr of scalar
168168
#[track_caller]
169169
pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> Value {
170170
let layout = self.1;
171171
match self.0 {
172172
CValueInner::ByRef(ptr, None) => {
173-
let clif_ty = match layout.abi {
174-
Abi::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar),
175-
Abi::Vector { element, count } => scalar_to_clif_type(fx.tcx, element)
173+
let clif_ty = match layout.backend_repr {
174+
BackendRepr::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar),
175+
BackendRepr::Vector { element, count } => scalar_to_clif_type(fx.tcx, element)
176176
.by(u32::try_from(count).unwrap())
177177
.unwrap(),
178178
_ => unreachable!("{:?}", layout.ty),
@@ -187,14 +187,14 @@ impl<'tcx> CValue<'tcx> {
187187
}
188188
}
189189

190-
/// Load a value pair with layout.abi of scalar pair
190+
/// Load a value pair with layout.backend_repr of scalar pair
191191
#[track_caller]
192192
pub(crate) fn load_scalar_pair(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Value, Value) {
193193
let layout = self.1;
194194
match self.0 {
195195
CValueInner::ByRef(ptr, None) => {
196-
let (a_scalar, b_scalar) = match layout.abi {
197-
Abi::ScalarPair(a, b) => (a, b),
196+
let (a_scalar, b_scalar) = match layout.backend_repr {
197+
BackendRepr::ScalarPair(a, b) => (a, b),
198198
_ => unreachable!("load_scalar_pair({:?})", self),
199199
};
200200
let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
@@ -222,8 +222,8 @@ impl<'tcx> CValue<'tcx> {
222222
let layout = self.1;
223223
match self.0 {
224224
CValueInner::ByVal(_) => unreachable!(),
225-
CValueInner::ByValPair(val1, val2) => match layout.abi {
226-
Abi::ScalarPair(_, _) => {
225+
CValueInner::ByValPair(val1, val2) => match layout.backend_repr {
226+
BackendRepr::ScalarPair(_, _) => {
227227
let val = match field.as_u32() {
228228
0 => val1,
229229
1 => val2,
@@ -232,7 +232,7 @@ impl<'tcx> CValue<'tcx> {
232232
let field_layout = layout.field(&*fx, usize::from(field));
233233
CValue::by_val(val, field_layout)
234234
}
235-
_ => unreachable!("value_field for ByValPair with abi {:?}", layout.abi),
235+
_ => unreachable!("value_field for ByValPair with abi {:?}", layout.backend_repr),
236236
},
237237
CValueInner::ByRef(ptr, None) => {
238238
let (field_ptr, field_layout) = codegen_field(fx, ptr, None, layout, field);
@@ -360,7 +360,7 @@ impl<'tcx> CValue<'tcx> {
360360
pub(crate) fn cast_pointer_to(self, layout: TyAndLayout<'tcx>) -> Self {
361361
assert!(matches!(self.layout().ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
362362
assert!(matches!(layout.ty.kind(), ty::Ref(..) | ty::RawPtr(..) | ty::FnPtr(..)));
363-
assert_eq!(self.layout().abi, layout.abi);
363+
assert_eq!(self.layout().backend_repr, layout.backend_repr);
364364
CValue(self.0, layout)
365365
}
366366
}
@@ -609,8 +609,8 @@ impl<'tcx> CPlace<'tcx> {
609609
let dst_layout = self.layout();
610610
match self.inner {
611611
CPlaceInner::Var(_local, var) => {
612-
let data = match from.1.abi {
613-
Abi::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx),
612+
let data = match from.1.backend_repr {
613+
BackendRepr::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx),
614614
_ => {
615615
let (ptr, meta) = from.force_stack(fx);
616616
assert!(meta.is_none());
@@ -621,8 +621,10 @@ impl<'tcx> CPlace<'tcx> {
621621
transmute_scalar(fx, var, data, dst_ty);
622622
}
623623
CPlaceInner::VarPair(_local, var1, var2) => {
624-
let (data1, data2) = match from.1.abi {
625-
Abi::ScalarPair(_, _) => CValue(from.0, dst_layout).load_scalar_pair(fx),
624+
let (data1, data2) = match from.1.backend_repr {
625+
BackendRepr::ScalarPair(_, _) => {
626+
CValue(from.0, dst_layout).load_scalar_pair(fx)
627+
}
626628
_ => {
627629
let (ptr, meta) = from.force_stack(fx);
628630
assert!(meta.is_none());
@@ -635,7 +637,9 @@ impl<'tcx> CPlace<'tcx> {
635637
}
636638
CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self),
637639
CPlaceInner::Addr(to_ptr, None) => {
638-
if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited {
640+
if dst_layout.size == Size::ZERO
641+
|| dst_layout.backend_repr == BackendRepr::Uninhabited
642+
{
639643
return;
640644
}
641645

@@ -646,23 +650,28 @@ impl<'tcx> CPlace<'tcx> {
646650
CValueInner::ByVal(val) => {
647651
to_ptr.store(fx, val, flags);
648652
}
649-
CValueInner::ByValPair(val1, val2) => match from.layout().abi {
650-
Abi::ScalarPair(a_scalar, b_scalar) => {
653+
CValueInner::ByValPair(val1, val2) => match from.layout().backend_repr {
654+
BackendRepr::ScalarPair(a_scalar, b_scalar) => {
651655
let b_offset =
652656
scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
653657
to_ptr.store(fx, val1, flags);
654658
to_ptr.offset(fx, b_offset).store(fx, val2, flags);
655659
}
656-
_ => bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi),
660+
_ => {
661+
bug!(
662+
"Non ScalarPair repr {:?} for ByValPair CValue",
663+
dst_layout.backend_repr
664+
)
665+
}
657666
},
658667
CValueInner::ByRef(from_ptr, None) => {
659-
match from.layout().abi {
660-
Abi::Scalar(_) => {
668+
match from.layout().backend_repr {
669+
BackendRepr::Scalar(_) => {
661670
let val = from.load_scalar(fx);
662671
to_ptr.store(fx, val, flags);
663672
return;
664673
}
665-
Abi::ScalarPair(a_scalar, b_scalar) => {
674+
BackendRepr::ScalarPair(a_scalar, b_scalar) => {
666675
let b_offset =
667676
scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
668677
let (val1, val2) = from.load_scalar_pair(fx);

src/vtable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
4747
idx: usize,
4848
) -> (Pointer, Value) {
4949
let (ptr, vtable) = 'block: {
50-
if let Abi::Scalar(_) = arg.layout().abi {
50+
if let BackendRepr::Scalar(_) = arg.layout().backend_repr {
5151
while !arg.layout().ty.is_unsafe_ptr() && !arg.layout().ty.is_ref() {
5252
let (idx, _) = arg
5353
.layout()
@@ -68,7 +68,7 @@ pub(crate) fn get_ptr_and_method_ref<'tcx>(
6868
}
6969
}
7070

71-
if let Abi::ScalarPair(_, _) = arg.layout().abi {
71+
if let BackendRepr::ScalarPair(_, _) = arg.layout().backend_repr {
7272
let (ptr, vtable) = arg.load_scalar_pair(fx);
7373
(Pointer::new(ptr), vtable)
7474
} else {

0 commit comments

Comments
 (0)