#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>
usingnamespacemlir;
usingnamespacemlir::LLVM;
getMaxEnumValForCConv;
getMaxEnumValForLinkage;
getMaxEnumValForTailCallKind;
#include "mlir/Dialect/LLVMIR/LLVMOpsDialect.cpp.inc"
namespace mlir {
static Attribute convertToAttribute(MLIRContext *ctx,
IntegerOverflowFlags flags) { … }
static LogicalResult
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 constexpr const char kElemTypeAttrName[] = …;
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) { … }
static Type getI1SameShape(Type type) { … }
static int parseOptionalKeywordAlternative(OpAsmParser &parser,
ArrayRef<StringRef> keywords) { … }
namespace …
template <typename EnumTy, typename RetTy = EnumTy>
static RetTy parseOptionalLLVMKeyword(OpAsmParser &parser,
OperationState &result,
EnumTy defaultValue) { … }
static void printOneOpBundle(OpAsmPrinter &p, OperandRange operands,
TypeRange operandTypes, StringRef tag) { … }
static void printOpBundles(OpAsmPrinter &p, Operation *op,
OperandRangeRange opBundleOperands,
TypeRangeRange opBundleOperandTypes,
ArrayRef<std::string> opBundleTags) { … }
static ParseResult parseOneOpBundle(
OpAsmParser &p,
SmallVector<SmallVector<OpAsmParser::UnresolvedOperand>> &opBundleOperands,
SmallVector<SmallVector<Type>> &opBundleOperandTypes,
SmallVector<std::string> &opBundleTags) { … }
static std::optional<ParseResult> parseOpBundles(
OpAsmParser &p,
SmallVector<SmallVector<OpAsmParser::UnresolvedOperand>> &opBundleOperands,
SmallVector<SmallVector<Type>> &opBundleOperandTypes,
SmallVector<std::string> &opBundleTags) { … }
void ICmpOp::print(OpAsmPrinter &p) { … }
void FCmpOp::print(OpAsmPrinter &p) { … }
template <typename CmpPredicateType>
static ParseResult parseCmpOp(OpAsmParser &parser, OperationState &result) { … }
ParseResult ICmpOp::parse(OpAsmParser &parser, OperationState &result) { … }
ParseResult FCmpOp::parse(OpAsmParser &parser, OperationState &result) { … }
static Attribute getBoolAttribute(Type type, MLIRContext *ctx, bool value) { … }
OpFoldResult ICmpOp::fold(FoldAdaptor adaptor) { … }
void AllocaOp::print(OpAsmPrinter &p) { … }
ParseResult AllocaOp::parse(OpAsmParser &parser, OperationState &result) { … }
LogicalResult AllocaOp::verify() { … }
SuccessorOperands BrOp::getSuccessorOperands(unsigned index) { … }
SuccessorOperands CondBrOp::getSuccessorOperands(unsigned index) { … }
void CondBrOp::build(OpBuilder &builder, OperationState &result,
Value condition, Block *trueDest, ValueRange trueOperands,
Block *falseDest, ValueRange falseOperands,
std::optional<std::pair<uint32_t, uint32_t>> weights) { … }
void SwitchOp::build(OpBuilder &builder, OperationState &result, Value value,
Block *defaultDestination, ValueRange defaultOperands,
DenseIntElementsAttr caseValues,
BlockRange caseDestinations,
ArrayRef<ValueRange> caseOperands,
ArrayRef<int32_t> branchWeights) { … }
void SwitchOp::build(OpBuilder &builder, OperationState &result, Value value,
Block *defaultDestination, ValueRange defaultOperands,
ArrayRef<APInt> caseValues, BlockRange caseDestinations,
ArrayRef<ValueRange> caseOperands,
ArrayRef<int32_t> branchWeights) { … }
void SwitchOp::build(OpBuilder &builder, OperationState &result, Value value,
Block *defaultDestination, ValueRange defaultOperands,
ArrayRef<int32_t> caseValues, BlockRange caseDestinations,
ArrayRef<ValueRange> caseOperands,
ArrayRef<int32_t> branchWeights) { … }
static ParseResult parseSwitchOpCases(
OpAsmParser &parser, Type flagType, DenseIntElementsAttr &caseValues,
SmallVectorImpl<Block *> &caseDestinations,
SmallVectorImpl<SmallVector<OpAsmParser::UnresolvedOperand>> &caseOperands,
SmallVectorImpl<SmallVector<Type>> &caseOperandTypes) { … }
static void printSwitchOpCases(OpAsmPrinter &p, SwitchOp op, Type flagType,
DenseIntElementsAttr caseValues,
SuccessorRange caseDestinations,
OperandRangeRange caseOperands,
const TypeRangeRange &caseOperandTypes) { … }
LogicalResult SwitchOp::verify() { … }
SuccessorOperands SwitchOp::getSuccessorOperands(unsigned index) { … }
constexpr int32_t GEPOp::kDynamicIndex;
GEPIndicesAdaptor<ValueRange> GEPOp::getIndices() { … }
static Type extractVectorElementType(Type type) { … }
static void destructureIndices(Type currType, ArrayRef<GEPArg> indices,
SmallVectorImpl<int32_t> &rawConstantIndices,
SmallVectorImpl<Value> &dynamicIndices) { … }
void GEPOp::build(OpBuilder &builder, OperationState &result, Type resultType,
Type elementType, Value basePtr, ArrayRef<GEPArg> indices,
bool inbounds, ArrayRef<NamedAttribute> attributes) { … }
void GEPOp::build(OpBuilder &builder, OperationState &result, Type resultType,
Type elementType, Value basePtr, ValueRange indices,
bool inbounds, ArrayRef<NamedAttribute> attributes) { … }
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) { … }
static LogicalResult
verifyStructIndices(Type baseGEPType, GEPIndicesAdaptor<ValueRange> indices,
function_ref<InFlightDiagnostic()> emitOpError) { … }
LogicalResult LLVM::GEPOp::verify() { … }
void LoadOp::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) { … }
static bool isTypeCompatibleWithAtomicOp(Type type,
const DataLayout &dataLayout) { … }
template <typename OpTy>
LogicalResult verifyAtomicMemOp(OpTy memOp, Type valueType,
ArrayRef<AtomicOrdering> unsupportedOrderings) { … }
LogicalResult LoadOp::verify() { … }
void LoadOp::build(OpBuilder &builder, OperationState &state, Type type,
Value addr, unsigned alignment, bool isVolatile,
bool isNonTemporal, bool isInvariant,
AtomicOrdering ordering, StringRef syncscope) { … }
void StoreOp::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) { … }
LogicalResult StoreOp::verify() { … }
void StoreOp::build(OpBuilder &builder, OperationState &state, Value value,
Value addr, unsigned alignment, bool isVolatile,
bool isNonTemporal, AtomicOrdering ordering,
StringRef syncscope) { … }
static SmallVector<Type, 1> getCallOpResultTypes(LLVMFunctionType calleeType) { … }
static TypeAttr getCallOpVarCalleeType(LLVMFunctionType calleeType) { … }
static LLVMFunctionType getLLVMFuncType(MLIRContext *context, TypeRange results,
ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
StringRef callee, ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
StringAttr callee, ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state, TypeRange results,
FlatSymbolRefAttr callee, ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state,
LLVMFunctionType calleeType, StringRef callee,
ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state,
LLVMFunctionType calleeType, StringAttr callee,
ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state,
LLVMFunctionType calleeType, FlatSymbolRefAttr callee,
ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state,
LLVMFunctionType calleeType, ValueRange args) { … }
void CallOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
ValueRange args) { … }
CallInterfaceCallable CallOp::getCallableForCallee() { … }
void CallOp::setCalleeFromCallable(CallInterfaceCallable callee) { … }
Operation::operand_range CallOp::getArgOperands() { … }
MutableOperandRange CallOp::getArgOperandsMutable() { … }
static LogicalResult verifyCallOpDebugInfo(CallOp callOp, LLVMFuncOp callee) { … }
template <typename OpTy>
LogicalResult verifyCallOpVarCalleeType(OpTy callOp) { … }
template <typename OpType>
static LogicalResult verifyOperandBundles(OpType &op) { … }
LogicalResult CallOp::verify() { … }
LogicalResult CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … }
void CallOp::print(OpAsmPrinter &p) { … }
static ParseResult parseCallTypeAndResolveOperands(
OpAsmParser &parser, OperationState &result, bool isDirect,
ArrayRef<OpAsmParser::UnresolvedOperand> operands) { … }
static ParseResult parseOptionalCallFuncPtr(
OpAsmParser &parser,
SmallVectorImpl<OpAsmParser::UnresolvedOperand> &operands) { … }
static ParseResult resolveOpBundleOperands(
OpAsmParser &parser, SMLoc loc, OperationState &state,
ArrayRef<SmallVector<OpAsmParser::UnresolvedOperand>> opBundleOperands,
ArrayRef<SmallVector<Type>> opBundleOperandTypes,
StringAttr opBundleSizesAttrName) { … }
ParseResult CallOp::parse(OpAsmParser &parser, OperationState &result) { … }
LLVMFunctionType CallOp::getCalleeFunctionType() { … }
void InvokeOp::build(OpBuilder &builder, OperationState &state, LLVMFuncOp func,
ValueRange ops, Block *normal, ValueRange normalOps,
Block *unwind, ValueRange unwindOps) { … }
void InvokeOp::build(OpBuilder &builder, OperationState &state, TypeRange tys,
FlatSymbolRefAttr callee, ValueRange ops, Block *normal,
ValueRange normalOps, Block *unwind,
ValueRange unwindOps) { … }
void InvokeOp::build(OpBuilder &builder, OperationState &state,
LLVMFunctionType calleeType, FlatSymbolRefAttr callee,
ValueRange ops, Block *normal, ValueRange normalOps,
Block *unwind, ValueRange unwindOps) { … }
SuccessorOperands InvokeOp::getSuccessorOperands(unsigned index) { … }
CallInterfaceCallable InvokeOp::getCallableForCallee() { … }
void InvokeOp::setCalleeFromCallable(CallInterfaceCallable callee) { … }
Operation::operand_range InvokeOp::getArgOperands() { … }
MutableOperandRange InvokeOp::getArgOperandsMutable() { … }
LogicalResult InvokeOp::verify() { … }
void InvokeOp::print(OpAsmPrinter &p) { … }
ParseResult InvokeOp::parse(OpAsmParser &parser, OperationState &result) { … }
LLVMFunctionType InvokeOp::getCalleeFunctionType() { … }
LogicalResult LandingpadOp::verify() { … }
void LandingpadOp::print(OpAsmPrinter &p) { … }
ParseResult LandingpadOp::parse(OpAsmParser &parser, OperationState &result) { … }
static Type getInsertExtractValueElementType(
function_ref<InFlightDiagnostic(StringRef)> emitError, Type containerType,
ArrayRef<int64_t> position) { … }
static Type getInsertExtractValueElementType(Type llvmType,
ArrayRef<int64_t> position) { … }
OpFoldResult LLVM::ExtractValueOp::fold(FoldAdaptor adaptor) { … }
LogicalResult ExtractValueOp::verify() { … }
void ExtractValueOp::build(OpBuilder &builder, OperationState &state,
Value container, ArrayRef<int64_t> position) { … }
static ParseResult
parseInsertExtractValueElementType(AsmParser &parser, Type &valueType,
Type containerType,
DenseI64ArrayAttr position) { … }
static void printInsertExtractValueElementType(AsmPrinter &printer,
Operation *op, Type valueType,
Type containerType,
DenseI64ArrayAttr position) { … }
LogicalResult InsertValueOp::verify() { … }
LogicalResult ReturnOp::verify() { … }
static Operation *parentLLVMModule(Operation *op) { … }
GlobalOp AddressOfOp::getGlobal(SymbolTableCollection &symbolTable) { … }
LLVMFuncOp AddressOfOp::getFunction(SymbolTableCollection &symbolTable) { … }
LogicalResult
AddressOfOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … }
OpFoldResult LLVM::AddressOfOp::fold(FoldAdaptor) { … }
void ComdatOp::build(OpBuilder &builder, OperationState &result,
StringRef symName) { … }
LogicalResult ComdatOp::verifyRegions() { … }
void GlobalOp::build(OpBuilder &builder, OperationState &result, Type type,
bool isConstant, Linkage linkage, StringRef name,
Attribute value, uint64_t alignment, unsigned addrSpace,
bool dsoLocal, bool threadLocal, SymbolRefAttr comdat,
ArrayRef<NamedAttribute> attrs,
DIGlobalVariableExpressionAttr dbgExpr) { … }
void GlobalOp::print(OpAsmPrinter &p) { … }
static LogicalResult verifyComdat(Operation *op,
std::optional<SymbolRefAttr> attr) { … }
ParseResult GlobalOp::parse(OpAsmParser &parser, OperationState &result) { … }
static bool isZeroAttribute(Attribute value) { … }
LogicalResult GlobalOp::verify() { … }
LogicalResult GlobalOp::verifyRegions() { … }
LogicalResult
GlobalCtorsOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … }
LogicalResult GlobalCtorsOp::verify() { … }
LogicalResult
GlobalDtorsOp::verifySymbolUses(SymbolTableCollection &symbolTable) { … }
LogicalResult GlobalDtorsOp::verify() { … }
void ShuffleVectorOp::build(OpBuilder &builder, OperationState &state, Value v1,
Value v2, DenseI32ArrayAttr mask,
ArrayRef<NamedAttribute> attrs) { … }
void ShuffleVectorOp::build(OpBuilder &builder, OperationState &state, Value v1,
Value v2, ArrayRef<int32_t> mask) { … }
static ParseResult parseShuffleType(AsmParser &parser, Type v1Type,
Type &resType, DenseI32ArrayAttr mask) { … }
static void printShuffleType(AsmPrinter &printer, Operation *op, Type v1Type,
Type resType, DenseI32ArrayAttr mask) { … }
LogicalResult ShuffleVectorOp::verify() { … }
Block *LLVMFuncOp::addEntryBlock(OpBuilder &builder) { … }
void LLVMFuncOp::build(OpBuilder &builder, OperationState &result,
StringRef name, Type type, LLVM::Linkage linkage,
bool dsoLocal, CConv cconv, SymbolRefAttr comdat,
ArrayRef<NamedAttribute> attrs,
ArrayRef<DictionaryAttr> argAttrs,
std::optional<uint64_t> functionEntryCount) { … }
static Type
buildLLVMFunctionType(OpAsmParser &parser, SMLoc loc, ArrayRef<Type> inputs,
ArrayRef<Type> outputs,
function_interface_impl::VariadicFlag variadicFlag) { … }
ParseResult LLVMFuncOp::parse(OpAsmParser &parser, OperationState &result) { … }
void LLVMFuncOp::print(OpAsmPrinter &p) { … }
LogicalResult LLVMFuncOp::verify() { … }
LogicalResult LLVMFuncOp::verifyRegions() { … }
Region *LLVMFuncOp::getCallableRegion() { … }
OpFoldResult LLVM::UndefOp::fold(FoldAdaptor) { … }
OpFoldResult LLVM::PoisonOp::fold(FoldAdaptor) { … }
LogicalResult LLVM::ZeroOp::verify() { … }
OpFoldResult LLVM::ZeroOp::fold(FoldAdaptor) { … }
static int64_t getNumElements(Type t) { … }
static bool hasScalableVectorType(Type t) { … }
LogicalResult LLVM::ConstantOp::verify() { … }
bool LLVM::ConstantOp::isBuildableWith(Attribute value, Type type) { … }
ConstantOp LLVM::ConstantOp::materialize(OpBuilder &builder, Attribute value,
Type type, Location loc) { … }
OpFoldResult LLVM::ConstantOp::fold(FoldAdaptor) { … }
void AtomicRMWOp::build(OpBuilder &builder, OperationState &state,
AtomicBinOp binOp, Value ptr, Value val,
AtomicOrdering ordering, StringRef syncscope,
unsigned alignment, bool isVolatile) { … }
LogicalResult AtomicRMWOp::verify() { … }
static LLVMStructType getValAndBoolStructType(Type valType) { … }
void AtomicCmpXchgOp::build(OpBuilder &builder, OperationState &state,
Value ptr, Value cmp, Value val,
AtomicOrdering successOrdering,
AtomicOrdering failureOrdering, StringRef syncscope,
unsigned alignment, bool isWeak, bool isVolatile) { … }
LogicalResult AtomicCmpXchgOp::verify() { … }
void FenceOp::build(OpBuilder &builder, OperationState &state,
AtomicOrdering ordering, StringRef syncscope) { … }
LogicalResult FenceOp::verify() { … }
template <class ExtOp>
static LogicalResult verifyExtOp(ExtOp op) { … }
LogicalResult ZExtOp::verify() { … }
OpFoldResult LLVM::ZExtOp::fold(FoldAdaptor adaptor) { … }
LogicalResult SExtOp::verify() { … }
template <typename T>
static OpFoldResult foldChainableCast(T castOp,
typename T::FoldAdaptor adaptor) { … }
OpFoldResult LLVM::BitcastOp::fold(FoldAdaptor adaptor) { … }
LogicalResult LLVM::BitcastOp::verify() { … }
OpFoldResult LLVM::AddrSpaceCastOp::fold(FoldAdaptor adaptor) { … }
Value LLVM::AddrSpaceCastOp::getViewSource() { … }
OpFoldResult LLVM::GEPOp::fold(FoldAdaptor adaptor) { … }
Value LLVM::GEPOp::getViewSource() { … }
OpFoldResult LLVM::ShlOp::fold(FoldAdaptor adaptor) { … }
OpFoldResult LLVM::OrOp::fold(FoldAdaptor adaptor) { … }
LogicalResult CallIntrinsicOp::verify() { … }
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
mlir::StringAttr intrin, mlir::ValueRange args) { … }
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
mlir::StringAttr intrin, mlir::ValueRange args,
mlir::LLVM::FastmathFlagsAttr fastMathFlags) { … }
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
mlir::Type resultType, mlir::StringAttr intrin,
mlir::ValueRange args) { … }
void CallIntrinsicOp::build(OpBuilder &builder, OperationState &state,
mlir::TypeRange resultTypes,
mlir::StringAttr intrin, mlir::ValueRange args,
mlir::LLVM::FastmathFlagsAttr fastMathFlags) { … }
namespace {
struct LLVMOpAsmDialectInterface : public OpAsmDialectInterface { … };
}
LogicalResult LinkerOptionsOp::verify() { … }
void InlineAsmOp::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) { … }
LogicalResult LLVM::masked_gather::verify() { … }
LogicalResult LLVM::masked_scatter::verify() { … }
void LLVMDialect::initialize() { … }
#define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMOps.cpp.inc"
#define GET_OP_CLASSES
#include "mlir/Dialect/LLVMIR/LLVMIntrinsicOps.cpp.inc"
LogicalResult LLVMDialect::verifyDataLayoutString(
StringRef descr, llvm::function_ref<void(const Twine &)> reportError) { … }
LogicalResult LLVMDialect::verifyOperationAttribute(Operation *op,
NamedAttribute attr) { … }
LogicalResult LLVMDialect::verifyParameterAttribute(Operation *op,
Type paramType,
NamedAttribute paramAttr) { … }
LogicalResult LLVMDialect::verifyRegionArgAttribute(Operation *op,
unsigned regionIdx,
unsigned argIdx,
NamedAttribute argAttr) { … }
LogicalResult LLVMDialect::verifyRegionResultAttribute(Operation *op,
unsigned regionIdx,
unsigned resIdx,
NamedAttribute resAttr) { … }
Operation *LLVMDialect::materializeConstant(OpBuilder &builder, Attribute value,
Type type, Location loc) { … }
Value mlir::LLVM::createGlobalString(Location loc, OpBuilder &builder,
StringRef name, StringRef value,
LLVM::Linkage linkage) { … }
bool mlir::LLVM::satisfiesLLVMModule(Operation *op) { … }