MLIR  15.0.0git
Public Member Functions | Static Public Member Functions | 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:
+ Collaboration diagram for mlir::LLVM::LLVMStructType:

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...
 
unsigned getTypeSizeInBits (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 Hooks for DataLayoutTypeInterface. More...
 
unsigned getABIAlignment (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 
unsigned getPreferredAlignment (const DataLayout &dataLayout, DataLayoutEntryListRef params) const
 
bool areCompatible (DataLayoutEntryListRef oldLayout, DataLayoutEntryListRef newLayout) const
 
LogicalResult verifyEntries (DataLayoutEntryListRef entries, Location loc) const
 

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 verify (function_ref< InFlightDiagnostic()> emitError, StringRef, bool)
 Verifies that the type about to be constructed is well-formed. More...
 
static LogicalResult verify (function_ref< InFlightDiagnostic()> emitError, ArrayRef< Type > types, bool)
 
- 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...
 
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...
 

Additional Inherited Members

- 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)
 
- 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...
 
ImplTypegetImpl () const
 Utility for easy access to the storage instance. More...
 
- Static Protected Member Functions inherited from mlir::detail::StorageUserBase< ConcreteT, BaseT, StorageT, UniquerT, Traits >
template<typename... Args>
static LogicalResult verify (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 265 of file LLVMTypes.h.

Member Function Documentation

◆ areCompatible()

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

Definition at line 539 of file LLVMTypes.cpp.

References extractStructSpecValue().

◆ getABIAlignment()

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

Definition at line 521 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 365 of file LLVMTypes.cpp.

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

Referenced by getNewIdentified(), mlir::LLVMTypeConverter::LLVMTypeConverter(), and mlir::LLVM::detail::TypeFromLLVMIRTranslatorImpl::translateType().

◆ getIdentifiedChecked()

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

◆ 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

◆ getName()

StringRef LLVMStructType::getName ( )

◆ 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 376 of file LLVMTypes.cpp.

References mlir::failed(), and getIdentified().

Referenced by isDefinedByCallTo(), and mlir::DataDescriptor::undef().

◆ 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 405 of file LLVMTypes.cpp.

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

Referenced by mlir::LLVM::detail::TypeFromLLVMIRTranslatorImpl::translateType().

◆ getOpaqueChecked()

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

◆ getPreferredAlignment()

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

Definition at line 528 of file LLVMTypes.cpp.

References calculateStructAlignment().

◆ getTypeSizeInBits()

unsigned 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 451 of file LLVMTypes.cpp.

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

◆ isIdentified()

bool LLVMStructType::isIdentified ( ) const

◆ isInitialized()

bool LLVMStructType::isInitialized ( )

Checks if a struct is initialized.

Definition at line 428 of file LLVMTypes.cpp.

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

◆ isOpaque()

bool LLVMStructType::isOpaque ( )

◆ 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 360 of file LLVMTypes.cpp.

References mlir::Type::isa().

Referenced by setBody().

◆ 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 415 of file LLVMTypes.cpp.

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

Referenced by mlir::LLVM::detail::TypeFromLLVMIRTranslatorImpl::translateType().

◆ verify() [1/2]

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

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

Definition at line 435 of file LLVMTypes.cpp.

References mlir::success().

◆ verify() [2/2]

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

◆ verifyEntries()

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

Definition at line 562 of file LLVMTypes.cpp.

References mlir::emitError(), extractStructSpecValue(), and mlir::success().


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