MLIR 22.0.0git
mlir::spirv::StructType Class Reference

SPIR-V struct type. More...

#include "mlir/Dialect/SPIRV/IR/SPIRVTypes.h"

Inheritance diagram for mlir::spirv::StructType:

Classes

struct  MemberDecorationInfo
struct  StructDecorationInfo

Public Types

using OffsetInfo = uint32_t
Public Types inherited from mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
using Base
 Utility declarations for the concrete attribute class.
using ImplType
using HasTraitFn

Public Member Functions

StringRef getIdentifier () const
 For literal structs, return an empty string.
bool isIdentified () const
 Returns true if the StructType is identified.
unsigned getNumElements () const
Type getElementType (unsigned) const
TypeRange getElementTypes () const
bool hasOffset () const
bool hasDecoration (spirv::Decoration decoration) const
 Returns true if the struct has a specified decoration.
uint64_t getMemberOffset (unsigned) const
void getMemberDecorations (SmallVectorImpl< StructType::MemberDecorationInfo > &memberDecorations) const
void getMemberDecorations (unsigned i, SmallVectorImpl< StructType::MemberDecorationInfo > &decorationsInfo) const
void getStructDecorations (SmallVectorImpl< StructType::StructDecorationInfo > &structDecorations) const
LogicalResult trySetBody (ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={}, ArrayRef< StructDecorationInfo > structDecorations={})
 Sets the contents of an incomplete identified StructType.
Public Member Functions inherited from mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
ImplTypegetImpl () const
 Utility for easy access to the storage instance.

Static Public Member Functions

static StructType get (ArrayRef< Type > memberTypes, ArrayRef< OffsetInfo > offsetInfo={}, ArrayRef< MemberDecorationInfo > memberDecorations={}, ArrayRef< StructDecorationInfo > structDecorations={})
 Construct a literal StructType with at least one member.
static StructType getIdentified (MLIRContext *context, StringRef identifier)
 Construct an identified StructType.
static StructType getEmpty (MLIRContext *context, StringRef identifier="")
 Construct a (possibly identified) StructType with no members.
Static Public Member Functions inherited from mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
static TypeID getTypeID ()
 Return a unique identifier for the concrete type.
static bool classof (T val)
 Provide an implementation of 'classof' that compares the type id of the provided value with that of the concrete type.
static detail::InterfaceMap getInterfaceMap ()
 Returns an interface map for the interfaces registered to this storage user.
static HasTraitFn getHasTraitFn ()
 Returns the function that returns true if the given Trait ID matches the IDs of any of the traits defined by the storage user.
static auto getWalkImmediateSubElementsFn ()
 Returns a function that walks immediate sub elements of a given instance of the storage user.
static auto getReplaceImmediateSubElementsFn ()
 Returns a function that replaces immediate sub elements of a given instance of the storage user.
static void attachInterface (MLIRContext &context)
 Attach the given models as implementations of the corresponding interfaces for the concrete storage user class.
static ConcreteType get (MLIRContext *ctx, Args &&...args)
 Get or create a new ConcreteT instance within the ctx.
static ConcreteType getChecked (const Location &loc, Args &&...args)
 Get or create a new ConcreteT instance within the ctx, defined at the given, potentially unknown, location.
static ConcreteType getChecked (function_ref< InFlightDiagnostic()> emitErrorFn, MLIRContext *ctx, Args... args)
 Get or create a new ConcreteT instance within the ctx.
static ConcreteType getFromOpaquePointer (const void *ptr)
 Get an instance of the concrete type from a void pointer.

Static Public Attributes

static constexpr StringLiteral name = "spirv.struct"

Additional Inherited Members

Protected Member Functions inherited from mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
LogicalResult mutate (Args &&...args)
 Mutate the current storage instance.
Static Protected Member Functions inherited from mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
static LogicalResult verifyInvariants (Args... args)
 Default implementation that just returns success.

