MLIR  15.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/StringSwitch.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/LLVMOpsEnums.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMOpsInterfaces.cpp.inc"
#include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.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 GET_ATTRDEF_CLASSES
 
#define REGISTER_ENUM_TYPE(Ty)
 
#define GET_OP_LIST
 
#define GET_OP_LIST
 
#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...
 
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 llvm::Error recordStructIndices (Type baseGEPType, unsigned indexPos, ArrayRef< int32_t > structIndices, ValueRange indices, SmallVectorImpl< int32_t > *updatedStructIndices, SmallVectorImpl< Value > *remainingIndices)
 For the given structIndices and indices, check if they're complied with baseGEPType, especially check against LLVMStructTypes nested within, and refine/promote struct index from indices to updatedStructIndices if the latter argument is not null. More...
 
static llvm::Error findStructIndices (Type baseGEPType, ArrayRef< int32_t > structIndices, ValueRange indices, SmallVectorImpl< int32_t > *updatedStructIndices=nullptr, SmallVectorImpl< Value > *remainingIndices=nullptr)
 Driver function around recordStructIndices. More...
 
static Type extractVectorElementType (Type type)
 Returns the elemental type of any LLVM-compatible vector type or self. More...
 
static ParseResult parseGEPIndices (OpAsmParser &parser, SmallVectorImpl< OpAsmParser::UnresolvedOperand > &indices, DenseIntElementsAttr &structIndices)
 
static void printGEPIndices (OpAsmPrinter &printer, LLVM::GEPOp gepOp, OperandRange indices, DenseIntElementsAttr structIndices)
 
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 (OpAsmParser &parser, Type containerType, ArrayAttr positionAttr, SMLoc attributeLoc, SMLoc typeLoc)
 
static Type getInsertExtractValueElementType (Type containerType, ArrayAttr positionAttr, Operation *op)
 
template<typename OpTy >
static OpTy lookupSymbolInModule (Operation *parent, StringRef name)
 
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 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)
 
template<typename T >
static Optional< T > getOption (ArrayRef< std::pair< LoopOptionCase, int64_t >> options, LoopOptionCase option)
 

Variables

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

Macro Definition Documentation

◆ GET_ATTRDEF_CLASSES

#define GET_ATTRDEF_CLASSES

Definition at line 50 of file LLVMDialect.cpp.

◆ GET_OP_CLASSES

#define GET_OP_CLASSES

Definition at line 2676 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 1815 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

◆ extractVectorElementType()

static Type extractVectorElementType ( Type  type)
static

◆ findStructIndices()

static llvm::Error findStructIndices ( Type  baseGEPType,
ArrayRef< int32_t >  structIndices,
ValueRange  indices,
SmallVectorImpl< int32_t > *  updatedStructIndices = nullptr,
SmallVectorImpl< Value > *  remainingIndices = nullptr 
)
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 519 of file LLVMDialect.cpp.

References recordStructIndices().

Referenced by extractVectorElementType(), and printGEPIndices().

◆ getInsertExtractValueElementType() [1/2]

static Type getInsertExtractValueElementType ( OpAsmParser parser,
Type  containerType,
ArrayAttr  positionAttr,
SMLoc  attributeLoc,
SMLoc  typeLoc 
)
static

◆ getInsertExtractValueElementType() [2/2]

static Type getInsertExtractValueElementType ( Type  containerType,
ArrayAttr  positionAttr,
Operation op 
)
static

◆ getLoadStoreElementType()

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

Definition at line 761 of file LLVMDialect.cpp.

References mlir::OperationState::addAttribute(), mlir::OperationState::addAttributes(), mlir::OperationState::addOperands(), mlir::OperationState::addSuccessors(), mlir::OperationState::addTypes(), mlir::InFlightDiagnostic::attachNote(), mlir::OperationState::attributes, mlir::Type::dyn_cast(), mlir::AsmParser::emitError(), mlir::emitError(), mlir::Block::empty(), mlir::failure(), mlir::Block::front(), mlir::LLVM::LLVMFunctionType::get(), mlir::LLVM::LLVMPointerType::get(), mlir::FlatSymbolRefAttr::getAttr(), mlir::AsmParser::getBuilder(), mlir::Builder::getContext(), mlir::AsmParser::getCurrentLocation(), mlir::Value::getDefiningOp(), mlir::Builder::getI32VectorAttr(), mlir::Builder::getI64IntegerAttr(), mlir::AsmParser::getNameLoc(), mlir::LLVM::LLVMFunctionType::getNumParams(), mlir::LLVM::LLVMFunctionType::getParamType(), mlir::LLVM::LLVMFunctionType::getReturnType(), mlir::Value::getType(), mlir::Builder::getUnitAttr(), mlir::FlatSymbolRefAttr::getValue(), mlir::LLVM::getVectorElementType(), mlir::Type::isa(), mlir::LLVM::isCompatibleType(), mlir::LLVM::isCompatibleVectorType(), mlir::LLVM::LLVMFunctionType::isVarArg(), kNonTemporalAttrName, kVolatileAttrName, mlir::SymbolTable::lookupNearestSymbolFrom(), mlir::OperationState::operands, mlir::AsmParser::Paren, mlir::AsmParser::parseArrow(), mlir::AsmParser::parseAttribute(), mlir::AsmParser::parseColon(), mlir::AsmParser::parseColonType(), mlir::AsmParser::parseComma(), mlir::AsmParser::parseKeyword(), mlir::AsmParser::parseLSquare(), mlir::OpAsmParser::parseOperand(), mlir::OpAsmParser::parseOperandList(), mlir::AsmParser::parseOptionalAttrDict(), mlir::AsmParser::parseOptionalComma(), mlir::AsmParser::parseOptionalKeyword(), mlir::AsmParser::parseOptionalLParen(), mlir::AsmParser::parseRParen(), mlir::AsmParser::parseRSquare(), mlir::OpAsmParser::parseSuccessorAndUseList(), mlir::AsmParser::parseType(), print(), mlir::OpAsmPrinter::printFunctionalType(), mlir::OpAsmPrinter::printOptionalAttrDict(), mlir::OpAsmPrinter::printSuccessorAndUseList(), mlir::AsmPrinter::printSymbolName(), processFMFAttr(), mlir::OpAsmParser::resolveOperand(), mlir::OpAsmParser::resolveOperands(), mlir::succeeded(), mlir::success(), value, vectorType(), mlir::verify(), and verifyMemoryOpMetadata().

