20LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
23 StringRef intrinName = inst->getCalledFunction()->getName();
25 SmallVector<llvm::Value *> args(inst->args());
26 ArrayRef<llvm::Value *> llvmOperands(args);
28 SmallVector<llvm::OperandBundleUse> llvmOpBundles;
29 llvmOpBundles.reserve(inst->getNumOperandBundles());
30 for (
unsigned i = 0; i < inst->getNumOperandBundles(); ++i)
31 llvmOpBundles.push_back(inst->getOperandBundleAt(i));
33 SmallVector<Value> mlirOperands;
34 SmallVector<NamedAttribute> mlirAttrs;
36 llvmOperands, llvmOpBundles,
false,
41 Type resultType = moduleImport.
convertType(inst->getType());
42 auto op = CallIntrinsicOp::create(
45 StringAttr::get(builder.
getContext(), intrinName),
46 ValueRange{mlirOperands}, FastmathFlagsAttr{});
52 unsigned numRes = op.getNumResults();
54 moduleImport.
mapValue(inst) = op.getResult(0);
59 "expected at most one result from target intrinsic call");
71 llvm::Intrinsic::ID intrinId = inst->getIntrinsicID();
72 assert(intrinId != llvm::Intrinsic::not_intrinsic);
79 dialect = intrinsicToDialect.lookup(intrinId);
84 return convertUnregisteredIntrinsic(builder, inst, moduleImport);
88 assert(iface &&
"expected to find a dialect interface");
MLIRContext * getContext() const
const LLVMImportDialectInterface * getInterfaceFor(Object *obj) const
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.
LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport) const
Converts the LLVM intrinsic to an MLIR operation if a conversion exists.
Module import implementation class that provides methods to import globals and functions from an LLVM...
LogicalResult convertIntrinsicArguments(ArrayRef< llvm::Value * > values, ArrayRef< llvm::OperandBundleUse > opBundles, bool requiresOpBundles, ArrayRef< unsigned > immArgPositions, ArrayRef< StringLiteral > immArgAttrNames, SmallVectorImpl< Value > &valuesOut, SmallVectorImpl< NamedAttribute > &attrsOut)
Converts the LLVM values for an intrinsic to mixed MLIR values and attributes for LLVM_IntrOpBase.
Location translateLoc(llvm::DILocation *loc)
Translates the debug location.
bool useUnregisteredIntrinsicsOnly() const
Whether the importer should try to convert all intrinsics to llvm.call_intrinsic instead of dialect s...
void mapNoResultOp(llvm::Instruction *llvm, Operation *mlir)
Stores a mapping between an LLVM instruction and the imported MLIR operation if the operation returns...
Type convertType(llvm::Type *type)
Converts the type from LLVM to MLIR LLVM dialect.
void setFastmathFlagsAttr(llvm::Instruction *inst, Operation *op) const
Sets the fastmath flags attribute for the imported operation op given the original instruction inst.
void convertArgAndResultAttrs(llvm::CallBase *call, ArgAndResultAttrsOpInterface attrsOp, ArrayRef< unsigned > immArgPositions={})
Converts the argument and result attributes attached to call and adds them to attrsOp.
void mapValue(llvm::Value *llvm, Value mlir)
Stores the mapping between an LLVM value and its MLIR counterpart.
This class helps build Operations.
Include the generated interface declarations.