pub struct MemFlags { /* private fields */ }
Expand description

Flags for memory operations like load/store.

Each of these flags introduce a limited form of undefined behavior. The flags each enable certain optimizations that need to make additional assumptions. Generally, the semantics of a program does not change when a flag is removed, but adding a flag will.

In addition, the flags determine the endianness of the memory access. By default, any memory access uses the native endianness determined by the target ISA. This can be overridden for individual accesses by explicitly specifying little- or big-endian semantics via the flags.

Implementations§

source§

impl MemFlags

source

pub fn new() -> Self

Create a new empty set of flags.

source

pub fn trusted() -> Self

Create a set of flags representing an access from a “trusted” address, meaning it’s known to be aligned and non-trapping.

source

pub fn set_by_name(&mut self, name: &str) -> bool

Set a flag bit by name.

Returns true if the flag was found and set, false for an unknown flag name. Will also return false when trying to set inconsistent endianness flags.

source

pub fn endianness(self, native_endianness: Endianness) -> Endianness

Return endianness of the memory access. This will return the endianness explicitly specified by the flags if any, and will default to the native endianness otherwise. The native endianness has to be provided by the caller since it is not explicitly encoded in CLIF IR – this allows a front end to create IR without having to know the target endianness.

source

pub fn set_endianness(&mut self, endianness: Endianness)

Set endianness of the memory access.

source

pub fn with_endianness(self, endianness: Endianness) -> Self

Set endianness of the memory access, returning new flags.

source

pub fn notrap(self) -> bool

Test if the notrap flag is set.

Normally, trapping is part of the semantics of a load/store operation. If the platform would cause a trap when accessing the effective address, the Cranelift memory operation is also required to trap.

The notrap flag tells Cranelift that the memory is accessible, which means that accesses will not trap. This makes it possible to delete an unused load or a dead store instruction.

source

pub fn set_notrap(&mut self)

Set the notrap flag.

source

pub fn with_notrap(self) -> Self

Set the notrap flag, returning new flags.

source

pub fn aligned(self) -> bool

Test if the aligned flag is set.

By default, Cranelift memory instructions work with any unaligned effective address. If the aligned flag is set, the instruction is permitted to trap or return a wrong result if the effective address is misaligned.

source

pub fn set_aligned(&mut self)

Set the aligned flag.

source

pub fn with_aligned(self) -> Self

Set the aligned flag, returning new flags.

source

pub fn readonly(self) -> bool

Test if the readonly flag is set.

Loads with this flag have no memory dependencies. This results in undefined behavior if the dereferenced memory is mutated at any time between when the function is called and when it is exited.

source

pub fn set_readonly(&mut self)

Set the readonly flag.

source

pub fn with_readonly(self) -> Self

Set the readonly flag, returning new flags.

source

pub fn heap(self) -> bool

Test if the heap bit is set.

Loads and stores with this flag accesses the “heap” part of abstract state. This is disjoint from the “table”, “vmctx”, and “other” parts of abstract state. In concrete terms, this means that behavior is undefined if the same memory is also accessed by another load/store with one of the other alias-analysis bits (table, vmctx) set, or heap not set.

source

pub fn set_heap(&mut self)

Set the heap bit. See the notes about mutual exclusion with other bits in heap().

source

pub fn with_heap(self) -> Self

Set the heap bit, returning new flags.

source

pub fn table(self) -> bool

Test if the table bit is set.

Loads and stores with this flag accesses the “table” part of abstract state. This is disjoint from the “heap”, “vmctx”, and “other” parts of abstract state. In concrete terms, this means that behavior is undefined if the same memory is also accessed by another load/store with one of the other alias-analysis bits (heap, vmctx) set, or table not set.

source

pub fn set_table(&mut self)

Set the table bit. See the notes about mutual exclusion with other bits in table().

source

pub fn with_table(self) -> Self

Set the table bit, returning new flags.

source

pub fn vmctx(self) -> bool

Test if the vmctx bit is set.

Loads and stores with this flag accesses the “vmctx” part of abstract state. This is disjoint from the “heap”, “table”, and “other” parts of abstract state. In concrete terms, this means that behavior is undefined if the same memory is also accessed by another load/store with one of the other alias-analysis bits (heap, table) set, or vmctx not set.

source

pub fn set_vmctx(&mut self)

Set the vmctx bit. See the notes about mutual exclusion with other bits in vmctx().

source

pub fn with_vmctx(self) -> Self

Set the vmctx bit, returning new flags.

Trait Implementations§

source§

impl Clone for MemFlags

source§

fn clone(&self) -> MemFlags

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 MemFlags

source§

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

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

impl Display for MemFlags

source§

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

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

impl Hash for MemFlags

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<MemFlags> for MemFlags

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for MemFlags

source§

impl Eq for MemFlags

source§

impl StructuralEq for MemFlags

source§

impl StructuralPartialEq for MemFlags

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere 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 Qwhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.