MLIR 24.0.0git
LLVMToLLVMIRTranslation.cpp File Reference
#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/IR/Operation.h"
#include "mlir/Interfaces/CallInterfaces.h"
#include "mlir/Support/LLVM.h"
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/IR/DIBuilder.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/MatrixBuilder.h"
#include "llvm/IR/MemoryModelRelaxationAnnotations.h"
#include "llvm/Support/LogicalResult.h"
#include "mlir/Dialect/LLVMIR/LLVMConversionEnumsToLLVM.inc"
#include "mlir/Dialect/LLVMIR/LLVMConversions.inc"
#include "mlir/Dialect/LLVMIR/LLVMIntrinsicConversions.inc"

Go to the source code of this file.

Functions

static llvm::FastMathFlags getFastmathFlags (FastmathFlagsInterface &op)
static SmallVector< unsignedextractPosition (ArrayRef< int64_t > indices)
 Convert the value of a DenseI64ArrayAttr to a vector of unsigned indices.
static std::string diagStr (const llvm::Type *type)
 Convert an LLVM type to a string for printing in diagnostics.
static FailureOr< llvm::Function * > getOverloadedDeclaration (CallIntrinsicOp op, llvm::Intrinsic::ID id, llvm::Module *module, LLVM::ModuleTranslation &moduleTranslation)
 Get the declaration of an overloaded llvm intrinsic.
