MLIR  16.0.0git
Macros | Functions | Variables
LLVMDialect.cpp File Reference
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "TypeDetail.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/IR/Builders.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/FunctionImplementation.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Matchers.h"
#include "llvm/ADT/TypeSwitch.h"
#include "llvm/AsmParser/Parser.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/SourceMgr.h"
#include <numeric>
#include "mlir/Dialect/LLVMIR/LLVMOpsDialect.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMOps.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.cpp.inc"
+ Include dependency graph for LLVMDialect.cpp:

Go to the source code of this file.

Macros

#define REGISTER_ENUM_TYPE(Ty)
 
#define GET_OP_LIST
 
#define GET_OP_LIST
 
#define GET_OP_CLASSES
 
#define GET_OP_CLASSES
 

Functions

static auto processFMFAttr (ArrayRef< NamedAttribute > attrs)
 
static ParseResult parseLLVMOpAttrs (OpAsmParser &parser, NamedAttrList &result)
 
static void printLLVMOpAttrs (OpAsmPrinter &printer, Operation *op, DictionaryAttr attrs)
 
static LogicalResult verifySymbolAttrUse (FlatSymbolRefAttr symbol, Operation *op, SymbolTableCollection &symbolTable)
 Verifies symbol's use in op to ensure the symbol is a valid and fully defined llvm.func. More...
 
static Type getI1SameShape (Type type)
 Returns a boolean type that has the same shape as type. More...
 
template<typename CmpPredicateType >
static ParseResult parseCmpOp (OpAsmParser &parser, OperationState &result)
 
static LogicalResult verifyOpaquePtr (Operation *op, LLVMPointerType ptrType, Optional< Type > ptrElementType)
 Checks that the elemental type is present in either the pointer type or the attribute, but not both. More...
 
static ParseResult parseSwitchOpCases (OpAsmParser &parser, Type flagType, ElementsAttr &caseValues, SmallVectorImpl< Block * > &caseDestinations, SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand >> &caseOperands, SmallVectorImpl< SmallVector< Type >> &caseOperandTypes)
 <cases> ::= integer : bb-id (( ssa-use-and-type-list ))? ( , integer : bb-id (( ssa-use-and-type-list ))? )? More...
 
static void printSwitchOpCases (OpAsmPrinter &p, SwitchOp op, Type flagType, ElementsAttr caseValues, SuccessorRange caseDestinations, OperandRangeRange caseOperands, const TypeRangeRange &caseOperandTypes)
 
static Type extractVectorElementType (Type type)
 Returns the elemental type of any LLVM-compatible vector type or self. More...
 
static void destructureIndices (Type currType, ArrayRef< GEPArg > indices, SmallVectorImpl< int32_t > &rawConstantIndices, SmallVectorImpl< Value > &dynamicIndices)
 Destructures the 'indices' parameter into 'rawConstantIndices' and 'dynamicIndices', encoding the former in the process. More...
 
static ParseResult parseGEPIndices (OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &indices, DenseI32ArrayAttr &rawConstantIndices)
 
static void printGEPIndices (OpAsmPrinter &printer, LLVM::GEPOp gepOp, OperandRange indices, DenseI32ArrayAttr rawConstantIndices)
 
static llvm::Error verifyStructIndices (Type baseGEPType, unsigned indexPos, GEPIndicesAdaptor< ValueRange > indices)
 For the given structIndices and indices, check if they're complied with baseGEPType, especially check against LLVMStructTypes nested within. More...
 
static llvm::Error verifyStructIndices (Type baseGEPType, GEPIndicesAdaptor< ValueRange > indices)
 Driver function around recordStructIndices. More...
 
LogicalResult verifySymbolAttribute (Operation *op, StringRef attributeName, llvm::function_ref< LogicalResult(Operation *, SymbolRefAttr)> verifySymbolType)
 
template<typename OpTy >
static LogicalResult verifyOpMetadata (Operation *op, StringRef attributeName)
 
static LogicalResult verifyMemoryOpMetadata (Operation *op)
 
static Optional< TypegetLoadStoreElementType (OpAsmParser &parser, Type type, SMLoc trailingTypeLoc)
 
static Type getInsertExtractValueElementType (function_ref< InFlightDiagnostic(StringRef)> emitError, Type containerType, ArrayRef< int64_t > position)
 Extract the type at position in the LLVM IR aggregate type containerType. More...
 
static Type getInsertExtractValueElementType (Type llvmType, ArrayRef< int64_t > position)
 Extract the type at position in the wrapped LLVM IR aggregate type containerType. More...
 
static ParseResult parseInsertExtractValueElementType (AsmParser &parser, Type &valueType, Type containerType, DenseI64ArrayAttr position)
 Infer the value type from the container type and position. More...
 
