-
Notifications
You must be signed in to change notification settings - Fork 12.8k
/
s390x.rs
107 lines (98 loc) · 3.13 KB
/
s390x.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
use crate::abi::call::{ArgAbi, FnAbi, Reg, RegKind};
use crate::abi::{Abi, HasDataLayout, TyAbiInterface, TyAndLayout};
use crate::spec::{HasS390xVector, HasTargetSpec};
#[derive(Debug, Clone, Copy, PartialEq)]
enum ABI {
NoVector, // no-vector ABI, i.e., compiling for a pre-z13 machine or using -C target-feature=-vector
Vector, // vector ABI, i.e., compiling for a z13 or later machine or using -C target-feature=+vector
}
use ABI::*;
fn contains_vector<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool
where
Ty: TyAbiInterface<'a, C> + Copy,
{
match layout.abi {
Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) => false,
Abi::Vector { .. } => layout.size.bits() == 128,
Abi::Aggregate { .. } => {
for i in 0..layout.fields.count() {
if contains_vector(cx, layout.field(cx, i)) {
return true;
}
}
false
}
}
}
fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, abi: ABI)
where
Ty: TyAbiInterface<'a, C> + Copy,
{
let size = ret.layout.size;
if !ret.layout.is_aggregate() && size.bits() <= 64 {
ret.extend_integer_width_to(64);
return;
}
if abi == Vector && size.bits() == 128 && contains_vector(cx, ret.layout) {
ret.cast_to(Reg { kind: RegKind::Vector, size });
return;
}
ret.make_indirect();
}
fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, abi: ABI)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec,
{
if !arg.layout.is_sized() {
// Not touching this...
return;
}
if arg.is_ignore() {
// s390x-unknown-linux-{gnu,musl,uclibc} doesn't ignore ZSTs.
if cx.target_spec().os == "linux"
&& matches!(&*cx.target_spec().env, "gnu" | "musl" | "uclibc")
&& arg.layout.is_zst()
{
arg.make_indirect_from_ignore();
}
return;
}
let size = arg.layout.size;
if !arg.layout.is_aggregate() && size.bits() <= 64 {
arg.extend_integer_width_to(64);
return;
}
if abi == Vector && size.bits() == 128 && contains_vector(cx, arg.layout) {
arg.cast_to(Reg { kind: RegKind::Vector, size });
return;
}
if arg.layout.is_single_fp_element(cx) {
match size.bytes() {
4 => arg.cast_to(Reg::f32()),
8 => arg.cast_to(Reg::f64()),
_ => arg.make_indirect(),
}
} else {
match size.bytes() {
1 => arg.cast_to(Reg::i8()),
2 => arg.cast_to(Reg::i16()),
4 => arg.cast_to(Reg::i32()),
8 => arg.cast_to(Reg::i64()),
_ => arg.make_indirect(),
}
}
}
pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec + HasS390xVector,
{
let abi = if cx.has_s390x_vector() { Vector } else { NoVector };
if !fn_abi.ret.is_ignore() {
classify_ret(cx, &mut fn_abi.ret, abi);
}
for arg in fn_abi.args.iter_mut() {
classify_arg(cx, arg, abi);
}
}