Skip to content

Commit 0c44c66

Browse files
authored
Rollup merge of rust-lang#92021 - woodenarrow:br_single_fp_element, r=Mark-Simulacrum
Eliminate duplicate codes of is_single_fp_element There are duplicate codes of is_single_fp_element function. Merge these codes to TyAndLayout impl block. ![image](https://user-images.githubusercontent.com/95843988/146707753-ba9ffc41-5888-4a53-80cf-f4fe3bcbac54.png)
2 parents 2d658e9 + d9b98f9 commit 0c44c66

File tree

3 files changed

+22
-40
lines changed

3 files changed

+22
-40
lines changed

compiler/rustc_target/src/abi/call/s390x.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// for a pre-z13 machine or using -mno-vx.
33

44
use crate::abi::call::{ArgAbi, FnAbi, Reg};
5-
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
5+
use crate::abi::{HasDataLayout, TyAbiInterface};
66

77
fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
88
if !ret.layout.is_aggregate() && ret.layout.size.bits() <= 64 {
@@ -12,24 +12,6 @@ fn classify_ret<Ty>(ret: &mut ArgAbi<'_, Ty>) {
1212
}
1313
}
1414

15-
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
16-
where
17-
Ty: TyAbiInterface<'a, C>,
18-
C: HasDataLayout,
19-
{
20-
match layout.abi {
21-
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
22-
abi::Abi::Aggregate { .. } => {
23-
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
24-
is_single_fp_element(cx, layout.field(cx, 0))
25-
} else {
26-
false
27-
}
28-
}
29-
_ => false,
30-
}
31-
}
32-
3315
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>)
3416
where
3517
Ty: TyAbiInterface<'a, C> + Copy,
@@ -40,7 +22,7 @@ where
4022
return;
4123
}
4224

43-
if is_single_fp_element(cx, arg.layout) {
25+
if arg.layout.is_single_fp_element(cx) {
4426
match arg.layout.size.bytes() {
4527
4 => arg.cast_to(Reg::f32()),
4628
8 => arg.cast_to(Reg::f64()),

compiler/rustc_target/src/abi/call/x86.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::abi::call::{ArgAttribute, FnAbi, PassMode, Reg, RegKind};
2-
use crate::abi::{self, HasDataLayout, TyAbiInterface, TyAndLayout};
2+
use crate::abi::{HasDataLayout, TyAbiInterface};
33
use crate::spec::HasTargetSpec;
44

55
#[derive(PartialEq)]
@@ -8,24 +8,6 @@ pub enum Flavor {
88
Fastcall,
99
}
1010

11-
fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
12-
where
13-
Ty: TyAbiInterface<'a, C> + Copy,
14-
C: HasDataLayout,
15-
{
16-
match layout.abi {
17-
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
18-
abi::Abi::Aggregate { .. } => {
19-
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
20-
is_single_fp_element(cx, layout.field(cx, 0))
21-
} else {
22-
false
23-
}
24-
}
25-
_ => false,
26-
}
27-
}
28-
2911
pub fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>, flavor: Flavor)
3012
where
3113
Ty: TyAbiInterface<'a, C> + Copy,
@@ -44,7 +26,7 @@ where
4426
if t.abi_return_struct_as_int {
4527
// According to Clang, everyone but MSVC returns single-element
4628
// float aggregates directly in a floating-point register.
47-
if !t.is_like_msvc && is_single_fp_element(cx, fn_abi.ret.layout) {
29+
if !t.is_like_msvc && fn_abi.ret.layout.is_single_fp_element(cx) {
4830
match fn_abi.ret.layout.size.bytes() {
4931
4 => fn_abi.ret.cast_to(Reg::f32()),
5032
8 => fn_abi.ret.cast_to(Reg::f64()),

compiler/rustc_target/src/abi/mod.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1276,6 +1276,24 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
12761276
{
12771277
Ty::ty_and_layout_pointee_info_at(self, cx, offset)
12781278
}
1279+
1280+
pub fn is_single_fp_element<C>(self, cx: &C) -> bool
1281+
where
1282+
Ty: TyAbiInterface<'a, C>,
1283+
C: HasDataLayout,
1284+
{
1285+
match self.abi {
1286+
Abi::Scalar(scalar) => scalar.value.is_float(),
1287+
Abi::Aggregate { .. } => {
1288+
if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 {
1289+
self.field(cx, 0).is_single_fp_element(cx)
1290+
} else {
1291+
false
1292+
}
1293+
}
1294+
_ => false,
1295+
}
1296+
}
12791297
}
12801298

12811299
impl<'a, Ty> TyAndLayout<'a, Ty> {

0 commit comments

Comments
 (0)