static void printInsertExtractValueElementType (AsmPrinter &printer, Operation *op, Type valueType, Type containerType, DenseI64ArrayAttr position)
 Nothing to print for an inferred type. More...
 
static OperationparentLLVMModule (Operation *op)
 
static int parseOptionalKeywordAlternative (OpAsmParser &parser, ArrayRef< StringRef > keywords)
 
template<typename EnumTy , typename RetTy = EnumTy>
static RetTy parseOptionalLLVMKeyword (OpAsmParser &parser, OperationState &result, EnumTy defaultValue)
 Parse an enum from the keyword, or default to the provided default value. More...
 
static bool isZeroAttribute (Attribute value)
 
static ParseResult parseShuffleType (AsmParser &parser, Type v1Type, Type &resType, DenseI32ArrayAttr mask)
 Build the result type of a shuffle vector operation. More...
 
static void printShuffleType (AsmPrinter &printer, Operation *op, Type v1Type, Type resType, DenseI32ArrayAttr mask)
 Nothing to do when the result type is inferred. More...
 
static Type buildLLVMFunctionType (OpAsmParser &parser, SMLoc loc, ArrayRef< Type > inputs, ArrayRef< Type > outputs, function_interface_impl::VariadicFlag variadicFlag)
 
static ParseResult parseAtomicBinOp (OpAsmParser &parser, OperationState &result, StringRef attrName)
 
static ParseResult parseAtomicOrdering (OpAsmParser &parser, OperationState &result, StringRef attrName)
 
static LogicalResult verifyFuncOpInterfaceStructAttr (Operation *op, Attribute attr, const std::function< Type(FunctionOpInterface)> &getAnnotatedType)
 

Variables

static constexpr const char kVolatileAttrName [] = "volatile_"
 
static constexpr const char kNonTemporalAttrName [] = "nontemporal"
 
static constexpr const char kElemTypeAttrName [] = "elem_type"
 

Macro Definition Documentation

◆ GET_OP_CLASSES [1/2]

#define GET_OP_CLASSES

Definition at line 2607 of file LLVMDialect.cpp.

◆ GET_OP_CLASSES [2/2]

#define GET_OP_CLASSES

Definition at line 2607 of file LLVMDialect.cpp.

◆ GET_OP_LIST [1/2]

#define GET_OP_LIST

◆ GET_OP_LIST [2/2]

#define GET_OP_LIST

◆ REGISTER_ENUM_TYPE

