pub struct ReallocOperation<'c> { /* private fields */ }
Expand description
A realloc
operation. Memory reallocation operation.
The realloc
operation changes the size of a memory region. The memory
region is specified by a 1D source memref and the size of the new memory
region is specified by a 1D result memref type and an optional dynamic Value
of Index
type. The source and the result memref must be in the same memory
space and have the same element type.
The operation may move the memory region to a new location. In this case, the content of the memory block is preserved up to the lesser of the new and old sizes. If the new size if larger, the value of the extended memory is undefined. This is consistent with the ISO C realloc.
The operation returns an SSA value for the memref.
Example:
%0 = memref.realloc %src : memref<64xf32> to memref<124xf32>
The source memref may have a dynamic shape, in which case, the compiler will generate code to extract its size from the runtime data structure for the memref.
%1 = memref.realloc %src : memref<?xf32> to memref<124xf32>
If the result memref has a dynamic shape, a result dimension operand is needed to spefify its dynamic dimension. In the example below, the ssa value ‘%d’ specifies the unknown dimension of the result memref.
%2 = memref.realloc %src(%d) : memref<?xf32> to memref<?xf32>
An optional alignment
attribute may be specified to ensure that the
region of memory that will be indexed is aligned at the specified byte
boundary. This is consistent with the fact that memref.alloc supports such
an optional alignment attribute. Note that in ISO C standard, neither alloc
nor realloc supports alignment, though there is aligned_alloc but not
aligned_realloc.
%3 = memref.realloc %src {alignment = 8} : memref<64xf32> to memref<124xf32>
Referencing the memref through the old SSA value after realloc is undefined behavior.
%new = memref.realloc %old : memref<64xf32> to memref<124xf32>
%4 = memref.load %new[%index] // ok
%5 = memref.load %old[%index] // undefined behavior
Implementations§
source§impl<'c> ReallocOperation<'c>
impl<'c> ReallocOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> ReallocOperationBuilder<'c, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> ReallocOperationBuilder<'c, Unset>
Creates a builder.