cranelift_codegen::ir::types

Struct Type

Source
pub struct Type(/* private fields */);
Expand description

The type of an SSA value.

The INVALID type isn’t a real type, and is used as a placeholder in the IR where a type field is present put no type is needed, such as the controlling type variable for a non-polymorphic instruction.

Basic integer types: I8, I16, I32, I64, and I128. These types are sign-agnostic.

Basic floating point types: F16, F32, F64, and F128. IEEE half, single, double, and quadruple precision.

SIMD vector types have power-of-two lanes, up to 256. Lanes can be any int/float type.

Note that this is encoded in a u16 currently for extensibility, but allows only 14 bits to be used due to some bitpacking tricks in the CLIF data structures.

Implementations§

Source§

impl Type

Source

pub fn lane_type(self) -> Self

Get the lane type of this SIMD vector type.

A lane type is the same as a SIMD vector type with one lane, so it returns itself.

Source

pub fn lane_of(self) -> Self

The type transformation that returns the lane type of a type variable; it is just a renaming of lane_type() to be used in context where we think in terms of type variable transformations.

Source

pub fn log2_lane_bits(self) -> u32

Get log_2 of the number of bits in a lane.

Source

pub fn lane_bits(self) -> u32

Get the number of bits in a lane.

Source

pub fn bounds(self, signed: bool) -> (u128, u128)

Get the (minimum, maximum) values represented by each lane in the type. Note that these are returned as unsigned ‘bit patterns’.

Source

pub fn int(bits: u16) -> Option<Self>

Get an integer type with the requested number of bits.

For the same thing but in bytes, use Self::int_with_byte_size.

Source

pub fn int_with_byte_size(bytes: u16) -> Option<Self>

Get an integer type with the requested number of bytes.

For the same thing but in bits, use Self::int.

Source

pub fn as_truthy_pedantic(self) -> Self

Get a type with the same number of lanes as this type, but with the lanes replaced by booleans of the same size.

Lane types are treated as vectors with one lane, so they are converted to the multi-bit boolean types.

Source

pub fn as_truthy(self) -> Self

Get the type of a comparison result for the given type. For vectors this will be a vector with the same number of lanes and integer elements, and for scalar types this will be i8, which is the result type of comparisons.

Source

pub fn as_int(self) -> Self

Get a type with the same number of lanes as this type, but with the lanes replaced by integers of the same size.

Source

pub fn half_width(self) -> Option<Self>

Get a type with the same number of lanes as this type, but with lanes that are half the number of bits.

Source

pub fn double_width(self) -> Option<Self>

Get a type with the same number of lanes as this type, but with lanes that are twice the number of bits.

Source

pub fn is_invalid(self) -> bool

Is this the INVALID type?

Source

pub fn is_special(self) -> bool

Is this a special type?

Source

pub fn is_lane(self) -> bool

Is this a lane type?

This is a scalar type that can also appear as the lane type of a SIMD vector.

Source

pub fn is_vector(self) -> bool

Is this a SIMD vector type?

A vector type has 2 or more lanes.

Source

pub fn is_dynamic_vector(self) -> bool

Is this a SIMD vector type with a runtime number of lanes?

Source

pub fn is_int(self) -> bool

Is this a scalar integer type?

Source

pub fn is_float(self) -> bool

Is this a scalar floating point type?

Source

pub fn is_ref(self) -> bool

Is this a ref type?

Source

pub fn log2_lane_count(self) -> u32

Get log_2 of the number of lanes in this SIMD vector type.

All SIMD types have a lane count that is a power of two and no larger than 256, so this will be a number in the range 0-8.

A scalar type is the same as a SIMD vector type with one lane, so it returns 0.

Source

pub fn log2_min_lane_count(self) -> u32

Get log_2 of the number of lanes in this vector/dynamic type.

Source

pub fn lane_count(self) -> u32

Get the number of lanes in this SIMD vector type.

A scalar type is the same as a SIMD vector type with one lane, so it returns 1.

Source

pub fn bits(self) -> u32

Get the total number of bits used to represent this type.

Source

pub fn min_lane_count(self) -> u32

Get the minimum of lanes in this SIMD vector type, this supports both fixed and dynamic types.

Source

pub fn min_bits(self) -> u32

Get the minimum number of bits used to represent this type.

Source

pub fn bytes(self) -> u32

Get the number of bytes used to store this type in memory.

Source

pub fn by(self, n: u32) -> Option<Self>

Get a SIMD vector type with n times more lanes than this one.

If this is a scalar type, this produces a SIMD type with this as a lane type and n lanes.

If this is already a SIMD vector type, this produces a SIMD vector type with n * self.lane_count() lanes.

Source

pub fn vector_to_dynamic(self) -> Option<Self>

Convert a fixed vector type to a dynamic one.

Source

pub fn dynamic_to_vector(self) -> Option<Self>

Convert a dynamic vector type to a fixed one.

Source

pub fn split_lanes(self) -> Option<Self>

Split the lane width in half and double the number of lanes to maintain the same bit-width.

If this is a scalar type of n bits, it produces a SIMD vector type of (n/2)x2.

Source

pub fn merge_lanes(self) -> Option<Self>

Merge lanes to half the number of lanes and double the lane width to maintain the same bit-width.

If this is a scalar type, it will return None.

Source

pub fn index(self) -> usize

Index of this type, for use with hash tables etc.

Source

pub fn wider_or_equal(self, other: Self) -> bool

True iff:

  1. self.lane_count() == other.lane_count() and
  2. self.lane_bits() >= other.lane_bits()
Source

pub fn triple_pointer_type(triple: &Triple) -> Self

Return the pointer type for the given target triple.

Trait Implementations§

Source§

impl Clone for Type

Source§

fn clone(&self) -> Type

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Type

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Type

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Type

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Type

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Type

Source§

fn eq(&self, other: &Type) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for Type

Source§

impl Eq for Type

Source§

impl StructuralPartialEq for Type

Auto Trait Implementations§

§

impl Freeze for Type

§

impl RefUnwindSafe for Type

§

impl Send for Type

§

impl Sync for Type

§

impl Unpin for Type

§

impl UnwindSafe for Type

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.