Detailed Description

SPIR-V struct type.

Two kinds of struct types are supported:

  • Literal: a literal struct type is uniqued by its fields (types + offset info + decoration info).
  • Identified: an indentified struct type is uniqued by its string identifier (name). This is useful in representing recursive structs. For example, the following C struct:

struct A { A* next; };

would be represented in MLIR as:

!spirv.struct<A, (!spirv.ptr<!spirv.struct, Generic>)>

In the above, expressing recursive struct types is accomplished by giving a recursive struct a unique identified and using that identifier in the struct definition for recursive references.

Definition at line 249 of file SPIRVTypes.h.

Member Typedef Documentation

◆ OffsetInfo

Definition at line 256 of file SPIRVTypes.h.

Member Function Documentation

◆ get()

StructType StructType::get ( ArrayRef< Type > memberTypes,
ArrayRef< OffsetInfo > offsetInfo = {},
ArrayRef< MemberDecorationInfo > memberDecorations = {},
ArrayRef< StructDecorationInfo > structDecorations = {} )
static

◆ getElementType()

Type StructType::getElementType ( unsigned index) const

◆ getElementTypes()

◆ getEmpty()

StructType StructType::getEmpty ( MLIRContext * context,
StringRef identifier = "" )
static

Construct a (possibly identified) StructType with no members.

Note: this method might fail in a multi-threaded setup if another thread created an identified struct with the same identifier but with different contents before returning. In which case, an empty (default-constructed) StructType is returned.

Definition at line 1045 of file SPIRVTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >::get(), isIdentified(), and trySetBody().

Referenced by parseStructType(), and mlir::spirv::Deserializer::processStructType().

◆ getIdentified()

StructType StructType::getIdentified ( MLIRContext * context,
StringRef identifier )
static

Construct an identified StructType.

This creates a StructType whose body (member types, offset info, and decorations) is not set yet. A call to StructType::trySetBody(...) must follow when the StructType contents are available (e.g. parsed or deserialized).

Note: If another thread creates (or had already created) a struct with the same identifier, that struct will be returned as a result.

Definition at line 1034 of file SPIRVTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >::get().

Referenced by parseStructType(), and mlir::spirv::Deserializer::processStructType().

◆ getIdentifier()

StringRef StructType::getIdentifier ( ) const

For literal structs, return an empty string.

For identified structs, return the struct's identifier.

Definition at line 1061 of file SPIRVTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >::getImpl().

Referenced by print().

◆ getMemberDecorations() [1/2]

◆ getMemberDecorations() [2/2]

◆ getMemberOffset()

uint64_t StructType::getMemberOffset ( unsigned index) const

◆ getNumElements()

◆ getStructDecorations()

void StructType::getStructDecorations ( SmallVectorImpl< StructType::StructDecorationInfo > & structDecorations) const

◆ hasDecoration()

bool StructType::hasDecoration ( spirv::Decoration decoration) const

Returns true if the struct has a specified decoration.

Definition at line 1079 of file SPIRVTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >::getImpl().

◆ hasOffset()

◆ isIdentified()

bool StructType::isIdentified ( ) const

◆ trySetBody()

LogicalResult StructType::trySetBody ( ArrayRef< Type > memberTypes,
ArrayRef< OffsetInfo > offsetInfo = {},
ArrayRef< MemberDecorationInfo > memberDecorations = {},
ArrayRef< StructDecorationInfo > structDecorations = {} )

Sets the contents of an incomplete identified StructType.

This method must be called only for identified StructTypes and it must be called only once per instance. Otherwise, failure() is returned.

Definition at line 1128 of file SPIRVTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >::mutate().

Referenced by getEmpty(), and parseStructType().

Member Data Documentation

◆ name

StringLiteral mlir::spirv::StructType::name = "spirv.struct"
staticconstexpr

Definition at line 258 of file SPIRVTypes.h.


The documentation for this class was generated from the following files: