MLIR  20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
mlir::LLVM::LLVMStructType Class Reference

LLVM dialect structure type representing a collection of different-typed elements manipulated together. More...

#include "mlir/Dialect/LLVMIR/LLVMTypes.h"

+ Inheritance diagram for mlir::LLVM::LLVMStructType:

Public Types

using Base = StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits... >
 Inherit base constructors. More...
 
- Public Types inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
using Base = StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits... >
 Utility declarations for the concrete attribute class. More...
 
using ImplType = StorageT
 
using HasTraitFn = bool(*)(TypeID)
 

Public Member Functions

LogicalResult setBody (ArrayRef< Type > types, bool isPacked)
 Set the body of an identified struct. More...
 
bool isPacked () const
 Checks if a struct is packed. More...
 
bool isIdentified () const
 Checks if a struct is identified. More...
 
bool isOpaque ()
 Checks if a struct is opaque. More...
 
bool isInitialized ()
 Checks if a struct is initialized. More...
 
StringRef getName ()
 Returns the name of an identified struct. More...
 
ArrayRef< TypegetBody () const
 Returns the list of element types contained in a non-opaque struct. More...
 
llvm::TypeSize getTypeSizeInBits (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 Hooks for DataLayoutTypeInterface. More...
 
uint64_t getABIAlignment (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 
uint64_t getPreferredAlignment (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 
bool areCompatible (DataLayoutEntryListRef oldLayout, DataLayoutEntryListRef newLayout) const
 
LogicalResult verifyEntries (DataLayoutEntryListRef entries, Location loc) const
 
std::optional< DenseMap< Attribute, Type > > getSubelementIndexMap ()
 Destructs the struct into its indexed field types. More...
 
Type getTypeAtIndex (Attribute index)
 Returns which type is stored at a given integer index within the struct. More...
 
- Public Member Functions inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
ImplTypegetImpl () const
 Utility for easy access to the storage instance. More...
 

Static Public Member Functions

static bool isValidElementType (Type type)
 Checks if the given type can be contained in a structure type. More...
 
static LLVMStructType getIdentified (MLIRContext *context, StringRef name)
 Gets or creates an identified struct with the given name in the provided context. More...
 
static LLVMStructType getIdentifiedChecked (function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
 
static LLVMStructType getNewIdentified (MLIRContext *context, StringRef name, ArrayRef< Type > elements, bool isPacked=false)
 Gets a new identified struct with the given body. More...
 
static LLVMStructType getLiteral (MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
 Gets or creates a literal struct with the given body in the provided context. More...
 
static LLVMStructType getLiteralChecked (function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
 
static LLVMStructType getOpaque (StringRef name, MLIRContext *context)
 Gets or creates an intentionally-opaque identified struct. More...
 
static LLVMStructType getOpaqueChecked (function_ref< InFlightDiagnostic()> emitError, MLIRContext *context, StringRef name)
 
static LogicalResult verifyInvariants (function_ref< InFlightDiagnostic()> emitError, StringRef, bool)
 Verifies that the type about to be constructed is well-formed. More...
 
static LogicalResult verifyInvariants (function_ref< InFlightDiagnostic()> emitError, ArrayRef< Type > types, bool)
 
template<typename... Args>
static LogicalResult verifyInvariants (Args... args)
 Default implementation that just returns success. More...
 
- Static Public Member Functions inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
static TypeID getTypeID ()
 Return a unique identifier for the concrete type. More...
 
template<typename T >
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. More...
 
static detail::InterfaceMap getInterfaceMap ()
 Returns an interface map for the interfaces registered to this storage user. More...
 
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. More...
 
static auto getWalkImmediateSubElementsFn ()
 Returns a function that walks immediate sub elements of a given instance of the storage user. More...
 
static auto getReplaceImmediateSubElementsFn ()
 Returns a function that replaces immediate sub elements of a given instance of the storage user. More...
 
template<typename... IfaceModels>
static void attachInterface (MLIRContext &context)
 Attach the given models as implementations of the corresponding interfaces for the concrete storage user class. More...
 
template<typename... Args>
static ConcreteT get (MLIRContext *ctx, Args &&...args)
 Get or create a new ConcreteT instance within the ctx. More...
 
template<typename... Args>
static ConcreteT getChecked (const Location &loc, Args &&...args)
 Get or create a new ConcreteT instance within the ctx, defined at the given, potentially unknown, location. More...
 
template<typename... Args>
static ConcreteT getChecked (function_ref< InFlightDiagnostic()> emitErrorFn, MLIRContext *ctx, Args... args)
 Get or create a new ConcreteT instance within the ctx. More...
 
static ConcreteT getFromOpaquePointer (const void *ptr)
 Get an instance of the concrete type from a void pointer. More...
 

Static Public Attributes

static constexpr StringLiteral name = "llvm.struct"
 

Additional Inherited Members

- Protected Member Functions inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
template<typename... Args>
LogicalResult mutate (Args &&...args)
 Mutate the current storage instance. More...
 
- Static Protected Member Functions inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
template<typename... Args>
static LogicalResult verifyInvariants (Args... args)
 Default implementation that just returns success. More...
 

Detailed Description

LLVM dialect structure type representing a collection of different-typed elements manipulated together.

Structured can optionally be packed, meaning that their elements immediately follow each other in memory without accounting for potential alignment.

Structure types can be identified (named) or literal. Literal structures are uniquely represented by the list of types they contain and packedness. Literal structure types are immutable after construction.

Identified structures are uniquely represented by their name, a string. They have a mutable component, consisting of the list of types they contain, the packedness and the opacity bits. Identified structs can be created without providing the lists of element types, making them suitable to represent recursive, i.e. self-referring, structures. Identified structs without body are considered opaque. For such structs, one can set the body. Identified structs can be created as intentionally-opaque, implying that the caller does not intend to ever set the body (e.g. forward-declarations of structs from another module) and wants to disallow further modification of the body. For intentionally-opaque structs or non-opaque structs with the body, one is not allowed to set another body (however, one can set exactly the same body).

Note that the packedness of the struct takes place in uniquing of literal structs, but does not in uniquing of identified structs.

Definition at line 104 of file LLVMTypes.h.

Member Typedef Documentation

◆ Base

using mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::Base = StorageUserBase<ConcreteT, BaseT, StorageT, UniquerT, Traits...>

Inherit base constructors.

Definition at line 100 of file StorageUniquerSupport.h.

Member Function Documentation

◆ areCompatible()

bool LLVMStructType::areCompatible ( DataLayoutEntryListRef  oldLayout,
DataLayoutEntryListRef  newLayout 
) const

Definition at line 599 of file LLVMTypes.cpp.

References extractStructSpecValue().

◆ getABIAlignment()

uint64_t LLVMStructType::getABIAlignment ( const DataLayout dataLayout,
DataLayoutEntryListRef  params 
) const

Definition at line 581 of file LLVMTypes.cpp.

References calculateStructAlignment().

◆ getBody()

ArrayRef< Type > LLVMStructType::getBody ( ) const

◆ getIdentified()

LLVMStructType LLVMStructType::getIdentified ( MLIRContext context,
StringRef  name 
)
static

Gets or creates an identified struct with the given name in the provided context.

Note that unlike llvm::StructType::create, this function will NOT rename a struct in case a struct with the same name already exists in the context. Instead, it will just return the existing struct, similarly to the rest of MLIR type get methods.

Definition at line 424 of file LLVMTypes.cpp.

References mlir::get(), and name.

Referenced by getNewIdentified(), mlir::LLVMTypeConverter::LLVMTypeConverter(), and mlirLLVMStructTypeIdentifiedGet().

◆ getIdentifiedChecked()

LLVMStructType LLVMStructType::getIdentifiedChecked ( function_ref< InFlightDiagnostic()>  emitError,
MLIRContext context,
StringRef  name 
)
static

Definition at line 429 of file LLVMTypes.cpp.

References mlir::emitError(), and name.

◆ getLiteral()

LLVMStructType LLVMStructType::getLiteral ( MLIRContext context,
ArrayRef< Type types,
bool  isPacked = false 
)
static

◆ getLiteralChecked()

LLVMStructType LLVMStructType::getLiteralChecked ( function_ref< InFlightDiagnostic()>  emitError,
MLIRContext context,
ArrayRef< Type types,
bool  isPacked = false 
)
static

Definition at line 458 of file LLVMTypes.cpp.

References mlir::emitError(), and isPacked().

Referenced by mlirLLVMStructTypeLiteralGetChecked().

◆ getName()

StringRef LLVMStructType::getName ( )

Returns the name of an identified struct.

Definition at line 488 of file LLVMTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::getImpl().

Referenced by printStructType().

◆ getNewIdentified()

LLVMStructType LLVMStructType::getNewIdentified ( MLIRContext context,
StringRef  name,
ArrayRef< Type elements,
bool  isPacked = false 
)
static

Gets a new identified struct with the given body.

The body cannot be changed later. If a struct with the given name already exists, renames the struct by appending a . followed by a number to the name. Renaming happens even if the existing struct has the same body.

Definition at line 435 of file LLVMTypes.cpp.

References getIdentified(), isPacked(), and name.

Referenced by mlirLLVMStructTypeIdentifiedNewGet().

◆ getOpaque()

LLVMStructType LLVMStructType::getOpaque ( StringRef  name,
MLIRContext context 
)
static

Gets or creates an intentionally-opaque identified struct.

Such a struct cannot have its body set. To create an opaque struct with a mutable body, use getIdentified. Note that unlike llvm::StructType::create, this function will NOT rename a struct in case a struct with the same name already exists in the context. Instead, it will just return the existing struct, similarly to the rest of MLIR type get methods.

Definition at line 464 of file LLVMTypes.cpp.

References mlir::get(), and name.

Referenced by mlirLLVMStructTypeOpaqueGet().

◆ getOpaqueChecked()

LLVMStructType LLVMStructType::getOpaqueChecked ( function_ref< InFlightDiagnostic()>  emitError,
MLIRContext context,
StringRef  name 
)
static

Definition at line 469 of file LLVMTypes.cpp.

References mlir::emitError(), and name.

◆ getPreferredAlignment()

uint64_t LLVMStructType::getPreferredAlignment ( const DataLayout dataLayout,
DataLayoutEntryListRef  params 
) const

Definition at line 588 of file LLVMTypes.cpp.

References calculateStructAlignment().

◆ getSubelementIndexMap()

std::optional< DenseMap< Attribute, Type > > LLVM::LLVMStructType::getSubelementIndexMap ( )

Destructs the struct into its indexed field types.

Definition at line 1569 of file LLVMMemorySlot.cpp.

References mlir::detail::enumerate(), mlir::get(), getBody(), and getContext().

◆ getTypeAtIndex()

Type LLVM::LLVMStructType::getTypeAtIndex ( Attribute  index)

Returns which type is stored at a given integer index within the struct.

Definition at line 1577 of file LLVMMemorySlot.cpp.

◆ getTypeSizeInBits()

llvm::TypeSize LLVMStructType::getTypeSizeInBits ( const DataLayout dataLayout,
DataLayoutEntryListRef  params 
) const

Hooks for DataLayoutTypeInterface.

Should not be called directly. Obtain a DataLayout instance and query it instead.

Definition at line 511 of file LLVMTypes.cpp.

References getBody(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypeSize(), isPacked(), kBitsInByte, and max().

◆ isIdentified()

bool LLVMStructType::isIdentified ( ) const

Checks if a struct is identified.

Definition at line 482 of file LLVMTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::getImpl().

Referenced by getBody(), printStructType(), and setBody().

◆ isInitialized()

bool LLVMStructType::isInitialized ( )

Checks if a struct is initialized.

Definition at line 487 of file LLVMTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::getImpl().

◆ isOpaque()

bool LLVMStructType::isOpaque ( )

Checks if a struct is opaque.

Definition at line 483 of file LLVMTypes.cpp.

References mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::getImpl().

◆ isPacked()

bool LLVMStructType::isPacked ( ) const

◆ isValidElementType()

bool LLVMStructType::isValidElementType ( Type  type)
static

Checks if the given type can be contained in a structure type.

Definition at line 419 of file LLVMTypes.cpp.

Referenced by setBody(), and verifyInvariants().

◆ setBody()

LogicalResult LLVMStructType::setBody ( ArrayRef< Type types,
bool  isPacked 
)

Set the body of an identified struct.

Returns failure if the body could not be set, e.g. if the struct already has a body or if it was marked as intentionally opaque. This might happen in a multi-threaded context when a different thread modified the struct after it was created. Most callers are likely to assert this always succeeds, but it is possible to implement a local renaming scheme based on the result of this call.

Definition at line 474 of file LLVMTypes.cpp.

References isIdentified(), isPacked(), and isValidElementType().

◆ verifyEntries()

LogicalResult LLVMStructType::verifyEntries ( DataLayoutEntryListRef  entries,
Location  loc 
) const

◆ verifyInvariants() [1/3]

template<typename... Args>
static LogicalResult mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >::verifyInvariants ( typename...  Args)
inlinestatic

Default implementation that just returns success.

Definition at line 229 of file StorageUniquerSupport.h.

◆ verifyInvariants() [2/3]

LogicalResult LLVMStructType::verifyInvariants ( function_ref< InFlightDiagnostic()>  emitError,
ArrayRef< Type types,
bool   
)
static

Definition at line 501 of file LLVMTypes.cpp.

References mlir::emitError(), and isValidElementType().

◆ verifyInvariants() [3/3]

LogicalResult LLVMStructType::verifyInvariants ( function_ref< InFlightDiagnostic()>  emitError,
StringRef  ,
bool   
)
static

Verifies that the type about to be constructed is well-formed.

Definition at line 495 of file LLVMTypes.cpp.

Member Data Documentation

◆ name

constexpr StringLiteral mlir::LLVM::LLVMStructType::name = "llvm.struct"
staticconstexpr

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