Skip to content

Commit 57b314f

Browse files
cg_clif: rustc_abi::Abi => IrForm
1 parent 886171f commit 57b314f

File tree

8 files changed

+55
-53
lines changed

8 files changed

+55
-53
lines changed

compiler/rustc_codegen_cranelift/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 IrForm::ScalarPair(_, _) = layout.ir_form {
197197
CPlace::new_var_pair(fx, local, layout)
198198
} else {
199199
CPlace::new_var(fx, local, layout)

compiler/rustc_codegen_cranelift/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.ir_form {
82+
IrForm::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+
IrForm::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.ir_form),
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.ir_form {
93+
IrForm::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.ir_form),
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.ir_form {
134+
IrForm::Scalar(scalar) => {
135135
(None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))])
136136
}
137-
Abi::Vector { .. } => {
137+
IrForm::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.ir_form),
142142
},
143-
PassMode::Pair(_, _) => match self.layout.abi {
144-
Abi::ScalarPair(a, b) => {
143+
PassMode::Pair(_, _) => match self.layout.ir_form {
144+
IrForm::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.ir_form),
150150
},
151151
PassMode::Cast { ref cast, .. } => {
152152
(None, cast_target_to_abi_params(cast).into_iter().collect())

compiler/rustc_codegen_cranelift/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.ir_form {
648+
IrForm::Scalar(_) => CValue::zst(dest_layout),
649+
IrForm::ScalarPair(_, _) => {
650650
CValue::by_val(operand.load_scalar_pair(fx).1, dest_layout)
651651
}
652652
_ => bug!("Unexpected `PtrToMetadata` operand: {operand:?}"),

compiler/rustc_codegen_cranelift/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

compiler/rustc_codegen_cranelift/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.ir_form {
55+
IrForm::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 IrForm::ScalarPair(_, _) = ptr.layout().ir_form {
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 IrForm::ScalarPair(_, _) = ptr.layout().ir_form {
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 {

compiler/rustc_codegen_cranelift/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::{FIRST_VARIANT, FieldIdx, IrForm, 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};

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+26-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.ir_form {
135+
IrForm::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.ir_form 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.ir_form {
174+
IrForm::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar),
175+
IrForm::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.ir_form 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.ir_form {
197+
IrForm::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.ir_form {
226+
IrForm::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.ir_form),
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().ir_form, layout.ir_form);
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.ir_form {
613+
IrForm::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,8 @@ 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.ir_form {
625+
IrForm::ScalarPair(_, _) => CValue(from.0, dst_layout).load_scalar_pair(fx),
626626
_ => {
627627
let (ptr, meta) = from.force_stack(fx);
628628
assert!(meta.is_none());
@@ -635,7 +635,7 @@ impl<'tcx> CPlace<'tcx> {
635635
}
636636
CPlaceInner::Addr(_, Some(_)) => bug!("Can't write value to unsized place {:?}", self),
637637
CPlaceInner::Addr(to_ptr, None) => {
638-
if dst_layout.size == Size::ZERO || dst_layout.abi == Abi::Uninhabited {
638+
if dst_layout.size == Size::ZERO || dst_layout.ir_form == IrForm::Uninhabited {
639639
return;
640640
}
641641

@@ -646,23 +646,25 @@ impl<'tcx> CPlace<'tcx> {
646646
CValueInner::ByVal(val) => {
647647
to_ptr.store(fx, val, flags);
648648
}
649-
CValueInner::ByValPair(val1, val2) => match from.layout().abi {
650-
Abi::ScalarPair(a_scalar, b_scalar) => {
649+
CValueInner::ByValPair(val1, val2) => match from.layout().ir_form {
650+
IrForm::ScalarPair(a_scalar, b_scalar) => {
651651
let b_offset =
652652
scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
653653
to_ptr.store(fx, val1, flags);
654654
to_ptr.offset(fx, b_offset).store(fx, val2, flags);
655655
}
656-
_ => bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.abi),
656+
_ => {
657+
bug!("Non ScalarPair abi {:?} for ByValPair CValue", dst_layout.ir_form)
658+
}
657659
},
658660
CValueInner::ByRef(from_ptr, None) => {
659-
match from.layout().abi {
660-
Abi::Scalar(_) => {
661+
match from.layout().ir_form {
662+
IrForm::Scalar(_) => {
661663
let val = from.load_scalar(fx);
662664
to_ptr.store(fx, val, flags);
663665
return;
664666
}
665-
Abi::ScalarPair(a_scalar, b_scalar) => {
667+
IrForm::ScalarPair(a_scalar, b_scalar) => {
666668
let b_offset =
667669
scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar);
668670
let (val1, val2) = from.load_scalar_pair(fx);

compiler/rustc_codegen_cranelift/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 IrForm::Scalar(_) = arg.layout().ir_form {
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 IrForm::ScalarPair(_, _) = arg.layout().ir_form {
7272
let (ptr, vtable) = arg.load_scalar_pair(fx);
7373
(Pointer::new(ptr), vtable)
7474
} else {

0 commit comments

Comments
 (0)