◆ getOption()

template<typename T >
static Optional<T> getOption ( ArrayRef< std::pair< LoopOptionCase, int64_t >>  options,
LoopOptionCase  option 
)
static

◆ isZeroAttribute()

static bool isZeroAttribute ( Attribute  value)
static

Definition at line 1917 of file LLVMDialect.cpp.

References mlir::function_interface_impl::addArgAndResultAttrs(), mlir::OperationState::addAttribute(), mlir::OperationState::addAttributes(), mlir::OperationState::addRegion(), mlir::OperationState::addTypes(), mlir::NamedAttrList::append(), mlir::OperationState::attributes, mlir::Attribute::cast(), mlir::Type::cast(), mlir::Attribute::dyn_cast(), mlir::Type::dyn_cast(), mlir::AsmParser::emitError(), mlir::emitError(), mlir::Operation::emitError(), mlir::failed(), mlir::failure(), mlir::Builder::getContext(), mlir::AsmParser::getCurrentLocation(), mlir::function_interface_impl::getFunctionType(), mlir::LLVM::LLVMFunctionType::getNumParams(), mlir::LLVM::LLVMFunctionType::getParamType(), mlir::Builder::getStringAttr(), mlir::SymbolTable::getSymbolAttrName(), mlir::Value::getType(), mlir::Builder::getUnitAttr(), mlir::LLVM::getVectorElementType(), mlir::LLVM::getVectorType(), mlir::LLVM::isCompatibleVectorType(), mlir::LLVM::isScalableVectorType(), mlir::LLVM::LLVMPointerType::isValidElementType(), mlir::OperationState::name, mlir::OperationState::operands, mlir::AsmParser::parseAttribute(), mlir::AsmParser::parseColonType(), mlir::AsmParser::parseComma(), mlir::OpAsmParser::parseOperand(), mlir::AsmParser::parseOptionalAttrDict(), mlir::AsmParser::parseType(), print(), mlir::OpAsmPrinter::printOptionalAttrDict(), mlir::OpAsmParser::resolveOperand(), mlir::LLVM::satisfiesLLVMModule(), mlir::success(), mlir::verify(), and verifySymbolAttrUse().

◆ lookupSymbolInModule()

template<typename OpTy >
static OpTy lookupSymbolInModule ( Operation parent,
StringRef  name 
)
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 114 of file LLVMDialect.cpp.

References mlir::AsmParser::getBuilder().

◆ parseGEPIndices()

static ParseResult parseGEPIndices ( OpAsmParser parser,
SmallVectorImpl< OpAsmParser::UnresolvedOperand > &  indices,
DenseIntElementsAttr structIndices 
)
static

◆ parseLLVMOpAttrs()

static ParseResult parseLLVMOpAttrs ( OpAsmParser parser,
NamedAttrList result 
)
static

Definition at line 65 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

◆ 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,
DenseIntElementsAttr  structIndices 
)
static

◆ printLLVMOpAttrs()

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

◆ printSwitchOpCases()

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

◆ processFMFAttr()

static auto processFMFAttr ( ArrayRef< NamedAttribute attrs)
static

◆ recordStructIndices()

static llvm::Error recordStructIndices ( Type  baseGEPType,
unsigned  indexPos,
ArrayRef< int32_t >  structIndices,
ValueRange  indices,
SmallVectorImpl< int32_t > *  updatedStructIndices,
SmallVectorImpl< Value > *  remainingIndices 
)
static

For the given structIndices and indices, check if they're complied with baseGEPType, especially check against LLVMStructTypes nested within, and refine/promote struct index from indices to updatedStructIndices if the latter argument is not null.

Definition at line 453 of file LLVMDialect.cpp.

References mlir::Error, mlir::LLVM::LLVMStructType::getBody(), mlir::m_ConstantInt(), mlir::matchPattern(), and mlir::success().

Referenced by findStructIndices().

◆ verifyFuncOpInterfaceStructAttr()

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

◆ verifyMemoryOpMetadata()

static LogicalResult verifyMemoryOpMetadata ( Operation op)
static

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

References mlir::Operation::emitOpError(), mlir::Builder::getI32VectorAttr(), mlir::LLVM::LLVMPointerType::isOpaque(), kElemTypeAttrName, mlir::success(), value, and mlir::verify().

Referenced by printGEPIndices().

◆ verifyOpMetadata()

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

◆ 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

Variable Documentation

◆ kElemTypeAttrName

constexpr const char kElemTypeAttrName[] = "elem_type"
static

◆ kNonTemporalAttrName

constexpr const char kNonTemporalAttrName[] = "nontemporal"
static

Definition at line 45 of file LLVMDialect.cpp.

Referenced by getLoadStoreElementType(), and verifyMemoryOpMetadata().

◆ kVolatileAttrName

constexpr const char kVolatileAttrName[] = "volatile_"
static

Definition at line 44 of file LLVMDialect.cpp.

Referenced by getLoadStoreElementType(), and verifyMemoryOpMetadata().