Add support to new float types

This commit is contained in:
Celina G. Val 2024-03-01 11:16:35 -08:00
parent e3ac2c68b8
commit 0567162933
2 changed files with 31 additions and 8 deletions

View File

@ -6,8 +6,9 @@ use crate::rustc_smir::{Stable, Tables};
use rustc_middle::ty;
use rustc_target::abi::call::Conv;
use stable_mir::abi::{
AddressSpace, ArgAbi, CallConvention, FieldsShape, FnAbi, IntegerLength, Layout, LayoutShape,
PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape, WrappingRange,
AddressSpace, ArgAbi, CallConvention, FieldsShape, FloatLength, FnAbi, IntegerLength, Layout,
LayoutShape, PassMode, Primitive, Scalar, TagEncoding, TyAndLayout, ValueAbi, VariantsShape,
WrappingRange,
};
use stable_mir::opaque;
use stable_mir::target::MachineSize as Size;
@ -255,8 +256,10 @@ impl<'tcx> Stable<'tcx> for rustc_abi::Primitive {
rustc_abi::Primitive::Int(length, signed) => {
Primitive::Int { length: length.stable(tables), signed: *signed }
}
rustc_abi::Primitive::F32 => Primitive::F32,
rustc_abi::Primitive::F64 => Primitive::F64,
rustc_abi::Primitive::F16 => Primitive::Float { length: FloatLength::F16 },
rustc_abi::Primitive::F32 => Primitive::Float { length: FloatLength::F32 },
rustc_abi::Primitive::F64 => Primitive::Float { length: FloatLength::F64 },
rustc_abi::Primitive::F128 => Primitive::Float { length: FloatLength::F128 },
rustc_abi::Primitive::Pointer(space) => Primitive::Pointer(space.stable(tables)),
}
}

View File

@ -293,8 +293,9 @@ pub enum Primitive {
length: IntegerLength,
signed: bool,
},
F32,
F64,
Float {
length: FloatLength,
},
Pointer(AddressSpace),
}
@ -302,8 +303,7 @@ impl Primitive {
pub fn size(self, target: &MachineInfo) -> Size {
match self {
Primitive::Int { length, .. } => Size::from_bits(length.bits()),
Primitive::F32 => Size::from_bits(32),
Primitive::F64 => Size::from_bits(64),
Primitive::Float { length } => Size::from_bits(length.bits()),
Primitive::Pointer(_) => target.pointer_width,
}
}
@ -319,6 +319,15 @@ pub enum IntegerLength {
I128,
}
/// Enum representing the existing float lengths.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum FloatLength {
F16,
F32,
F64,
F128,
}
impl IntegerLength {
pub fn bits(self) -> usize {
match self {
@ -331,6 +340,17 @@ impl IntegerLength {
}
}
impl FloatLength {
pub fn bits(self) -> usize {
match self {
FloatLength::F16 => 16,
FloatLength::F32 => 32,
FloatLength::F64 => 64,
FloatLength::F128 => 128,
}
}
}
/// An identifier that specifies the address space that some operation
/// should operate on. Special address spaces have an effect on code generation,
/// depending on the target and the address spaces it implements.