static llvm::OperandBundleDef convertOperandBundle (OperandRange bundleOperands, StringRef bundleTag, LLVM::ModuleTranslation &moduleTranslation)
static SmallVector< llvm::OperandBundleDef > convertOperandBundles (OperandRangeRange bundleOperands, ArrayAttr bundleTags, LLVM::ModuleTranslation &moduleTranslation)
static SmallVector< llvm::OperandBundleDef > convertOperandBundles (OperandRangeRange bundleOperands, std::optional< ArrayAttr > bundleTags, LLVM::ModuleTranslation &moduleTranslation)
static LogicalResult convertCallLLVMIntrinsicOp (CallIntrinsicOp op, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
 Builder for LLVM_CallIntrinsicOp.
static LogicalResult convertNamedMetadataOp (NamedMetadataOp op, LLVM::ModuleTranslation &moduleTranslation)
static void convertLinkerOptionsOp (ArrayAttr options, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static llvm::Metadata * convertModuleFlagValue (StringRef key, ArrayAttr arrayAttr, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static llvm::Metadata * convertModuleFlagProfileSummaryAttr (StringRef key, ModuleFlagProfileSummaryAttr summaryAttr, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static void convertModuleFlagsOp (ArrayAttr flags, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static std::pair< llvm::GlobalValue *, llvm::FunctionType * > lookupNonFunctionSymbolCallee (FlatSymbolRefAttr attr, mlir::Type calleeFuncType, Operation &opInst, LLVM::ModuleTranslation &moduleTranslation)
 Looks up the GlobalValue and FunctionType for a callee symbol that is not a regular LLVM function (i.e.
static llvm::DILocalScope * getLocalScopeFromLoc (llvm::IRBuilderBase &builder, Location loc, LLVM::ModuleTranslation &moduleTranslation)
static LogicalResult convertOperationImpl (Operation &opInst, llvm::IRBuilderBase &builder, LLVM::ModuleTranslation &moduleTranslation)
static LogicalResult amendOperationImpl (Operation &op, ArrayRef< llvm::Instruction * > instructions, NamedAttribute attribute, LLVM::ModuleTranslation &moduleTranslation)
llvm::Constant * getLLVMConstant (llvm::Type *llvmType, Attribute attr, Location loc, const ModuleTranslation &moduleTranslation)
 Create an LLVM IR constant of llvmType from the MLIR attribute attr.

Function Documentation

◆ amendOperationImpl()

LogicalResult amendOperationImpl ( Operation & op,
ArrayRef< llvm::Instruction * > instructions,
NamedAttribute attribute,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertCallLLVMIntrinsicOp()

◆ convertLinkerOptionsOp()

void convertLinkerOptionsOp ( ArrayAttr options,
llvm::IRBuilderBase & builder,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertModuleFlagProfileSummaryAttr()

llvm::Metadata * convertModuleFlagProfileSummaryAttr ( StringRef key,
ModuleFlagProfileSummaryAttr summaryAttr,
llvm::IRBuilderBase & builder,
LLVM::ModuleTranslation & moduleTranslation )
static

Definition at line 296 of file LLVMToLLVMIRTranslation.cpp.

Referenced by convertModuleFlagsOp().

◆ convertModuleFlagsOp()

void convertModuleFlagsOp ( ArrayAttr flags,
llvm::IRBuilderBase & builder,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertModuleFlagValue()

llvm::Metadata * convertModuleFlagValue ( StringRef key,
ArrayAttr arrayAttr,
llvm::IRBuilderBase & builder,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertNamedMetadataOp()

LogicalResult convertNamedMetadataOp ( NamedMetadataOp op,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertOperandBundle()

llvm::OperandBundleDef convertOperandBundle ( OperandRange bundleOperands,
StringRef bundleTag,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertOperandBundles() [1/2]

SmallVector< llvm::OperandBundleDef > convertOperandBundles ( OperandRangeRange bundleOperands,
ArrayAttr bundleTags,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ convertOperandBundles() [2/2]

SmallVector< llvm::OperandBundleDef > convertOperandBundles ( OperandRangeRange bundleOperands,
std::optional< ArrayAttr > bundleTags,
LLVM::ModuleTranslation & moduleTranslation )
static

Definition at line 130 of file LLVMToLLVMIRTranslation.cpp.

References convertOperandBundles().

◆ convertOperationImpl()

LogicalResult convertOperationImpl ( Operation & opInst,
llvm::IRBuilderBase & builder,
LLVM::ModuleTranslation & moduleTranslation )
static

Definition at line 430 of file LLVMToLLVMIRTranslation.cpp.

References ArrayAttr(), b, mlir::LLVM::ModuleTranslation::convertAllocsizeAttr(), mlir::LLVM::ModuleTranslation::convertArgAndResultAttrs(), mlir::LLVM::ModuleTranslation::convertDefaultFuncAttr(), mlir::LLVM::ModuleTranslation::convertFunctionAttrCollection(), mlir::LLVM::ModuleTranslation::convertNoBuiltin(), convertOperandBundles(), mlir::LLVM::ModuleTranslation::convertType(), mlir::FlatSymbolRefAttr::get(), mlir::Operation::getAttrOfType(), mlir::LLVM::ModuleTranslation::getContext(), getFastmathFlags(), mlir::LLVM::ModuleTranslation::getLLVMContext(), mlir::LLVM::ModuleTranslation::getLLVMModule(), mlir::Operation::getNumResults(), mlir::Operation::getResult(), mlir::LLVM::ModuleTranslation::lookupAlias(), mlir::LLVM::ModuleTranslation::lookupBlock(), mlir::LLVM::ModuleTranslation::lookupBlockAddress(), mlir::LLVM::ModuleTranslation::lookupFunction(), mlir::LLVM::ModuleTranslation::lookupGlobal(), mlir::LLVM::ModuleTranslation::lookupIFunc(), lookupNonFunctionSymbolCallee(), mlir::LLVM::ModuleTranslation::lookupValue(), mlir::LLVM::ModuleTranslation::lookupValues(), mlir::LLVM::ModuleTranslation::mapBlockAddress(), mlir::LLVM::ModuleTranslation::mapBranch(), mlir::LLVM::ModuleTranslation::mapCall(), mlir::LLVM::ModuleTranslation::mapUnresolvedBlockAddress(), mlir::LLVM::ModuleTranslation::mapValue(), result, mlir::LLVM::ModuleTranslation::setAccessGroupsMetadata(), mlir::LLVM::ModuleTranslation::setAliasScopeMetadata(), mlir::LLVM::ModuleTranslation::setLoopMetadata(), mlir::LLVM::ModuleTranslation::setTBAAMetadata(), success(), and mlir::LLVM::ModuleTranslation::symbolTable().

◆ diagStr()

std::string diagStr ( const llvm::Type * type)
static

Convert an LLVM type to a string for printing in diagnostics.

Definition at line 67 of file LLVMToLLVMIRTranslation.cpp.

Referenced by convertCallLLVMIntrinsicOp(), and getOverloadedDeclaration().

◆ extractPosition()

SmallVector< unsigned > extractPosition ( ArrayRef< int64_t > indices)
static

Convert the value of a DenseI64ArrayAttr to a vector of unsigned indices.

Definition at line 60 of file LLVMToLLVMIRTranslation.cpp.

References indices.

◆ getFastmathFlags()

llvm::FastMathFlags getFastmathFlags ( FastmathFlagsInterface & op)
static

Definition at line 37 of file LLVMToLLVMIRTranslation.cpp.

Referenced by convertCallLLVMIntrinsicOp(), and convertOperationImpl().

◆ getLLVMConstant()

llvm::Constant * mlir::LLVM::detail::getLLVMConstant ( llvm::Type * llvmType,
Attribute attr,
Location loc,
const ModuleTranslation & moduleTranslation )

Create an LLVM IR constant of llvmType from the MLIR attribute attr.

This currently supports integer, floating point, splat and dense element attributes and combinations thereof. Also, an array attribute with two elements is supported to represent a complex constant. In case of error, report it to loc and return nullptr.

Definition at line 573 of file ModuleTranslation.cpp.

References mlir::emitError().

◆ getLocalScopeFromLoc()

llvm::DILocalScope * getLocalScopeFromLoc ( llvm::IRBuilderBase & builder,
Location loc,
LLVM::ModuleTranslation & moduleTranslation )
static

◆ getOverloadedDeclaration()

FailureOr< llvm::Function * > getOverloadedDeclaration ( CallIntrinsicOp op,
llvm::Intrinsic::ID id,
llvm::Module * module,
LLVM::ModuleTranslation & moduleTranslation )
static

Get the declaration of an overloaded llvm intrinsic.

First we get the overloaded argument types and/or result type from the CallIntrinsicOp, and then use those to get the correct declaration of the overloaded intrinsic.

Definition at line 78 of file LLVMToLLVMIRTranslation.cpp.

References mlir::LLVM::ModuleTranslation::convertType(), diagStr(), and mlir::emitError().

Referenced by convertCallLLVMIntrinsicOp().

◆ lookupNonFunctionSymbolCallee()

std::pair< llvm::GlobalValue *, llvm::FunctionType * > lookupNonFunctionSymbolCallee ( FlatSymbolRefAttr attr,
mlir::Type calleeFuncType,
Operation & opInst,
LLVM::ModuleTranslation & moduleTranslation )
static

Looks up the GlobalValue and FunctionType for a callee symbol that is not a regular LLVM function (i.e.

an alias or ifunc). Returns the lowered GlobalValue and FunctionType derived from calleeFuncType.

Definition at line 402 of file LLVMToLLVMIRTranslation.cpp.

References mlir::LLVM::ModuleTranslation::convertType(), mlir::LLVM::ModuleTranslation::lookupAlias(), mlir::LLVM::ModuleTranslation::lookupIFunc(), mlir::SymbolTableCollection::lookupSymbolIn(), mlir::LLVM::parentLLVMModule(), and mlir::LLVM::ModuleTranslation::symbolTable().

Referenced by convertOperationImpl().