MLIR 24.0.0git
LLVMIRToLLVMTranslation.cpp File Reference
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMIRToLLVMTranslation.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Target/LLVMIR/ModuleImport.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
#include <optional>
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc"
#include "mlir/Dialect/LLVMIR/LLVMConvertibleLLVMIRIntrinsics.inc"
#include "mlir/Dialect/LLVMIR/LLVMIntrinsicFromLLVMIRConversions.inc"

Go to the source code of this file.

Functions

static bool isConvertibleIntrinsic (llvm::Intrinsic::ID id)
 Returns true if the LLVM IR intrinsic is convertible to an MLIR LLVM dialect intrinsic.
static ArrayRef< unsigned > getSupportedIntrinsicsImpl ()
 Returns the list of LLVM IR intrinsic identifiers that are convertible to MLIR LLVM dialect intrinsics.
static LogicalResult convertIntrinsicImpl (OpBuilder &odsBuilder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport)
 Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a conversion exits.
static SmallVector< unsigned > getSupportedMetadataImpl (llvm::LLVMContext &llvmContext)
 Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM dialect attributes.
static std::optional< uint64_t > getUInt64Metadata (llvm::Metadata *metadata)
 Extracts an LLVM metadata constant as an unsigned 64-bit integer.
static LogicalResult setProfilingAttr (OpBuilder &builder, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Converts the given profiling metadata node to an MLIR profiling attribute and attaches it to the imported operation if the translation succeeds.
static LogicalResult setTBAAAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Searches for the attribute that maps to the given TBAA metadata node and attaches it to the imported operation if the lookup succeeds.
static LogicalResult setTBAAStructAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Attaches the tbaa_struct attribute converted from !tbaa.struct by ModuleImport::convertTBAAStructMetadata to the imported aggregate copy, like setTBAAAttr does for access tags.
static LogicalResult setAccessGroupsAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Looks up all the access group attributes that map to the access group nodes starting from the access group metadata node, and attaches all of them to the imported operation if the lookups succeed.
static LogicalResult setDereferenceableAttr (const llvm::MDNode *node, unsigned kindID, Operation *op, LLVM::ModuleImport &moduleImport)
 Converts the given dereferenceable metadata node to a dereferenceable attribute, and attaches it to the imported operation if the translation succeeds.
static LogicalResult setRangeAttr (const llvm::MDNode *node, Operation *op)
 Multi-range metadata is imported as the union of its ranges.
static LogicalResult setMmraAttr (llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Convert the given MMRA metadata (either an MMRA tag or an array of them) into corresponding MLIR attributes and set them on the given operation as a discardable llvm.mmra attribute.
static LogicalResult setLoopAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Converts the given loop metadata node to an MLIR loop annotation attribute and attaches it to the imported operation if the translation succeeds.
static LogicalResult setAliasScopesAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Looks up all the alias scope attributes that map to the alias scope nodes starting from the alias scope metadata node, and attaches all of them to the imported operation if the lookups succeed.
static LogicalResult setNoaliasScopesAttr (const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
 Looks up all the alias scope attributes that map to the alias scope nodes starting from the noalias metadata node, and attaches all of them to the imported operation if the lookups succeed.
static std::optional< int32_t > parseIntegerMD (llvm::Metadata *md)
 Extracts an integer from the provided metadata md if possible.
static VecTypeHintAttr convertVecTypeHint (Builder builder, llvm::MDNode *node, ModuleImport &moduleImport)
 Converts the provided metadata node node to an LLVM dialect VecTypeHintAttr if possible.
static DenseI32ArrayAttr convertDenseI32Array (Builder builder, llvm::MDNode *node)
 Converts the provided metadata node node to an MLIR DenseI32ArrayAttr if possible.
static IntegerAttr convertIntegerMD (Builder builder, llvm::MDNode *node)
 Convert an MDNode to an MLIR IntegerAttr if possible.
static LogicalResult setVecTypeHintAttr (Builder &builder, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
static LogicalResult setWorkGroupSizeHintAttr (Builder &builder, llvm::MDNode *node, Operation *op)
static LogicalResult setReqdWorkGroupSizeAttr (Builder &builder, llvm::MDNode *node, Operation *op)
static LogicalResult setIntelReqdSubGroupSizeAttr (Builder &builder, llvm::MDNode *node, Operation *op)
 Converts the given intel required subgroup size metadata node to an MLIR attribute and attaches it to the imported operation if the translation succeeds.
static DenseI64ArrayAttr getCallStackAttr (OpBuilder &builder, const llvm::MDNode *node)
 Builds the call-stack hash list of a MemProf callsite node, one int64 per operand.
static LogicalResult setCallsiteAttr (OpBuilder &builder, const llvm::MDNode *node, Operation *op)
 Converts !callsite to the llvm.callsite attribute.
static LogicalResult setMemProfAttr (OpBuilder &builder, const llvm::MDNode *node, Operation *op)
 Converts !memprof to the llvm.memprof attribute.

Variables

static constexpr StringLiteral vecTypeHintMDName = "vec_type_hint"
static constexpr StringLiteral workGroupSizeHintMDName = "work_group_size_hint"
static constexpr StringLiteral reqdWorkGroupSizeMDName = "reqd_work_group_size"
static constexpr StringLiteral intelReqdSubGroupSizeMDName

Function Documentation

◆ convertDenseI32Array()

DenseI32ArrayAttr convertDenseI32Array ( Builder builder,
llvm::MDNode * node )
static

Converts the provided metadata node node to an MLIR DenseI32ArrayAttr if possible.

Definition at line 414 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Builder::getDenseI32ArrayAttr(), and parseIntegerMD().

Referenced by setReqdWorkGroupSizeAttr(), and setWorkGroupSizeHintAttr().

◆ convertIntegerMD()

IntegerAttr convertIntegerMD ( Builder builder,
llvm::MDNode * node )
static

Convert an MDNode to an MLIR IntegerAttr if possible.

Definition at line 429 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Builder::getI32IntegerAttr(), and parseIntegerMD().

Referenced by setIntelReqdSubGroupSizeAttr().

◆ convertIntrinsicImpl()

LogicalResult convertIntrinsicImpl ( OpBuilder & odsBuilder,
llvm::CallInst * inst,
LLVM::ModuleImport & moduleImport )
static

Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a conversion exits.

Returns failure otherwise.

Definition at line 61 of file LLVMIRToLLVMTranslation.cpp.

References isConvertibleIntrinsic().

◆ convertVecTypeHint()

VecTypeHintAttr convertVecTypeHint ( Builder builder,
llvm::MDNode * node,
ModuleImport & moduleImport )
static

Converts the provided metadata node node to an LLVM dialect VecTypeHintAttr if possible.

Definition at line 393 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::convertType(), mlir::Builder::getAttr(), and parseIntegerMD().

Referenced by setVecTypeHintAttr().

◆ getCallStackAttr()

DenseI64ArrayAttr getCallStackAttr ( OpBuilder & builder,
const llvm::MDNode * node )
static

Builds the call-stack hash list of a MemProf callsite node, one int64 per operand.

Returns an empty attribute for an empty or malformed node.

Definition at line 501 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Builder::getDenseI64ArrayAttr().

Referenced by setCallsiteAttr(), and setMemProfAttr().

◆ getSupportedIntrinsicsImpl()

ArrayRef< unsigned > getSupportedIntrinsicsImpl ( )
static

Returns the list of LLVM IR intrinsic identifiers that are convertible to MLIR LLVM dialect intrinsics.

Definition at line 52 of file LLVMIRToLLVMTranslation.cpp.

◆ getSupportedMetadataImpl()

SmallVector< unsigned > getSupportedMetadataImpl ( llvm::LLVMContext & llvmContext)
static

Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM dialect attributes.

Definition at line 86 of file LLVMIRToLLVMTranslation.cpp.

References intelReqdSubGroupSizeMDName, reqdWorkGroupSizeMDName, vecTypeHintMDName, and workGroupSizeHintMDName.

◆ getUInt64Metadata()

std::optional< uint64_t > getUInt64Metadata ( llvm::Metadata * metadata)
static

Extracts an LLVM metadata constant as an unsigned 64-bit integer.

Definition at line 109 of file LLVMIRToLLVMTranslation.cpp.

Referenced by setProfilingAttr().

◆ isConvertibleIntrinsic()

bool isConvertibleIntrinsic ( llvm::Intrinsic::ID id)
static

Returns true if the LLVM IR intrinsic is convertible to an MLIR LLVM dialect intrinsic.

Returns false otherwise.

Definition at line 43 of file LLVMIRToLLVMTranslation.cpp.

Referenced by convertIntrinsicImpl().

◆ parseIntegerMD()

std::optional< int32_t > parseIntegerMD ( llvm::Metadata * md)
static

Extracts an integer from the provided metadata md if possible.

Returns nullopt otherwise.

Definition at line 379 of file LLVMIRToLLVMTranslation.cpp.

Referenced by convertDenseI32Array(), convertIntegerMD(), and convertVecTypeHint().

◆ setAccessGroupsAttr()

LogicalResult setAccessGroupsAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Looks up all the access group attributes that map to the access group nodes starting from the access group metadata node, and attaches all of them to the imported operation if the lookups succeed.

Returns failure otherwise.

Definition at line 239 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::lookupAccessGroupAttrs(), and success().

◆ setAliasScopesAttr()

LogicalResult setAliasScopesAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Looks up all the alias scope attributes that map to the alias scope nodes starting from the alias scope metadata node, and attaches all of them to the imported operation if the lookups succeed.

Returns failure otherwise.

Definition at line 341 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::lookupAliasScopeAttrs(), and success().

◆ setCallsiteAttr()

LogicalResult setCallsiteAttr ( OpBuilder & builder,
const llvm::MDNode * node,
Operation * op )
static

Converts !callsite to the llvm.callsite attribute.

The node is the partial allocation call stack this call sits on, which is what ties it to a !memprof record elsewhere in the profile.

Definition at line 521 of file LLVMIRToLLVMTranslation.cpp.

References getCallStackAttr(), mlir::Operation::setDiscardableAttr(), and success().

◆ setDereferenceableAttr()

LogicalResult setDereferenceableAttr ( const llvm::MDNode * node,
unsigned kindID,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Converts the given dereferenceable metadata node to a dereferenceable attribute, and attaches it to the imported operation if the translation succeeds.

Returns failure if the LLVM IR metadata node is ill-formed.

Definition at line 259 of file LLVMIRToLLVMTranslation.cpp.

References success(), and mlir::LLVM::ModuleImport::translateDereferenceableAttr().

◆ setIntelReqdSubGroupSizeAttr()

LogicalResult setIntelReqdSubGroupSizeAttr ( Builder & builder,
llvm::MDNode * node,
Operation * op )
static

Converts the given intel required subgroup size metadata node to an MLIR attribute and attaches it to the imported operation if the translation succeeds.

Returns failure otherwise.

Definition at line 484 of file LLVMIRToLLVMTranslation.cpp.

References convertIntegerMD(), and success().

◆ setLoopAttr()

LogicalResult setLoopAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Converts the given loop metadata node to an MLIR loop annotation attribute and attaches it to the imported operation if the translation succeeds.

Returns failure otherwise.

Definition at line 323 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Operation::getLoc(), success(), and mlir::LLVM::ModuleImport::translateLoopAnnotationAttr().

◆ setMemProfAttr()

LogicalResult setMemProfAttr ( OpBuilder & builder,
const llvm::MDNode * node,
Operation * op )
static

Converts !memprof to the llvm.memprof attribute.

The node is a list of MemInfoBlocks; each is an allocation call stack, the one allocation-type tag string, then optionally (context id, total size) pairs.

Definition at line 533 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Builder::getArrayAttr(), getCallStackAttr(), mlir::Operation::getContext(), mlir::Builder::getStringAttr(), mlir::Operation::setDiscardableAttr(), and success().

◆ setMmraAttr()

LogicalResult setMmraAttr ( llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Convert the given MMRA metadata (either an MMRA tag or an array of them) into corresponding MLIR attributes and set them on the given operation as a discardable llvm.mmra attribute.

Definition at line 290 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Operation::getContext(), mlir::Operation::setDiscardableAttr(), and success().

◆ setNoaliasScopesAttr()

LogicalResult setNoaliasScopesAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Looks up all the alias scope attributes that map to the alias scope nodes starting from the noalias metadata node, and attaches all of them to the imported operation if the lookups succeed.

Returns failure otherwise.

Definition at line 360 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::lookupAliasScopeAttrs(), and success().

◆ setProfilingAttr()

LogicalResult setProfilingAttr ( OpBuilder & builder,
llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Converts the given profiling metadata node to an MLIR profiling attribute and attaches it to the imported operation if the translation succeeds.

Returns failure otherwise.

Definition at line 119 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Operation::emitWarning(), mlir::Builder::getContext(), mlir::Operation::getNumSuccessors(), getUInt64Metadata(), and success().

◆ setRangeAttr()

LogicalResult setRangeAttr ( const llvm::MDNode * node,
Operation * op )
static

Multi-range metadata is imported as the union of its ranges.

Definition at line 276 of file LLVMIRToLLVMTranslation.cpp.

References mlir::Operation::getContext(), and success().

◆ setReqdWorkGroupSizeAttr()

LogicalResult setReqdWorkGroupSizeAttr ( Builder & builder,
llvm::MDNode * node,
Operation * op )
static

Definition at line 468 of file LLVMIRToLLVMTranslation.cpp.

References convertDenseI32Array(), and success().

◆ setTBAAAttr()

LogicalResult setTBAAAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Searches for the attribute that maps to the given TBAA metadata node and attaches it to the imported operation if the lookup succeeds.

Returns failure otherwise.

Definition at line 204 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::lookupTBAAAttr(), and success().

◆ setTBAAStructAttr()

LogicalResult setTBAAStructAttr ( const llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Attaches the tbaa_struct attribute converted from !tbaa.struct by ModuleImport::convertTBAAStructMetadata to the imported aggregate copy, like setTBAAAttr does for access tags.

Nodes that could not be modeled are unmapped and declined here.

Definition at line 222 of file LLVMIRToLLVMTranslation.cpp.

References mlir::LLVM::ModuleImport::lookupTBAAStructAttr(), and success().

◆ setVecTypeHintAttr()

LogicalResult setVecTypeHintAttr ( Builder & builder,
llvm::MDNode * node,
Operation * op,
LLVM::ModuleImport & moduleImport )
static

Definition at line 438 of file LLVMIRToLLVMTranslation.cpp.

References convertVecTypeHint(), and success().

◆ setWorkGroupSizeHintAttr()

LogicalResult setWorkGroupSizeHintAttr ( Builder & builder,
llvm::MDNode * node,
Operation * op )
static

Definition at line 454 of file LLVMIRToLLVMTranslation.cpp.

References convertDenseI32Array(), and success().

Variable Documentation

◆ intelReqdSubGroupSizeMDName

StringLiteral intelReqdSubGroupSizeMDName
staticconstexpr
Initial value:
=
"intel_reqd_sub_group_size"

Definition at line 38 of file LLVMIRToLLVMTranslation.cpp.

Referenced by getSupportedMetadataImpl().

◆ reqdWorkGroupSizeMDName

StringLiteral reqdWorkGroupSizeMDName = "reqd_work_group_size"
staticconstexpr

Definition at line 37 of file LLVMIRToLLVMTranslation.cpp.

Referenced by getSupportedMetadataImpl().

◆ vecTypeHintMDName

StringLiteral vecTypeHintMDName = "vec_type_hint"
staticconstexpr

Definition at line 35 of file LLVMIRToLLVMTranslation.cpp.

Referenced by getSupportedMetadataImpl().

◆ workGroupSizeHintMDName

StringLiteral workGroupSizeHintMDName = "work_group_size_hint"
staticconstexpr

Definition at line 36 of file LLVMIRToLLVMTranslation.cpp.

Referenced by getSupportedMetadataImpl().