13 #ifndef MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H
14 #define MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H
23 #include "llvm/IR/Instruction.h"
24 #include "llvm/IR/Instructions.h"
25 #include "llvm/Support/FormatVariadic.h"
108 const auto *intrinsicIt =
110 return intrinsicToDialect.count(id);
116 "expected unique conversion for intrinsic ({0}), but "
117 "got conflicting {1} and {2} conversions",
118 *intrinsicIt, iface.getDialect()->getNamespace(),
119 intrinsicToDialect.lookup(*intrinsicIt)->getNamespace()));
121 const auto *instructionIt =
123 return instructionToDialect.count(id);
129 "expected unique conversion for instruction ({0}), but "
130 "got conflicting {1} and {2} conversions",
131 *intrinsicIt, iface.getDialect()->getNamespace(),
132 instructionToDialect.lookup(*intrinsicIt)
138 intrinsicToDialect[id] = iface.getDialect();
141 instructionToDialect[id] = &iface;
144 metadataToDialect[kind].push_back(iface.getDialect());
155 Dialect *dialect = intrinsicToDialect.lookup(inst->getIntrinsicID());
161 assert(iface &&
"expected to find a dialect interface");
168 return intrinsicToDialect.count(
id);
178 instructionToDialect.lookup(inst->getOpcode());
188 return instructionToDialect.count(
id);
199 auto it = metadataToDialect.find(kind);
200 if (it == metadataToDialect.end())
204 bool isSuccess =
false;
205 for (
Dialect *dialect : it->getSecond()) {
207 assert(iface &&
"expected to find a dialect interface");
220 return metadataToDialect.count(kind);
A collection of dialect interfaces within a context, for a given concrete interface type.
DialectInterfaceCollection< LLVMImportDialectInterface > Base
const LLVMImportDialectInterface * getInterfaceFor(Object *obj) const
Get the interface for a given object, or null if one is not registered.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
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 ArrayRef< unsigned > getSupportedInstructions() const
Hook for derived dialect interfaces to publish the supported instructions.
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 ArrayRef< unsigned > getSupportedMetadata() const
Hook for derived dialect interfaces to publish the supported metadata kinds.
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.
Interface collection for the import of LLVM IR that dispatches to a concrete dialect interface implem...
LogicalResult initializeImport()
Queries all registered dialect interfaces for the supported LLVM IR intrinsic and metadata kinds and ...
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.
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.
The base class used for all derived interface types.
Include the generated interface declarations.
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This class represents an efficient way to signal success or failure.