MLIR

Multi-Level IR Compiler Framework

'ptr' Dialect

Pointer dialect

Operations 

source

ptr.ptr_add (ptr::PtrAddOp) 

Pointer add operation

Syntax:

operation ::= `ptr.ptr_add` ($flags^)? $base `,` $offset attr-dict `:` type($base) `,` type($offset)

The ptr_add operation adds an integer offset to a pointer to produce a new pointer. The input and output pointer types are always the same.

Example:

%x_off  = ptr.ptr_add %x, %off : !ptr.ptr<0>, i32
%x_off0 = ptr.ptr_add nusw %x, %off : !ptr.ptr<0>, i32

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), ViewLikeOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
basepointer type
offsetsignless integer or index

Results: 

ResultDescription
resultpointer type

ptr.type_offset (ptr::TypeOffsetOp) 

Type offset operation

Syntax:

operation ::= `ptr.type_offset` $elementType attr-dict `:` type($result)

The type_offset operation produces an int or index-typed SSA value equal to a target-specific constant representing the offset of a single element of the given type.

Example:

// Return the offset between two f32 stored in memory
%0 = ptr.type_offset f32 : index
// Return the offset between two memref descriptors stored in memory
%1 = ptr.type_offset memref<12 x f64> : i32

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Attributes: 

AttributeMLIR TypeDescription
elementType::mlir::TypeAttrany type attribute

Results: 

ResultDescription
resultsignless integer or index

Attributes 

GenericSpaceAttr 

Generic memory space

Syntax: #ptr.generic_space

The generic_space attribute defines a memory space attribute with the following properties:

  • Load and store operations are always valid, regardless of the type.
  • Atomic operations are always valid, regardless of the type.
  • Cast operations to generic_space are always valid.

Example:

#ptr.generic_space

SpecAttr 

Ptr data layout spec

Syntax:

#ptr.spec<
  uint32_t,   # size
  uint32_t,   # abi
  uint32_t,   # preferred
  uint32_t   # index
>

Defines the data layout spec for a pointer type. This attribute has 4 fields:

  • [Required] size: size of the pointer in bits.
  • [Required] abi: ABI-required alignment for the pointer in bits.
  • [Required] preferred: preferred alignment for the pointer in bits.
  • [Optional] index: bitwidth that should be used when performing index computations for the type. Setting the field to kOptionalSpecValue, means the field is optional.

Furthermore, the attribute will verify that all present values are divisible by 8 (number of bits in a byte), and that preferred > abi.

Example:

// Spec for a 64 bit ptr, with a required alignment of 64 bits, but with
// a preferred alignment of 128 bits and an index bitwidth of 64 bits.
#ptr.spec<size = 64, abi = 64, preferred = 128, index = 64>

Parameters: 

ParameterC++ typeDescription
sizeuint32_t
abiuint32_t
preferreduint32_t
indexuint32_t

Types 

PtrType 

Pointer type

Syntax:

!ptr.ptr<
  MemorySpaceAttrInterface   # memorySpace
>

The ptr type is an opaque pointer type. This type typically represents a handle to an object in memory or target-dependent values like nullptr. Pointers are parameterized by a memory space.

Syntax:

pointer ::= `ptr` (`<` memory-space `>`)?
memory-space ::= attribute-value

Parameters: 

ParameterC++ typeDescription
memorySpaceMemorySpaceAttrInterface

Enums 

AtomicBinOp 

Ptr.atomicrmw binary operations

Cases: 

SymbolValueString
xchg0xchg
add1add
sub2sub
_and3_and
nand4nand
_or5_or
_xor6_xor
max7max
min8min
umax9umax
umin10umin
fadd11fadd
fsub12fsub
fmax13fmax
fmin14fmin
uinc_wrap15uinc_wrap
udec_wrap16udec_wrap

AtomicOrdering 

Atomic ordering for LLVM’s memory model

Cases: 

SymbolValueString
not_atomic0not_atomic
unordered1unordered
monotonic2monotonic
acquire3acquire
release4release
acq_rel5acq_rel
seq_cst6seq_cst

PtrAddFlags 

Pointer add flags

Cases: 

SymbolValueString
none0none
nusw1nusw
nuw2nuw
inbounds3inbounds

OSZAR »