13#ifndef MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H
14#define MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H
22#include "llvm/IR/Instruction.h"
23#include "llvm/IR/Instructions.h"
24#include "llvm/Support/FormatVariadic.h"
115 const auto *intrinsicIt =
117 return intrinsicToDialect.count(id);
123 "expected unique conversion for intrinsic ({0}), but "
124 "got conflicting {1} and {2} conversions",
126 intrinsicToDialect.lookup(*intrinsicIt)->getNamespace()));
128 const auto *instructionIt =
130 return instructionToDialect.count(id);
136 "expected unique conversion for instruction ({0}), but "
137 "got conflicting {1} and {2} conversions",
139 instructionToDialect.lookup(*intrinsicIt)
148 instructionToDialect[id] = &iface;
151 metadataToDialect[kind].push_back(iface.
getDialect());
165 return intrinsicToDialect.count(
id);
175 instructionToDialect.lookup(inst->getOpcode());
185 return instructionToDialect.count(
id);
196 auto it = metadataToDialect.find(kind);
197 if (it == metadataToDialect.end())
201 bool isSuccess =
false;
202 for (
Dialect *dialect : it->getSecond()) {
204 assert(iface &&
"expected to find a dialect interface");
217 return metadataToDialect.count(kind);
223 convertUnregisteredIntrinsic(
OpBuilder &builder, llvm::CallInst *inst,
DialectInterfaceCollection< LLVMImportDialectInterface > Base
DialectInterfaceCollection(MLIRContext *ctx)
const LLVMImportDialectInterface * getInterfaceFor(Object *obj) const
MLIRContext * getContext() const
Return the context that holds the parent dialect of this interface.
Dialect * getDialect() const
Return the dialect that this interface represents.
detail::DialectInterfaceBase< ConcreteType, DialectInterface > Base
The base class used for all derived interface types.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
StringRef getNamespace() const
Base class for dialect interfaces used to import LLVM IR.
virtual LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport) const
Hook for derived dialect interfaces to implement the import of intrinsics into MLIR.
LLVMImportDialectInterface(Dialect *dialect)
virtual ArrayRef< unsigned > getSupportedIntrinsics() const
Hook for derived dialect interfaces to publish the supported intrinsics.
virtual SmallVector< unsigned > getSupportedMetadata(llvm::LLVMContext &llvmContext) const
Hook for derived dialect interfaces to publish the supported metadata kinds.
virtual LogicalResult convertInstruction(OpBuilder &builder, llvm::Instruction *inst, ArrayRef< llvm::Value * > llvmOperands, LLVM::ModuleImport &moduleImport) const
Hook for derived dialect interfaces to implement the import of instructions into MLIR.
virtual LogicalResult setMetadataAttrs(OpBuilder &builder, unsigned kind, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport) const
Hook for derived dialect interfaces to implement the import of metadata into MLIR.
virtual ArrayRef< unsigned > getSupportedInstructions() const
Hook for derived dialect interfaces to publish the supported instructions.
Interface collection for the import of LLVM IR that dispatches to a concrete dialect interface implem...
LogicalResult convertInstruction(OpBuilder &builder, llvm::Instruction *inst, ArrayRef< llvm::Value * > llvmOperands, LLVM::ModuleImport &moduleImport) const
Converts the LLVM instruction to an MLIR operation if a conversion exists.
LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport) const
Converts the LLVM intrinsic to an MLIR operation if a conversion exists.
LogicalResult setMetadataAttrs(OpBuilder &builder, unsigned kind, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport) const
Attaches the given LLVM metadata to the imported operation if a conversion to one or more MLIR dialec...
bool isConvertibleMetadata(unsigned kind)
Returns true if the given LLVM IR metadata is convertible to an MLIR attribute.
LogicalResult initializeImport(llvm::LLVMContext &llvmContext)
Queries all registered dialect interfaces for the supported LLVM IR intrinsic and metadata kinds and ...
bool isConvertibleInstruction(unsigned id)
Returns true if the given LLVM IR instruction is convertible to an MLIR operation.
bool isConvertibleIntrinsic(llvm::Intrinsic::ID id)
Returns true if the given LLVM IR intrinsic is convertible to an MLIR operation.
Module import implementation class that provides methods to import globals and functions from an LLVM...
This class helps build Operations.
Operation is the basic unit of execution within MLIR.
DialectInterfaceBase< ConcreteType, DialectInterface > Base
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap