MLIR  19.0.0git
Macros | Functions | Variables
LLVMDialect.cpp File Reference
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "LLVMInlining.h"
#include "TypeDetail.h"
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
#include "mlir/Dialect/LLVMIR/LLVMInterfaces.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/MLIRContext.h"
#include "mlir/IR/Matchers.h"
#include "mlir/Interfaces/FunctionImplementation.h"
#include "llvm/ADT/SCCIterator.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 <optional>
#include "mlir/Dialect/LLVMIR/LLVMOpsDialect.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMOps.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.cpp.inc"

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...
 
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...
 
template<typename CmpPredicateType >
static ParseResult parseCmpOp (OpAsmParser &parser, OperationState &result)
 
static Attribute getBoolAttribute (Type type, MLIRContext *ctx, bool value)
 Returns a scalar or vector boolean attribute of the given type. More...
 
static ParseResult parseSwitchOpCases (OpAsmParser &parser, Type flagType, DenseIntElementsAttr &caseValues, SmallVectorImpl< Block * > &caseDestinations, SmallVectorImpl< SmallVector< OpAsmParser::UnresolvedOperand >> &caseOperands, SmallVectorImpl< SmallVector< Type >> &caseOperandTypes)
 <cases> ::= [ (case (, case )* )? ] <case> ::= integer : bb-id (( ssa-use-and-type-list ))? More...
 
static void printSwitchOpCases (OpAsmPrinter &p, SwitchOp op, Type flagType, DenseIntElementsAttr 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 LogicalResult verifyStructIndices (Type baseGEPType, unsigned indexPos, GEPIndicesAdaptor< ValueRange > indices, function_ref< InFlightDiagnostic()> emitOpError)
 For the given indices, check if they comply with baseGEPType, especially check against LLVMStructTypes nested within. More...
 
static LogicalResult verifyStructIndices (Type baseGEPType, GEPIndicesAdaptor< ValueRange > indices, function_ref< InFlightDiagnostic()> emitOpError)
 Driver function around verifyStructIndices. More...
 
static bool isTypeCompatibleWithAtomicOp (Type type, bool isPointerTypeAllowed)
 Returns true if the given type is supported by atomic operations. More...
 
template<typename OpTy >
LogicalResult verifyAtomicMemOp (OpTy memOp, Type valueType, ArrayRef< AtomicOrdering > unsupportedOrderings)
 Verifies the attributes and the type of atomic memory access operations. More...
 
static SmallVector< Type, 1 > getCallOpResultTypes (LLVMFunctionType calleeType)
 Gets the MLIR Op-like result types of a LLVMFunctionType. More...
 
static LLVMFunctionType getLLVMFuncType (MLIRContext *context, TypeRange results, ValueRange args)
 Constructs a LLVMFunctionType from MLIR results and args. More...
 
static LogicalResult verifyCallOpDebugInfo (CallOp callOp, LLVMFuncOp callee)
 Verify that an inlinable callsite of a debug-info-bearing function in a debug-info-bearing function has a debug location attached to it. More...
 
static ParseResult parseCallTypeAndResolveOperands (OpAsmParser &parser, OperationState &result, bool isDirect, ArrayRef< OpAsmParser::UnresolvedOperand > operands)
 Parses the type of a call operation and resolves the operands if the parsing succeeds. More...
 
static ParseResult parseOptionalCallFuncPtr (OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &operands)
 Parses an optional function pointer operand before the call argument list for indirect calls, or stops parsing at the function identifier otherwise. More...
 
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 LogicalResult verifyComdat (Operation *op, std::optional< SymbolRefAttr > attr)
 
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 LLVMStructType getValAndBoolStructType (Type valType)
 Returns an LLVM struct type that contains a value type and a boolean type. More...
 
template<class ExtOp >
static LogicalResult verifyExtOp (ExtOp op)
 Verifies that the given extension operation operates on consistent scalars or vectors, and that the target width is larger than the input width. More...
 
template<typename T >
static Value foldChainableCast (T castOp, typename T::FoldAdaptor adaptor)
 Folds a cast op that can be chained. More...
 

Variables

static constexpr const char kElemTypeAttrName [] = "elem_type"
 

Macro Definition Documentation

◆ GET_OP_CLASSES [1/2]

#define GET_OP_CLASSES

Definition at line 3000 of file LLVMDialect.cpp.

◆ GET_OP_CLASSES [2/2]

#define GET_OP_CLASSES

Definition at line 3000 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(); } \
}
std::string stringify(T &&t)
Generically convert a value to a std::string.

Definition at line 122 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 553 of file LLVMDialect.cpp.

References 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 538 of file LLVMDialect.cpp.

◆ foldChainableCast()

template<typename T >
static Value foldChainableCast ( castOp,
typename T::FoldAdaptor  adaptor 
)
static

Folds a cast op that can be chained.

Definition at line 2766 of file LLVMDialect.cpp.

◆ getBoolAttribute()

static Attribute getBoolAttribute ( Type  type,
MLIRContext ctx,
bool  value 
)
static

Returns a scalar or vector boolean attribute of the given type.

Definition at line 231 of file LLVMDialect.cpp.

References mlir::BoolAttr::get(), and mlir::DenseElementsAttr::get().

◆ getCallOpResultTypes()

static SmallVector<Type, 1> getCallOpResultTypes ( LLVMFunctionType  calleeType)
static

Gets the MLIR Op-like result types of a LLVMFunctionType.

Definition at line 879 of file LLVMDialect.cpp.

◆ 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 99 of file LLVMDialect.cpp.

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

Referenced by parseCmpOp().

◆ 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 1547 of file LLVMDialect.cpp.

References 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 1584 of file LLVMDialect.cpp.

◆ getLLVMFuncType()

static LLVMFunctionType getLLVMFuncType ( MLIRContext context,
TypeRange  results,
ValueRange  args 
)
static

Constructs a LLVMFunctionType from MLIR results and args.

Definition at line 888 of file LLVMDialect.cpp.

References mlir::get(), and mlir::ValueRange::getTypes().

◆ getValAndBoolStructType()

static LLVMStructType getValAndBoolStructType ( Type  valType)
static

Returns an LLVM struct type that contains a value type and a boolean type.

Definition at line 2648 of file LLVMDialect.cpp.

References mlir::get(), and mlir::Type::getContext().

◆ isTypeCompatibleWithAtomicOp()

static bool isTypeCompatibleWithAtomicOp ( Type  type,
bool  isPointerTypeAllowed 
)
static

Returns true if the given type is supported by atomic operations.

All integer and float types with limited bit width are supported. Additionally, depending on the operation pointers may be supported as well.

Definition at line 776 of file LLVMDialect.cpp.

References mlir::LLVM::isCompatibleFloatingPointType().

Referenced by verifyAtomicMemOp().

◆ isZeroAttribute()

static bool isZeroAttribute ( Attribute  value)
static

Definition at line 1978 of file LLVMDialect.cpp.

◆ parentLLVMModule()

static Operation* parentLLVMModule ( Operation op)
static

Definition at line 1723 of file LLVMDialect.cpp.

◆ parseCallTypeAndResolveOperands()

static ParseResult parseCallTypeAndResolveOperands ( OpAsmParser parser,
OperationState result,
bool  isDirect,
ArrayRef< OpAsmParser::UnresolvedOperand operands 
)
static

◆ parseCmpOp()

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

◆ 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 65 of file LLVMDialect.cpp.

References mlir::AsmParser::parseOptionalAttrDict().

◆ parseOptionalCallFuncPtr()

static ParseResult parseOptionalCallFuncPtr ( OpAsmParser parser,
SmallVectorImpl< OpAsmParser::UnresolvedOperand > &  operands 
)
static

Parses an optional function pointer operand before the call argument list for indirect calls, or stops parsing at the function identifier otherwise.

Definition at line 1190 of file LLVMDialect.cpp.

References mlir::failed(), mlir::OptionalParseResult::has_value(), mlir::OpAsmParser::parseOptionalOperand(), and mlir::success().

◆ 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 overridden with the second template argument.

Definition at line 139 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,
DenseIntElementsAttr 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 653 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 1667 of file LLVMDialect.cpp.

◆ printLLVMOpAttrs()

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

Definition at line 70 of file LLVMDialect.cpp.

◆ 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 2153 of file LLVMDialect.cpp.

◆ printSwitchOpCases()

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

Definition at line 474 of file LLVMDialect.cpp.

◆ processFMFAttr()

static auto processFMFAttr ( ArrayRef< NamedAttribute attrs)
static

◆ verifyAtomicMemOp()

template<typename OpTy >
LogicalResult verifyAtomicMemOp ( OpTy  memOp,
Type  valueType,
ArrayRef< AtomicOrdering >  unsupportedOrderings 
)

Verifies the attributes and the type of atomic memory access operations.

Definition at line 797 of file LLVMDialect.cpp.

References isTypeCompatibleWithAtomicOp(), and mlir::success().

◆ verifyCallOpDebugInfo()

static LogicalResult verifyCallOpDebugInfo ( CallOp  callOp,
LLVMFuncOp  callee 
)
static

Verify that an inlinable callsite of a debug-info-bearing function in a debug-info-bearing function has a debug location attached to it.

This mirrors an LLVM IR verifier.

Definition at line 993 of file LLVMDialect.cpp.

References mlir::success().

◆ verifyComdat()

static LogicalResult verifyComdat ( Operation op,
std::optional< SymbolRefAttr >  attr 
)
static

Definition at line 1875 of file LLVMDialect.cpp.

◆ verifyExtOp()

template<class ExtOp >
static LogicalResult verifyExtOp ( ExtOp  op)
static

Verifies that the given extension operation operates on consistent scalars or vectors, and that the target width is larger than the input width.

Definition at line 2709 of file LLVMDialect.cpp.

◆ verifyStructIndices() [1/2]

static LogicalResult verifyStructIndices ( Type  baseGEPType,
GEPIndicesAdaptor< ValueRange indices,
function_ref< InFlightDiagnostic()>  emitOpError 
)
static

Driver function around verifyStructIndices.

Definition at line 708 of file LLVMDialect.cpp.

References verifyStructIndices().

◆ verifyStructIndices() [2/2]

static LogicalResult verifyStructIndices ( Type  baseGEPType,
unsigned  indexPos,
GEPIndicesAdaptor< ValueRange indices,
function_ref< InFlightDiagnostic()>  emitOpError 
)
static

For the given indices, check if they comply with baseGEPType, especially check against LLVMStructTypes nested within.

Definition at line 669 of file LLVMDialect.cpp.

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

Referenced by verifyStructIndices().

◆ 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 83 of file LLVMDialect.cpp.

Variable Documentation

◆ kElemTypeAttrName

constexpr const char kElemTypeAttrName[] = "elem_type"
staticconstexpr

Definition at line 50 of file LLVMDialect.cpp.