MLIR
20.0.0git
|
#include "mlir/Dialect/LLVMIR/LLVMDialect.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/Attributes.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 "mlir/Transforms/InliningUtils.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.
Namespaces | |
mlir | |
Include the generated interface declarations. | |
Macros | |
#define | REGISTER_ENUM_TYPE(Ty) |
#define | GET_OP_LIST |
#define | GET_OP_LIST |
#define | GET_OP_CLASSES |
#define | GET_OP_CLASSES |
Functions | |
static Attribute | mlir::convertToAttribute (MLIRContext *ctx, IntegerOverflowFlags flags) |
static LogicalResult | mlir::convertFromAttribute (IntegerOverflowFlags &flags, Attribute attr, function_ref< InFlightDiagnostic()> emitError) |
static ParseResult | parseOverflowFlags (AsmParser &p, IntegerOverflowFlags &flags) |
static void | printOverflowFlags (AsmPrinter &p, Operation *op, IntegerOverflowFlags flags) |
static auto | processFMFAttr (ArrayRef< NamedAttribute > 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... | |
static void | printOneOpBundle (OpAsmPrinter &p, OperandRange operands, TypeRange operandTypes, StringRef tag) |
static void | printOpBundles (OpAsmPrinter &p, Operation *op, OperandRangeRange opBundleOperands, TypeRangeRange opBundleOperandTypes, std::optional< ArrayAttr > opBundleTags) |
static ParseResult | parseOneOpBundle (OpAsmParser &p, SmallVector< SmallVector< OpAsmParser::UnresolvedOperand >> &opBundleOperands, SmallVector< SmallVector< Type >> &opBundleOperandTypes, SmallVector< Attribute > &opBundleTags) |
static std::optional< ParseResult > | parseOpBundles (OpAsmParser &p, SmallVector< SmallVector< OpAsmParser::UnresolvedOperand >> &opBundleOperands, SmallVector< SmallVector< Type >> &opBundleOperandTypes, ArrayAttr &opBundleTags) |
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, const DataLayout &dataLayout) |
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 TypeAttr | getCallOpVarCalleeType (LLVMFunctionType calleeType) |
Gets the variadic callee type for 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... | |
template<typename OpTy > | |
LogicalResult | verifyCallOpVarCalleeType (OpTy callOp) |
Verify that the parameter and return types of the variadic callee type match the callOp argument and result types. More... | |
template<typename OpType > | |
static LogicalResult | verifyOperandBundles (OpType &op) |
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 ParseResult | resolveOpBundleOperands (OpAsmParser &parser, SMLoc loc, OperationState &state, ArrayRef< SmallVector< OpAsmParser::UnresolvedOperand >> opBundleOperands, ArrayRef< SmallVector< Type >> opBundleOperandTypes, StringAttr opBundleSizesAttrName) |
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 Operation * | parentLLVMModule (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 int64_t | getNumElements (Type t) |
Compute the total number of elements in the given type, also taking into account nested types. More... | |
static bool | hasScalableVectorType (Type t) |
Check if the given type is a scalable vector type or a vector/array type that contains a nested scalable vector type. More... | |
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 OpFoldResult | foldChainableCast (T castOp, typename T::FoldAdaptor adaptor) |
Folds a cast op that can be chained. More... | |
Variables | |
static constexpr const char | kElemTypeAttrName [] = "elem_type" |
#define GET_OP_CLASSES |
Definition at line 3536 of file LLVMDialect.cpp.
#define GET_OP_CLASSES |
Definition at line 3536 of file LLVMDialect.cpp.
#define GET_OP_LIST |
#define GET_OP_LIST |
#define REGISTER_ENUM_TYPE | ( | Ty | ) |
Definition at line 176 of file LLVMDialect.cpp.
|
static |
Definition at line 2521 of file LLVMDialect.cpp.
References mlir::AsmParser::emitError(), mlir::get(), mlir::AsmParser::getBuilder(), mlir::Builder::getContext(), mlir::LLVM::isCompatibleType(), and mlir::function_interface_impl::VariadicFlag::isVariadic().
|
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 699 of file LLVMDialect.cpp.
References mlir::LLVM::kGEPConstantBitWidth, mlir::m_ConstantInt(), and mlir::matchPattern().
Returns the elemental type of any LLVM-compatible vector type or self.
Definition at line 684 of file LLVMDialect.cpp.
|
static |
Folds a cast op that can be chained.
Definition at line 3170 of file LLVMDialect.cpp.
|
static |
Returns a scalar or vector boolean attribute of the given type.
Definition at line 379 of file LLVMDialect.cpp.
References mlir::BoolAttr::get(), and mlir::DenseElementsAttr::get().
|
static |
Gets the MLIR Op-like result types of a LLVMFunctionType.
Definition at line 990 of file LLVMDialect.cpp.
|
static |
Gets the variadic callee type for a LLVMFunctionType.
Definition at line 999 of file LLVMDialect.cpp.
References mlir::get().
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 153 of file LLVMDialect.cpp.
References mlir::get(), mlir::Type::getContext(), mlir::LLVM::getVectorNumElements(), mlir::LLVM::getVectorType(), and mlir::LLVM::isCompatibleVectorType().
Referenced by parseCmpOp().
|
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 1844 of file LLVMDialect.cpp.
References mlir::emitError(), and mlir::LLVM::isCompatibleType().
Referenced by parseInsertExtractValueElementType().
Extract the type at position
in the wrapped LLVM IR aggregate type containerType
.
Definition at line 1881 of file LLVMDialect.cpp.
|
static |
Constructs a LLVMFunctionType from MLIR results
and args
.
Definition at line 1004 of file LLVMDialect.cpp.
References mlir::get(), and mlir::ValueRange::getTypes().
|
static |
Compute the total number of elements in the given type, also taking into account nested types.
Supported types are VectorType
, LLVMArrayType
and LLVMFixedVectorType
. Everything else is treated as a scalar.
Definition at line 2848 of file LLVMDialect.cpp.
Referenced by mlir::LLVM::detail::extractNDVectorTypeInfo(), hasAtMostSingleNonScalar(), mlir::affine::AffineDmaStartOp::print(), and mlir::affine::AffineDmaWaitOp::print().
|
static |
Returns an LLVM struct type that contains a value type and a boolean type.
Definition at line 3052 of file LLVMDialect.cpp.
References mlir::get(), and mlir::Type::getContext().
|
static |
Check if the given type is a scalable vector type or a vector/array type that contains a nested scalable vector type.
Definition at line 2863 of file LLVMDialect.cpp.
|
static |
Returns true if the given type is supported by atomic operations.
All integer, float, and pointer types with a power-of-two bitsize and a minimal size of 8 bits are supported.
Definition at line 893 of file LLVMDialect.cpp.
References mlir::DataLayout::getTypeSizeInBits(), and mlir::LLVM::isCompatibleFloatingPointType().
Referenced by verifyAtomicMemOp().
|
static |
Definition at line 2281 of file LLVMDialect.cpp.
Definition at line 2020 of file LLVMDialect.cpp.
References mlir::Operation::getParentOp(), and mlir::LLVM::satisfiesLLVMModule().
|
static |
Parses the type of a call operation and resolves the operands if the parsing succeeds.
Returns failure otherwise.
Definition at line 1345 of file LLVMDialect.cpp.
References mlir::OperationState::addTypes(), mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::getNameLoc(), mlir::OperationState::operands, mlir::AsmParser::parseColonTypeList(), and mlir::OpAsmParser::resolveOperands().
|
static |
Definition at line 323 of file LLVMDialect.cpp.
References mlir::OperationState::addTypes(), mlir::OperationState::attributes, mlir::AsmParser::emitError(), mlir::AsmParser::getBuilder(), mlir::AsmParser::getCurrentLocation(), getI1SameShape(), mlir::Builder::getI64IntegerAttr(), mlir::LLVM::isCompatibleType(), mlir::OperationState::operands, mlir::AsmParser::parseAttribute(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseComma(), mlir::OpAsmParser::parseOperand(), mlir::AsmParser::parseOptionalAttrDict(), mlir::AsmParser::parseType(), mlir::OpAsmParser::resolveOperand(), and mlir::NamedAttrList::set().
|
static |
Definition at line 772 of file LLVMDialect.cpp.
References mlir::sparse_tensor::constantIndex(), mlir::detail::DenseArrayAttrImpl< int32_t >::get(), mlir::AsmParser::getContext(), mlir::OptionalParseResult::has_value(), mlir::AsmParser::parseCommaSeparatedList(), mlir::OpAsmParser::parseOperand(), mlir::AsmParser::parseOptionalInteger(), and mlir::OptionalParseResult::value().
|
static |
Infer the value type from the container type and position.
Definition at line 1952 of file LLVMDialect.cpp.
References mlir::detail::DenseArrayAttrImpl< T >::asArrayRef(), mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), and getInsertExtractValueElementType().
|
static |
Definition at line 244 of file LLVMDialect.cpp.
References mlir::AsmParser::emitError(), mlir::get(), mlir::AsmParser::getContext(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseLParen(), mlir::OpAsmParser::parseOperandList(), mlir::AsmParser::parseOptionalRParen(), mlir::AsmParser::parseRParen(), mlir::AsmParser::parseString(), and mlir::AsmParser::parseTypeList().
Referenced by parseOpBundles().
|
static |
Definition at line 273 of file LLVMDialect.cpp.
References mlir::get(), mlir::AsmParser::getContext(), mlir::AsmParser::parseCommaSeparatedList(), parseOneOpBundle(), mlir::AsmParser::parseOptionalLSquare(), mlir::AsmParser::parseOptionalRSquare(), and mlir::AsmParser::parseRSquare().
|
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 1388 of file LLVMDialect.cpp.
References mlir::OptionalParseResult::has_value(), and mlir::OpAsmParser::parseOptionalOperand().
|
static |
Definition at line 163 of file LLVMDialect.cpp.
References mlir::detail::enumerate(), and mlir::AsmParser::parseOptionalKeyword().
Referenced by parseOptionalLLVMKeyword().
|
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 194 of file LLVMDialect.cpp.
References parseOptionalKeywordAlternative(), and mlir::tblgen::stringify().
|
static |
Definition at line 79 of file LLVMDialect.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::AsmParser::parseGreater(), mlir::AsmParser::parseKeyword(), mlir::AsmParser::parseLess(), mlir::AsmParser::parseOptionalComma(), and mlir::AsmParser::parseOptionalKeyword().
|
static |
Build the result type of a shuffle vector operation.
Definition at line 2445 of file LLVMDialect.cpp.
References mlir::AsmParser::emitError(), mlir::AsmParser::getCurrentLocation(), mlir::LLVM::getVectorElementType(), mlir::LLVM::getVectorType(), mlir::LLVM::isCompatibleVectorType(), and mlir::LLVM::isScalableVectorType().
|
static |
<cases> ::= [
(case (,
case )* )? ]
<case> ::= integer :
bb-id ((
ssa-use-and-type-list )
)?
Definition at line 578 of file LLVMDialect.cpp.
References mlir::DenseIntElementsAttr::get(), mlir::get(), mlir::Type::getIntOrFloatBitWidth(), mlir::AsmParser::None, mlir::AsmParser::parseColon(), mlir::AsmParser::parseColonTypeList(), mlir::AsmParser::parseCommaSeparatedList(), mlir::AsmParser::parseInteger(), mlir::AsmParser::parseLSquare(), mlir::OpAsmParser::parseOperandList(), mlir::AsmParser::parseOptionalLParen(), mlir::AsmParser::parseOptionalRSquare(), mlir::AsmParser::parseRParen(), mlir::AsmParser::parseRSquare(), and mlir::OpAsmParser::parseSuccessor().
|
static |
Definition at line 799 of file LLVMDialect.cpp.
References mlir::OpAsmPrinter::printOperand().
|
static |
Nothing to print for an inferred type.
Definition at line 1964 of file LLVMDialect.cpp.
|
static |
Definition at line 211 of file LLVMDialect.cpp.
References mlir::OpAsmPrinter::printOperands(), and mlir::AsmPrinter::printString().
Referenced by printOpBundles().
|
static |
Definition at line 225 of file LLVMDialect.cpp.
References printOneOpBundle().
|
static |
Definition at line 102 of file LLVMDialect.cpp.
|
static |
Nothing to do when the result type is inferred.
Definition at line 2456 of file LLVMDialect.cpp.
|
static |
Definition at line 620 of file LLVMDialect.cpp.
References mlir::OpAsmPrinter::printNewline(), and mlir::OpAsmPrinter::printSuccessorAndUseList().
|
static |
Definition at line 122 of file LLVMDialect.cpp.
References mlir::NamedAttribute::getName(), and mlir::NamedAttribute::getValue().
|
static |
Definition at line 1401 of file LLVMDialect.cpp.
LogicalResult verifyAtomicMemOp | ( | OpTy | memOp, |
Type | valueType, | ||
ArrayRef< AtomicOrdering > | unsupportedOrderings | ||
) |
Verifies the attributes and the type of atomic memory access operations.
Definition at line 908 of file LLVMDialect.cpp.
References mlir::DataLayout::closest(), and isTypeCompatibleWithAtomicOp().
|
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 1122 of file LLVMDialect.cpp.
LogicalResult verifyCallOpVarCalleeType | ( | OpTy | callOp | ) |
Verify that the parameter and return types of the variadic callee type match the callOp
argument and result types.
Definition at line 1147 of file LLVMDialect.cpp.
|
static |
Definition at line 2178 of file LLVMDialect.cpp.
References mlir::Operation::emitError(), and mlir::SymbolTable::lookupNearestSymbolFrom().
|
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 3113 of file LLVMDialect.cpp.
References mlir::LLVM::getVectorElementType(), mlir::LLVM::getVectorNumElements(), and mlir::LLVM::isCompatibleVectorType().
|
static |
Definition at line 1185 of file LLVMDialect.cpp.
|
static |
Driver function around verifyStructIndices
.
Definition at line 854 of file LLVMDialect.cpp.
References verifyStructIndices().
|
static |
For the given indices
, check if they comply with baseGEPType
, especially check against LLVMStructTypes nested within.
Definition at line 815 of file LLVMDialect.cpp.
References mlir::LLVM::GEPIndicesAdaptor< DynamicRange >::size().
Referenced by verifyStructIndices().
|
static |
Verifies symbol
's use in op
to ensure the symbol is a valid and fully defined llvm.func.
Definition at line 137 of file LLVMDialect.cpp.
References mlir::Operation::emitOpError(), mlir::FlatSymbolRefAttr::getAttr(), mlir::FlatSymbolRefAttr::getValue(), and mlir::SymbolTableCollection::lookupNearestSymbolFrom().
|
staticconstexpr |
Definition at line 120 of file LLVMDialect.cpp.