16#include "llvm/ADT/SmallVector.h"
22LogicalResult mlir::LLVMImportInterface::convertUnregisteredIntrinsic(
25 Location loc = moduleImport.
translateLoc(inst->getDebugLoc());
26 SmallVector<llvm::Value *> args(inst->args());
27 SmallVector<Value> mlirOperands;
28 SmallVector<NamedAttribute> mlirAttrs;
30 args, llvm::to_vector(inst->operand_bundles()),
36 CallIntrinsicOp::Properties properties{};
39 properties.setOperandSegmentSizes(
40 {
static_cast<int32_t
>(args.size()),
41 static_cast<int32_t
>(mlirOperands.size() - args.size())});
42 if (
failed(CallIntrinsicOp::setPropertiesFromAttr(
44 [&] { return emitError(loc); })))
47 Type resultType = moduleImport.
convertType(inst->getType());
48 auto op = CallIntrinsicOp::create(
51 mlirOperands, properties, {});
55 op.setStrictfp(inst->getAttributes().hasFnAttr(llvm::Attribute::StrictFP));
58 unsigned numRes = op.getNumResults();
60 moduleImport.
mapValue(inst) = op.getResult(0);
65 "expected at most one result from target intrinsic call");
77 llvm::Intrinsic::ID intrinId = inst->getIntrinsicID();
78 assert(intrinId != llvm::Intrinsic::not_intrinsic);
85 dialect = intrinsicToDialect.lookup(intrinId);
90 return convertUnregisteredIntrinsic(builder, inst, moduleImport);
94 assert(iface &&
"expected to find a dialect interface");
95 return iface->convertIntrinsic(builder, inst, moduleImport);
StringAttr getStringAttr(const Twine &bytes)
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
const LLVMImportDialectInterface * getInterfaceFor(Object *obj) const
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
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.