Make abi::Abi
Copy
and remove a *lot* of refs
fix fix Remove more refs and clones fix more fix
This commit is contained in:
parent
86ff6aeb82
commit
5b2f757dae
33 changed files with 139 additions and 163 deletions
|
@ -3,7 +3,7 @@ use crate::abi::{self, HasDataLayout, Size, TyAbiInterface};
|
|||
|
||||
fn extend_integer_width_mips<Ty>(arg: &mut ArgAbi<'_, Ty>, bits: u64) {
|
||||
// Always sign extend u32 values on 64-bit mips
|
||||
if let abi::Abi::Scalar(ref scalar) = arg.layout.abi {
|
||||
if let abi::Abi::Scalar(scalar) = arg.layout.abi {
|
||||
if let abi::Int(i, signed) = scalar.value {
|
||||
if !signed && i.size().bits() == 32 {
|
||||
if let PassMode::Direct(ref mut attrs) = arg.mode {
|
||||
|
@ -23,7 +23,7 @@ where
|
|||
C: HasDataLayout,
|
||||
{
|
||||
match ret.layout.field(cx, i).abi {
|
||||
abi::Abi::Scalar(ref scalar) => match scalar.value {
|
||||
abi::Abi::Scalar(scalar) => match scalar.value {
|
||||
abi::F32 => Some(Reg::f32()),
|
||||
abi::F64 => Some(Reg::f64()),
|
||||
_ => None,
|
||||
|
@ -107,7 +107,7 @@ where
|
|||
let offset = arg.layout.fields.offset(i);
|
||||
|
||||
// We only care about aligned doubles
|
||||
if let abi::Abi::Scalar(ref scalar) = field.abi {
|
||||
if let abi::Abi::Scalar(scalar) = field.abi {
|
||||
if let abi::F64 = scalar.value {
|
||||
if offset.is_aligned(dl.f64_align.abi) {
|
||||
// Insert enough integers to cover [last_offset, offset)
|
||||
|
|
|
@ -322,7 +322,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
|||
Abi::Uninhabited => Err(Heterogeneous),
|
||||
|
||||
// The primitive for this algorithm.
|
||||
Abi::Scalar(ref scalar) => {
|
||||
Abi::Scalar(scalar) => {
|
||||
let kind = match scalar.value {
|
||||
abi::Int(..) | abi::Pointer => RegKind::Integer,
|
||||
abi::F32 | abi::F64 => RegKind::Float,
|
||||
|
@ -450,9 +450,9 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
|
|||
pub fn new(
|
||||
cx: &impl HasDataLayout,
|
||||
layout: TyAndLayout<'a, Ty>,
|
||||
scalar_attrs: impl Fn(&TyAndLayout<'a, Ty>, &abi::Scalar, Size) -> ArgAttributes,
|
||||
scalar_attrs: impl Fn(&TyAndLayout<'a, Ty>, abi::Scalar, Size) -> ArgAttributes,
|
||||
) -> Self {
|
||||
let mode = match &layout.abi {
|
||||
let mode = match layout.abi {
|
||||
Abi::Uninhabited => PassMode::Ignore,
|
||||
Abi::Scalar(scalar) => PassMode::Direct(scalar_attrs(&layout, scalar, Size::ZERO)),
|
||||
Abi::ScalarPair(a, b) => PassMode::Pair(
|
||||
|
@ -504,7 +504,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
|
|||
|
||||
pub fn extend_integer_width_to(&mut self, bits: u64) {
|
||||
// Only integers have signedness
|
||||
if let Abi::Scalar(ref scalar) = self.layout.abi {
|
||||
if let Abi::Scalar(scalar) = self.layout.abi {
|
||||
if let abi::Int(i, signed) = scalar.value {
|
||||
if i.size().bits() < bits {
|
||||
if let PassMode::Direct(ref mut attrs) = self.mode {
|
||||
|
|
|
@ -44,7 +44,7 @@ where
|
|||
Ty: TyAbiInterface<'a, C> + Copy,
|
||||
{
|
||||
match arg_layout.abi {
|
||||
Abi::Scalar(ref scalar) => match scalar.value {
|
||||
Abi::Scalar(scalar) => match scalar.value {
|
||||
abi::Int(..) | abi::Pointer => {
|
||||
if arg_layout.size.bits() > xlen {
|
||||
return Err(CannotUseFpConv);
|
||||
|
@ -297,7 +297,7 @@ fn classify_arg<'a, Ty, C>(
|
|||
}
|
||||
|
||||
fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) {
|
||||
if let Abi::Scalar(ref scalar) = arg.layout.abi {
|
||||
if let Abi::Scalar(scalar) = arg.layout.abi {
|
||||
if let abi::Int(i, _) = scalar.value {
|
||||
// 32-bit integers are always sign-extended
|
||||
if i.size().bits() == 32 && xlen > 32 {
|
||||
|
|
|
@ -18,7 +18,7 @@ where
|
|||
C: HasDataLayout,
|
||||
{
|
||||
match layout.abi {
|
||||
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Aggregate { .. } => {
|
||||
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
|
||||
is_single_fp_element(cx, layout.field(cx, 0))
|
||||
|
|
|
@ -14,7 +14,7 @@ where
|
|||
C: HasDataLayout,
|
||||
{
|
||||
match layout.abi {
|
||||
abi::Abi::Scalar(ref scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Scalar(scalar) => scalar.value.is_float(),
|
||||
abi::Abi::Aggregate { .. } => {
|
||||
if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 {
|
||||
is_single_fp_element(cx, layout.field(cx, 0))
|
||||
|
|
|
@ -49,7 +49,7 @@ where
|
|||
let mut c = match layout.abi {
|
||||
Abi::Uninhabited => return Ok(()),
|
||||
|
||||
Abi::Scalar(ref scalar) => match scalar.value {
|
||||
Abi::Scalar(scalar) => match scalar.value {
|
||||
abi::Int(..) | abi::Pointer => Class::Int,
|
||||
abi::F32 | abi::F64 => Class::Sse,
|
||||
},
|
||||
|
|
|
@ -955,7 +955,7 @@ impl AddressSpace {
|
|||
|
||||
/// Describes how values of the type are passed by target ABIs,
|
||||
/// in terms of categories of C types there are ABI rules for.
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
pub enum Abi {
|
||||
Uninhabited,
|
||||
Scalar(Scalar),
|
||||
|
@ -983,8 +983,8 @@ impl Abi {
|
|||
/// Returns `true` if this is a single signed integer scalar
|
||||
#[inline]
|
||||
pub fn is_signed(&self) -> bool {
|
||||
match *self {
|
||||
Abi::Scalar(ref scal) => match scal.value {
|
||||
match self {
|
||||
Abi::Scalar(scal) => match scal.value {
|
||||
Primitive::Int(_, signed) => signed,
|
||||
_ => false,
|
||||
},
|
||||
|
@ -1053,7 +1053,7 @@ pub enum TagEncoding {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)]
|
||||
pub struct Niche {
|
||||
pub offset: Size,
|
||||
pub scalar: Scalar,
|
||||
|
@ -1259,7 +1259,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
|||
Ty: TyAbiInterface<'a, C>,
|
||||
C: HasDataLayout,
|
||||
{
|
||||
let scalar_allows_raw_init = move |s: &Scalar| -> bool {
|
||||
let scalar_allows_raw_init = move |s: Scalar| -> bool {
|
||||
if zero {
|
||||
// The range must contain 0.
|
||||
s.valid_range.contains(0)
|
||||
|
@ -1270,11 +1270,11 @@ impl<'a, Ty> TyAndLayout<'a, Ty> {
|
|||
};
|
||||
|
||||
// Check the ABI.
|
||||
let valid = match &self.abi {
|
||||
let valid = match self.abi {
|
||||
Abi::Uninhabited => false, // definitely UB
|
||||
Abi::Scalar(s) => scalar_allows_raw_init(s),
|
||||
Abi::ScalarPair(s1, s2) => scalar_allows_raw_init(s1) && scalar_allows_raw_init(s2),
|
||||
Abi::Vector { element: s, count } => *count == 0 || scalar_allows_raw_init(s),
|
||||
Abi::Vector { element: s, count } => count == 0 || scalar_allows_raw_init(s),
|
||||
Abi::Aggregate { .. } => true, // Fields are checked below.
|
||||
};
|
||||
if !valid {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue