# MLIR

Multi-Level IR Compiler Framework

# 'bufferization' Dialect

Bufferization in MLIR is the process of converting the tensor type to the memref type. The bufferization dialect is intended to collect operations/interfaces specific to the bufferization passes.

Overview of the bufferization infrastructure and important conceptual details related to using the MLIR dialect conversion infrastructure can be found in bufferization and buffer deallocation .

## Operation definition ¶

### bufferization.clone (::mlir::bufferization::CloneOp) ¶

Syntax:

operation ::= bufferization.clone $input attr-dict : type($input) to type($output)  Clones the data in the input view into an implicitly defined output view. Usage: %arg1 = bufferization.clone %arg0 : memref<?xf32> to memref<?xf32>  Valid implementations of this operation may alias the input and output views or create an actual copy. Mutating the source or result of the clone operation after the clone operation thus leads to undefined behavior. Interfaces: AllocationOpInterface, CopyOpInterface, MemoryEffectOpInterface #### Operands: ¶ OperandDescription inputunranked.memref of any type values or memref of any type values #### Results: ¶ ResultDescription outputunranked.memref of any type values or memref of any type values ### bufferization.to_memref (::mlir::bufferization::ToMemrefOp) ¶ tensor to memref cast operation Syntax: operation ::= bufferization.to_memref$tensor attr-dict : type($memref)  Casts a tensor to a memref. // Result type is tensor<4x?xf32> %12 = bufferization.to_memref %10 : memref<4x?xf32, #map0, 42>  Note, that mutating the result of the to_buffer operation leads to undefined behavior. This operation is a specialized variant of the built-in unrealized_conversion_cast and is intended for use in the context of gradual bufferization. Traits: SameOperandsAndResultElementType, SameOperandsAndResultShape Interfaces: NoSideEffect (MemoryEffectOpInterface) Effects: MemoryEffects::Effect{} #### Operands: ¶ OperandDescription tensortensor of any type values #### Results: ¶ ResultDescription memrefunranked.memref of any type values or memref of any type values ### bufferization.to_tensor (::mlir::bufferization::ToTensorOp) ¶ memref to tensor operation Syntax: operation ::= bufferization.to_tensor$memref attr-dict : type(\$memref)


Create a tensor from a memref, making an independent copy of the element data. The result value is a tensor whose shape and element type match the memref operand.

The opposite of this op is to_memref. Together, these two ops are useful for source/target materializations when doing type conversions involving tensors and memrefs.

Example:

// Produces a value of tensor<4x?xf32> type.
%12 = bufferization.to_tensor %10 : memref<4x?xf32, #layout, memspace0>


Traits: SameOperandsAndResultElementType, SameOperandsAndResultShape

#### Operands: ¶

OperandDescription
memrefunranked.memref of any type values or memref of any type values

#### Results: ¶

ResultDescription
resulttensor of any type values