Skip to content

Commit f33fb02

Browse files
rustc_abi::Abi to IrForm in rustc_target
1 parent ff6d147 commit f33fb02

File tree

9 files changed

+66
-59
lines changed

9 files changed

+66
-59
lines changed

compiler/rustc_target/src/callconv/loongarch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
2-
use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{self, FieldsShape, HasDataLayout, IrForm, Size, TyAbiInterface, TyAndLayout};
33
use crate::spec::HasTargetSpec;
44
use crate::spec::abi::Abi as SpecAbi;
55

@@ -21,8 +21,8 @@ enum FloatConv {
2121
struct CannotUseFpConv;
2222

2323
fn is_loongarch_aggregate<Ty>(arg: &ArgAbi<'_, Ty>) -> bool {
24-
match arg.layout.abi {
25-
Abi::Vector { .. } => true,
24+
match arg.layout.ir_form {
25+
IrForm::Vector { .. } => true,
2626
_ => arg.layout.is_aggregate(),
2727
}
2828
}
@@ -38,8 +38,8 @@ fn should_use_fp_conv_helper<'a, Ty, C>(
3838
where
3939
Ty: TyAbiInterface<'a, C> + Copy,
4040
{
41-
match arg_layout.abi {
42-
Abi::Scalar(scalar) => match scalar.primitive() {
41+
match arg_layout.ir_form {
42+
IrForm::Scalar(scalar) => match scalar.primitive() {
4343
abi::Int(..) | abi::Pointer(_) => {
4444
if arg_layout.size.bits() > xlen {
4545
return Err(CannotUseFpConv);
@@ -77,8 +77,8 @@ where
7777
}
7878
}
7979
},
80-
Abi::Vector { .. } | Abi::Uninhabited => return Err(CannotUseFpConv),
81-
Abi::ScalarPair(..) | Abi::Aggregate { .. } => match arg_layout.fields {
80+
IrForm::Vector { .. } | IrForm::Uninhabited => return Err(CannotUseFpConv),
81+
IrForm::ScalarPair(..) | IrForm::Memory { .. } => match arg_layout.fields {
8282
FieldsShape::Primitive => {
8383
unreachable!("aggregates can't have `FieldsShape::Primitive`")
8484
}
@@ -311,7 +311,7 @@ fn classify_arg<'a, Ty, C>(
311311
}
312312

313313
fn extend_integer_width<Ty>(arg: &mut ArgAbi<'_, Ty>, xlen: u64) {
314-
if let Abi::Scalar(scalar) = arg.layout.abi {
314+
if let IrForm::Scalar(scalar) = arg.layout.ir_form {
315315
if let abi::Int(i, _) = scalar.primitive() {
316316
// 32-bit integers are always sign-extended
317317
if i.size().bits() == 32 && xlen > 32 {

compiler/rustc_target/src/callconv/mips64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::abi::{self, HasDataLayout, Size, TyAbiInterface};
55

66
fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
77
// Always sign extend u32 values on 64-bit mips
8-
if let abi::Abi::Scalar(scalar) = arg.layout.abi {
8+
if let abi::IrForm::Scalar(scalar) = arg.layout.ir_form {
99
if let abi::Int(i, signed) = scalar.primitive() {
1010
if !signed && i.size().bits() == 32 {
1111
if let PassMode::Direct(ref mut attrs) = arg.mode {
@@ -24,8 +24,8 @@ where
2424
Ty: TyAbiInterface<'a, C> + Copy,
2525
C: HasDataLayout,
2626
{
27-
match ret.layout.field(cx, i).abi {
28-
abi::Abi::Scalar(scalar) => match scalar.primitive() {
27+
match ret.layout.field(cx, i).ir_form {
28+
abi::IrForm::Scalar(scalar) => match scalar.primitive() {
2929
abi::Float(abi::F32) => Some(Reg::f32()),
3030
abi::Float(abi::F64) => Some(Reg::f64()),
3131
_ => None,
@@ -109,7 +109,7 @@ where
109109
let offset = arg.layout.fields.offset(i);
110110

111111
// We only care about aligned doubles
112-
if let abi::Abi::Scalar(scalar) = field.abi {
112+
if let abi::IrForm::Scalar(scalar) = field.ir_form {
113113
if scalar.primitive() == abi::Float(abi::F64) {
114114
if offset.is_aligned(dl.f64_align.abi) {
115115
// Insert enough integers to cover [last_offset, offset)

compiler/rustc_target/src/callconv/mod.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_macros::HashStable_Generic;
66
use rustc_span::Symbol;
77

88
use crate::abi::{
9-
self, Abi, AddressSpace, Align, HasDataLayout, Pointer, Size, TyAbiInterface, TyAndLayout,
9+
self, AddressSpace, Align, HasDataLayout, IrForm, Pointer, Size, TyAbiInterface, TyAndLayout,
1010
};
1111
use crate::spec::abi::Abi as SpecAbi;
1212
use crate::spec::{self, HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
@@ -350,15 +350,15 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
350350
layout: TyAndLayout<'a, Ty>,
351351
scalar_attrs: impl Fn(&TyAndLayout<'a, Ty>, abi::Scalar, Size) -> ArgAttributes,
352352
) -> Self {
353-
let mode = match layout.abi {
354-
Abi::Uninhabited => PassMode::Ignore,
355-
Abi::Scalar(scalar) => PassMode::Direct(scalar_attrs(&layout, scalar, Size::ZERO)),
356-
Abi::ScalarPair(a, b) => PassMode::Pair(
353+
let mode = match layout.ir_form {
354+
IrForm::Uninhabited => PassMode::Ignore,
355+
IrForm::Scalar(scalar) => PassMode::Direct(scalar_attrs(&layout, scalar, Size::ZERO)),
356+
IrForm::ScalarPair(a, b) => PassMode::Pair(
357357
scalar_attrs(&layout, a, Size::ZERO),
358358
scalar_attrs(&layout, b, a.size(cx).align_to(b.align(cx).abi)),
359359
),
360-
Abi::Vector { .. } => PassMode::Direct(ArgAttributes::new()),
361-
Abi::Aggregate { .. } => Self::indirect_pass_mode(&layout),
360+
IrForm::Vector { .. } => PassMode::Direct(ArgAttributes::new()),
361+
IrForm::Memory { .. } => Self::indirect_pass_mode(&layout),
362362
};
363363
ArgAbi { layout, mode }
364364
}
@@ -460,7 +460,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
460460

461461
pub fn extend_integer_width_to(&mut self, bits: u64) {
462462
// Only integers have signedness
463-
if let Abi::Scalar(scalar) = self.layout.abi {
463+
if let IrForm::Scalar(scalar) = self.layout.ir_form {
464464
if let abi::Int(i, signed) = scalar.primitive() {
465465
if i.size().bits() < bits {
466466
if let PassMode::Direct(ref mut attrs) = self.mode {
@@ -512,7 +512,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
512512
// That elevates any type difference to an ABI difference since we just use the
513513
// full Rust type as the LLVM argument/return type.
514514
if matches!(self.mode, PassMode::Direct(..))
515-
&& matches!(self.layout.abi, Abi::Aggregate { .. })
515+
&& matches!(self.layout.ir_form, IrForm::Memory { .. })
516516
{
517517
// For aggregates in `Direct` mode to be compatible, the types need to be equal.
518518
self.layout.ty == other.layout.ty
@@ -791,8 +791,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
791791
continue;
792792
}
793793

794-
match arg.layout.abi {
795-
Abi::Aggregate { .. } => {}
794+
match arg.layout.ir_form {
795+
IrForm::Memory { .. } => {}
796796

797797
// This is a fun case! The gist of what this is doing is
798798
// that we want callers and callees to always agree on the
@@ -813,7 +813,9 @@ impl<'a, Ty> FnAbi<'a, Ty> {
813813
// Note that the intrinsic ABI is exempt here as
814814
// that's how we connect up to LLVM and it's unstable
815815
// anyway, we control all calls to it in libstd.
816-
Abi::Vector { .. } if abi != SpecAbi::RustIntrinsic && spec.simd_types_indirect => {
816+
IrForm::Vector { .. }
817+
if abi != SpecAbi::RustIntrinsic && spec.simd_types_indirect =>
818+
{
817819
arg.make_indirect();
818820
continue;
819821
}

compiler/rustc_target/src/callconv/riscv.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
// Reference: Clang RISC-V ELF psABI lowering code
55
// https://github.com/llvm/llvm-project/blob/8e780252a7284be45cf1ba224cabd884847e8e92/clang/lib/CodeGen/TargetInfo.cpp#L9311-L9773
66

7+
use rustc_abi::{FieldsShape, HasDataLayout, IrForm, Size, TyAbiInterface, TyAndLayout};
8+
9+
use crate::abi;
710
use crate::abi::call::{ArgAbi, ArgExtension, CastTarget, FnAbi, PassMode, Reg, RegKind, Uniform};
8-
use crate::abi::{self, Abi, FieldsShape, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
911
use crate::spec::HasTargetSpec;
1012
use crate::spec::abi::Abi as SpecAbi;
1113

@@ -27,8 +29,8 @@ enum FloatConv {
2729
struct CannotUseFpConv;
2830

2931
fn is_riscv_aggregate<Ty>(arg: &ArgAbi<'_, Ty>) -> bool {
30-
match arg.layout.abi {
31-
Abi::Vector { .. } => true,
32+
match arg.layout.ir_form {
33+
IrForm::Vector { .. } => true,
3234
_ => arg.layout.is_aggregate(),
3335
}
3436
}
@@ -44,8 +46,8 @@ fn should_use_fp_conv_helper<'a, Ty, C>(
4446
where
4547
Ty: TyAbiInterface<'a, C> + Copy,
4648
{
47-
match arg_layout.abi {
48-
Abi::Scalar(scalar) => match scalar.primitive() {
49+
match arg_layout.ir_form {
50+
IrForm::Scalar(scalar) => match scalar.primitive() {
4951
abi::Int(..) | abi::Pointer(_) => {
5052
if arg_layout.size.bits() > xlen {
5153
return Err(CannotUseFpConv);
@@ -83,8 +85,8 @@ where
8385
}
8486
}
8587
},
86-
Abi::Vector { .. } | Abi::Uninhabited => return Err(CannotUseFpConv),
87-
Abi::ScalarPair(..) | Abi::Aggregate { .. } => match arg_layout.fields {
88+
IrForm::Vector { .. } | IrForm::Uninhabited => return Err(CannotUseFpConv),
89+
IrForm::ScalarPair(..) | IrForm::Memory { .. } => match arg_layout.fields {
8890
FieldsShape::Primitive => {
8991
unreachable!("aggregates can't have `FieldsShape::Primitive`")
9092
}
@@ -317,7 +319,7 @@ fn classify_arg<'a, Ty, C>(
317319
}
318320

319321
fn extend_integer_width<Ty>(arg: &mut ArgAbi<'_, Ty>, xlen: u64) {
320-
if let Abi::Scalar(scalar) = arg.layout.abi {
322+
if let IrForm::Scalar(scalar) = arg.layout.ir_form {
321323
if let abi::Int(i, _) = scalar.primitive() {
322324
// 32-bit integers are always sign-extended
323325
if i.size().bits() == 32 && xlen > 32 {

compiler/rustc_target/src/callconv/sparc64.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ where
109109
return data;
110110
}
111111

112-
match layout.abi {
113-
abi::Abi::Scalar(scalar) => {
112+
match layout.ir_form {
113+
abi::IrForm::Scalar(scalar) => {
114114
data = arg_scalar(cx, &scalar, offset, data);
115115
}
116-
abi::Abi::Aggregate { .. } => {
116+
abi::IrForm::Memory { .. } => {
117117
for i in 0..layout.fields.count() {
118118
if offset < layout.fields.offset(i) {
119119
offset = layout.fields.offset(i);
@@ -122,7 +122,7 @@ where
122122
}
123123
}
124124
_ => {
125-
if let abi::Abi::ScalarPair(scalar1, scalar2) = &layout.abi {
125+
if let abi::IrForm::ScalarPair(scalar1, scalar2) = &layout.ir_form {
126126
data = arg_scalar_pair(cx, scalar1, scalar2, offset, data);
127127
}
128128
}

compiler/rustc_target/src/callconv/x86.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind};
22
use crate::abi::{
3-
Abi, AddressSpace, Align, Float, HasDataLayout, Pointer, TyAbiInterface, TyAndLayout,
3+
AddressSpace, Align, Float, HasDataLayout, IrForm, Pointer, TyAbiInterface, TyAndLayout,
44
};
55
use crate::spec::HasTargetSpec;
66
use crate::spec::abi::Abi as SpecAbi;
@@ -105,10 +105,10 @@ where
105105
where
106106
Ty: TyAbiInterface<'a, C> + Copy,
107107
{
108-
match layout.abi {
109-
Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) => false,
110-
Abi::Vector { .. } => true,
111-
Abi::Aggregate { .. } => {
108+
match layout.ir_form {
109+
IrForm::Uninhabited | IrForm::Scalar(_) | IrForm::ScalarPair(..) => false,
110+
IrForm::Vector { .. } => true,
111+
IrForm::Memory { .. } => {
112112
for i in 0..layout.fields.count() {
113113
if contains_vector(cx, layout.field(cx, i)) {
114114
return true;
@@ -223,9 +223,9 @@ where
223223
// Intrinsics themselves are not actual "real" functions, so theres no need to change their ABIs.
224224
&& abi != SpecAbi::RustIntrinsic
225225
{
226-
let has_float = match fn_abi.ret.layout.abi {
227-
Abi::Scalar(s) => matches!(s.primitive(), Float(_)),
228-
Abi::ScalarPair(s1, s2) => {
226+
let has_float = match fn_abi.ret.layout.ir_form {
227+
IrForm::Scalar(s) => matches!(s.primitive(), Float(_)),
228+
IrForm::ScalarPair(s1, s2) => {
229229
matches!(s1.primitive(), Float(_)) || matches!(s2.primitive(), Float(_))
230230
}
231231
_ => false, // anyway not passed via registers on x86

compiler/rustc_target/src/callconv/x86_64.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// The classification code for the x86_64 ABI is taken from the clay language
22
// https://github.com/jckarter/clay/blob/db0bd2702ab0b6e48965cd85f8859bbd5f60e48e/compiler/externals.cpp
33

4+
use rustc_abi::{HasDataLayout, IrForm, Size, TyAbiInterface, TyAndLayout};
5+
6+
use crate::abi;
47
use crate::abi::call::{ArgAbi, CastTarget, FnAbi, Reg, RegKind};
5-
use crate::abi::{self, Abi, HasDataLayout, Size, TyAbiInterface, TyAndLayout};
68

79
/// Classification of "eightbyte" components.
810
// N.B., the order of the variants is from general to specific,
@@ -46,17 +48,17 @@ where
4648
return Ok(());
4749
}
4850

49-
let mut c = match layout.abi {
50-
Abi::Uninhabited => return Ok(()),
51+
let mut c = match layout.ir_form {
52+
IrForm::Uninhabited => return Ok(()),
5153

52-
Abi::Scalar(scalar) => match scalar.primitive() {
54+
IrForm::Scalar(scalar) => match scalar.primitive() {
5355
abi::Int(..) | abi::Pointer(_) => Class::Int,
5456
abi::Float(_) => Class::Sse,
5557
},
5658

57-
Abi::Vector { .. } => Class::Sse,
59+
IrForm::Vector { .. } => Class::Sse,
5860

59-
Abi::ScalarPair(..) | Abi::Aggregate { .. } => {
61+
IrForm::ScalarPair(..) | IrForm::Memory { .. } => {
6062
for i in 0..layout.fields.count() {
6163
let field_off = off + layout.fields.offset(i);
6264
classify(cx, layout.field(cx, i), cls, field_off)?;

compiler/rustc_target/src/callconv/x86_win64.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
use rustc_abi::{Float, IrForm, Primitive};
2+
13
use crate::abi::call::{ArgAbi, FnAbi, Reg};
2-
use crate::abi::{Abi, Float, Primitive};
34
use crate::spec::HasTargetSpec;
45

56
// Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing
67

78
pub(crate) fn compute_abi_info<Ty>(cx: &impl HasTargetSpec, fn_abi: &mut FnAbi<'_, Ty>) {
89
let fixup = |a: &mut ArgAbi<'_, Ty>| {
9-
match a.layout.abi {
10-
Abi::Uninhabited | Abi::Aggregate { sized: false } => {}
11-
Abi::ScalarPair(..) | Abi::Aggregate { sized: true } => match a.layout.size.bits() {
10+
match a.layout.ir_form {
11+
IrForm::Uninhabited | IrForm::Memory { sized: false } => {}
12+
IrForm::ScalarPair(..) | IrForm::Memory { sized: true } => match a.layout.size.bits() {
1213
8 => a.cast_to(Reg::i8()),
1314
16 => a.cast_to(Reg::i16()),
1415
32 => a.cast_to(Reg::i32()),
1516
64 => a.cast_to(Reg::i64()),
1617
_ => a.make_indirect(),
1718
},
18-
Abi::Vector { .. } => {
19+
IrForm::Vector { .. } => {
1920
// FIXME(eddyb) there should be a size cap here
2021
// (probably what clang calls "illegal vectors").
2122
}
22-
Abi::Scalar(scalar) => {
23+
IrForm::Scalar(scalar) => {
2324
// Match what LLVM does for `f128` so that `compiler-builtins` builtins match up
2425
// with what LLVM expects.
2526
if a.layout.size.bytes() > 8

compiler/rustc_target/src/callconv/xtensa.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//! Section 2.3 from the Xtensa programmers guide.
77
88
use crate::abi::call::{ArgAbi, FnAbi, Reg, Uniform};
9-
use crate::abi::{Abi, HasDataLayout, Size, TyAbiInterface};
9+
use crate::abi::{HasDataLayout, IrForm, Size, TyAbiInterface};
1010
use crate::spec::HasTargetSpec;
1111

1212
const NUM_ARG_GPRS: u64 = 6;
@@ -114,8 +114,8 @@ where
114114
}
115115

116116
fn is_xtensa_aggregate<'a, Ty>(arg: &ArgAbi<'a, Ty>) -> bool {
117-
match arg.layout.abi {
118-
Abi::Vector { .. } => true,
117+
match arg.layout.ir_form {
118+
IrForm::Vector { .. } => true,
119119
_ => arg.layout.is_aggregate(),
120120
}
121121
}

0 commit comments

Comments
 (0)