Struct cranelift_codegen::ir::MemFlags
source · 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
impl MemFlags
sourcepub fn trusted() -> Self
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.
sourcepub fn set_by_name(&mut self, name: &str) -> bool
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.
sourcepub fn endianness(self, native_endianness: Endianness) -> Endianness
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.
sourcepub fn set_endianness(&mut self, endianness: Endianness)
pub fn set_endianness(&mut self, endianness: Endianness)
Set endianness of the memory access.
sourcepub fn with_endianness(self, endianness: Endianness) -> Self
pub fn with_endianness(self, endianness: Endianness) -> Self
Set endianness of the memory access, returning new flags.
sourcepub fn notrap(self) -> bool
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.
sourcepub fn set_notrap(&mut self)
pub fn set_notrap(&mut self)
Set the notrap
flag.
sourcepub fn with_notrap(self) -> Self
pub fn with_notrap(self) -> Self
Set the notrap
flag, returning new flags.
sourcepub fn aligned(self) -> bool
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.
sourcepub fn set_aligned(&mut self)
pub fn set_aligned(&mut self)
Set the aligned
flag.
sourcepub fn with_aligned(self) -> Self
pub fn with_aligned(self) -> Self
Set the aligned
flag, returning new flags.
sourcepub fn readonly(self) -> bool
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.
sourcepub fn set_readonly(&mut self)
pub fn set_readonly(&mut self)
Set the readonly
flag.
sourcepub fn with_readonly(self) -> Self
pub fn with_readonly(self) -> Self
Set the readonly
flag, returning new flags.
sourcepub fn heap(self) -> bool
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.
sourcepub fn set_heap(&mut self)
pub fn set_heap(&mut self)
Set the heap
bit. See the notes about mutual exclusion with
other bits in heap()
.
sourcepub fn table(self) -> bool
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.
sourcepub fn set_table(&mut self)
pub fn set_table(&mut self)
Set the table
bit. See the notes about mutual exclusion with
other bits in table()
.
sourcepub fn with_table(self) -> Self
pub fn with_table(self) -> Self
Set the table
bit, returning new flags.
sourcepub fn vmctx(self) -> bool
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.
sourcepub fn set_vmctx(&mut self)
pub fn set_vmctx(&mut self)
Set the vmctx
bit. See the notes about mutual exclusion with
other bits in vmctx()
.
sourcepub fn with_vmctx(self) -> Self
pub fn with_vmctx(self) -> Self
Set the vmctx
bit, returning new flags.
Trait Implementations§
source§impl PartialEq for MemFlags
impl PartialEq for MemFlags
impl Copy for MemFlags
impl Eq for MemFlags
impl StructuralPartialEq for MemFlags
Auto Trait Implementations§
impl Freeze for MemFlags
impl RefUnwindSafe for MemFlags
impl Send for MemFlags
impl Sync for MemFlags
impl Unpin for MemFlags
impl UnwindSafe for MemFlags
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.