#define REGISTER_ENUM_TYPE (   Ty)
Value:
template <> \
struct EnumTraits<Ty> { \
static StringRef stringify(Ty value) { return stringify##Ty(value); } \
static unsigned getMaxEnumVal() { return getMaxEnumValFor##Ty(); } \
}
static constexpr const bool value
std::string stringify(T &&t)
Generically convert a value to a std::string.

Definition at line 1698 of file LLVMDialect.cpp.

Function Documentation

◆ buildLLVMFunctionType()

static Type buildLLVMFunctionType ( OpAsmParser parser,
SMLoc  loc,
ArrayRef< Type inputs,
ArrayRef< Type outputs,
function_interface_impl::VariadicFlag  variadicFlag 
)
static

◆ destructureIndices()

static void destructureIndices ( Type  currType,
ArrayRef< GEPArg indices,
SmallVectorImpl< int32_t > &  rawConstantIndices,
SmallVectorImpl< Value > &  dynamicIndices 
)
static

Destructures the 'indices' parameter into 'rawConstantIndices' and 'dynamicIndices', encoding the former in the process.

In the process, dynamic indices which are used to index into a structure type are converted to constant indices when possible. To do this, the GEPs element type should be passed as first parameter.

Definition at line 437 of file LLVMDialect.cpp.

References mlir::Value::dyn_cast(), mlir::LLVM::LLVMStructType::getBody(), mlir::Type::isa_and_nonnull(), mlir::LLVM::kGEPConstantBitWidth, mlir::m_ConstantInt(), and mlir::matchPattern().

◆ extractVectorElementType()

static Type extractVectorElementType ( Type  type)
static

Returns the elemental type of any LLVM-compatible vector type or self.

Definition at line 410 of file LLVMDialect.cpp.

References mlir::Type::dyn_cast().

◆ getI1SameShape()

static Type getI1SameShape ( Type  type)
static

Returns a boolean type that has the same shape as type.

It supports both fixed size vectors as well as scalable vectors.

Definition at line 91 of file LLVMDialect.cpp.

References mlir::Type::getContext(), mlir::LLVM::getVectorNumElements(), mlir::LLVM::getVectorType(), and mlir::LLVM::isCompatibleVectorType().

◆ getInsertExtractValueElementType() [1/2]

static Type getInsertExtractValueElementType ( function_ref< InFlightDiagnostic(StringRef)>  emitError,
Type  containerType,
ArrayRef< int64_t >  position 
)
static

Extract the type at position in the LLVM IR aggregate type containerType.

Each element of position is an index into a nested aggregate type. Return the resulting type or emit an error.

Definition at line 1369 of file LLVMDialect.cpp.

References mlir::Type::dyn_cast(), mlir::emitError(), and mlir::LLVM::isCompatibleType().

Referenced by parseInsertExtractValueElementType().

◆ getInsertExtractValueElementType() [2/2]

static Type getInsertExtractValueElementType ( Type  llvmType,
ArrayRef< int64_t >  position 
)
static

Extract the type at position in the wrapped LLVM IR aggregate type containerType.

Definition at line 1406 of file LLVMDialect.cpp.

References mlir::Type::cast(), mlir::Type::dyn_cast(), and getElementType().

◆ getLoadStoreElementType()

static Optional<Type> getLoadStoreElementType ( OpAsmParser parser,
Type  type,
SMLoc  trailingTypeLoc 
)
static

Definition at line 774 of file LLVMDialect.cpp.

References mlir::Type::dyn_cast(), and mlir::AsmParser::emitError().

◆ isZeroAttribute()

static bool isZeroAttribute ( Attribute  value)
static

Definition at line 1801 of file LLVMDialect.cpp.

References value.

◆ parentLLVMModule()

static Operation* parentLLVMModule ( Operation op)
static

◆ parseAtomicBinOp()

static ParseResult parseAtomicBinOp ( OpAsmParser parser,
OperationState result,
StringRef  attrName 
)
static

◆ parseAtomicOrdering()

static ParseResult parseAtomicOrdering ( OpAsmParser parser,
OperationState result,
StringRef  attrName 
)
static

◆ parseCmpOp()

template<typename CmpPredicateType >
static ParseResult parseCmpOp ( OpAsmParser parser,
OperationState result 
)
static

Definition at line 131 of file LLVMDialect.cpp.

◆ parseGEPIndices()

static ParseResult parseGEPIndices ( OpAsmParser parser,
SmallVectorImpl< OpAsmParser::UnresolvedOperand > &  indices,
DenseI32ArrayAttr rawConstantIndices 
)
static

◆ parseInsertExtractValueElementType()

static ParseResult parseInsertExtractValueElementType ( AsmParser parser,
Type valueType,
Type  containerType,
DenseI64ArrayAttr  position 
)
static

◆ parseLLVMOpAttrs()

static ParseResult parseLLVMOpAttrs ( OpAsmParser parser,
NamedAttrList result 
)
static

Definition at line 63 of file LLVMDialect.cpp.

References mlir::AsmParser::parseOptionalAttrDict().

◆ parseOptionalKeywordAlternative()

static int parseOptionalKeywordAlternative ( OpAsmParser parser,
ArrayRef< StringRef >  keywords 
)
static

◆ parseOptionalLLVMKeyword()

template<typename EnumTy , typename RetTy = EnumTy>
static RetTy parseOptionalLLVMKeyword ( OpAsmParser parser,
OperationState result,
EnumTy  defaultValue 
)
static

Parse an enum from the keyword, or default to the provided default value.

The return type is the enum type by default, unless overriden with the second template argument.

Definition at line 1714 of file LLVMDialect.cpp.

References parseOptionalKeywordAlternative(), and mlir::tblgen::stringify().

◆ parseShuffleType()

static ParseResult parseShuffleType ( AsmParser parser,
Type  v1Type,
Type resType,
DenseI32ArrayAttr  mask 
)
static

◆ parseSwitchOpCases()

static ParseResult parseSwitchOpCases ( OpAsmParser parser,
Type  flagType,
ElementsAttr &  caseValues,
SmallVectorImpl< Block * > &  caseDestinations,
SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand >> &  caseOperands,
SmallVectorImpl< SmallVector< Type >> &  caseOperandTypes 
)
static

◆ printGEPIndices()

static void printGEPIndices ( OpAsmPrinter printer,
LLVM::GEPOp  gepOp,
OperandRange  indices,
DenseI32ArrayAttr  rawConstantIndices 
)
static

Definition at line 543 of file LLVMDialect.cpp.

References mlir::OpAsmPrinter::printOperand().

◆ printInsertExtractValueElementType()

static void printInsertExtractValueElementType ( AsmPrinter printer,
Operation op,
Type  valueType,
Type  containerType,
DenseI64ArrayAttr  position 
)
static

Nothing to print for an inferred type.

Definition at line 1489 of file LLVMDialect.cpp.

◆ printLLVMOpAttrs()

static void printLLVMOpAttrs ( OpAsmPrinter printer,
Operation op,
DictionaryAttr  attrs 
)
static

◆ printShuffleType()

static void printShuffleType ( AsmPrinter printer,
Operation op,
Type  v1Type,
Type  resType,
DenseI32ArrayAttr  mask 
)
static

Nothing to do when the result type is inferred.

Definition at line 1959 of file LLVMDialect.cpp.

◆ printSwitchOpCases()

static void printSwitchOpCases ( OpAsmPrinter p,
SwitchOp  op,
Type  flagType,
ElementsAttr  caseValues,
SuccessorRange  caseDestinations,
OperandRangeRange  caseOperands,
const TypeRangeRange caseOperandTypes 
)
static

Definition at line 354 of file LLVMDialect.cpp.

References mlir::OpAsmPrinter::printNewline().

◆ processFMFAttr()

static auto processFMFAttr ( ArrayRef< NamedAttribute attrs)
static

Definition at line 50 of file LLVMDialect.cpp.

References mlir::NamedAttribute::getName(), and mlir::NamedAttribute::getValue().

Referenced by printLLVMOpAttrs().

◆ verifyFuncOpInterfaceStructAttr()

static LogicalResult verifyFuncOpInterfaceStructAttr ( Operation op,
Attribute  attr,
const std::function< Type(FunctionOpInterface)> &  getAnnotatedType 
)
static

Definition at line 2734 of file LLVMDialect.cpp.

References mlir::Operation::emitError().

◆ verifyMemoryOpMetadata()

static LogicalResult verifyMemoryOpMetadata ( Operation op)
static

Definition at line 725 of file LLVMDialect.cpp.

References mlir::failed(), mlir::failure(), and mlir::success().

◆ verifyOpaquePtr()

static LogicalResult verifyOpaquePtr ( Operation op,
LLVMPointerType  ptrType,
Optional< Type ptrElementType 
)
static

Checks that the elemental type is present in either the pointer type or the attribute, but not both.

Definition at line 254 of file LLVMDialect.cpp.

References mlir::Operation::emitOpError(), kElemTypeAttrName, and mlir::success().

◆ verifyOpMetadata()

template<typename OpTy >
static LogicalResult verifyOpMetadata ( Operation op,
StringRef  attributeName 
)
static

◆ verifyStructIndices() [1/2]

static llvm::Error verifyStructIndices ( Type  baseGEPType,
GEPIndicesAdaptor< ValueRange indices 
)
static

Driver function around recordStructIndices.

Note that we always check from the second GEP index since the first one is always dynamic.

Definition at line 637 of file LLVMDialect.cpp.

References verifyStructIndices().

◆ verifyStructIndices() [2/2]

static llvm::Error verifyStructIndices ( Type  baseGEPType,
unsigned  indexPos,
GEPIndicesAdaptor< ValueRange indices 
)
static

For the given structIndices and indices, check if they're complied with baseGEPType, especially check against LLVMStructTypes nested within.

Definition at line 604 of file LLVMDialect.cpp.

References mlir::LLVM::GEPIndicesAdaptor< DynamicRange >::size(), and mlir::success().

Referenced by verifyStructIndices().

◆ verifySymbolAttribute()

LogicalResult verifySymbolAttribute ( Operation op,
StringRef  attributeName,
llvm::function_ref< LogicalResult(Operation *, SymbolRefAttr)>  verifySymbolType 
)

◆ verifySymbolAttrUse()

static LogicalResult verifySymbolAttrUse ( FlatSymbolRefAttr  symbol,
Operation op,
SymbolTableCollection symbolTable 
)
static

Verifies symbol's use in op to ensure the symbol is a valid and fully defined llvm.func.

Definition at line 75 of file LLVMDialect.cpp.

References mlir::Operation::emitOpError(), mlir::FlatSymbolRefAttr::getAttr(), mlir::FlatSymbolRefAttr::getValue(), mlir::SymbolTableCollection::lookupNearestSymbolFrom(), and mlir::success().

Variable Documentation

◆ kElemTypeAttrName

constexpr const char kElemTypeAttrName[] = "elem_type"
staticconstexpr

Definition at line 46 of file LLVMDialect.cpp.

Referenced by verifyOpaquePtr().

◆ kNonTemporalAttrName

constexpr const char kNonTemporalAttrName[] = "nontemporal"
staticconstexpr

Definition at line 45 of file LLVMDialect.cpp.

◆ kVolatileAttrName

constexpr const char kVolatileAttrName[] = "volatile_"
staticconstexpr

Definition at line 44 of file LLVMDialect.cpp.