MLIR: include/mlir/Target/LLVMIR/LLVMImportInterface.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13 #ifndef MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H

14 #define MLIR_TARGET_LLVMIR_LLVMIMPORTINTERFACE_H

15

22 #include "llvm/IR/Instruction.h"

23 #include "llvm/IR/Instructions.h"

24 #include "llvm/Support/FormatVariadic.h"

25

26 namespace llvm {

27 class IRBuilderBase;

28 }

29

30 namespace mlir {

31 namespace LLVM {

32 class ModuleImport;

33 }

34

35

36

37

38

39

40

43 public:

45

46

47

48 virtual LogicalResult

51 return failure();

52 }

53

54

55

56 virtual LogicalResult

60 return failure();

61 }

62

63

64

65

66 virtual LogicalResult

69 return failure();

70 }

71

72

73

74

76

77

78

79

80

81

82

84

85

86

87

88

91 return {};

92 }

93 };

94

95

96

97

98

101 public:

103

104

105

106

107

110

111 const auto *intrinsicIt =

113 return intrinsicToDialect.count(id);

114 });

118 llvm::formatv(

119 "expected unique conversion for intrinsic ({0}), but "

120 "got conflicting {1} and {2} conversions",

121 *intrinsicIt, iface.getDialect()->getNamespace(),

122 intrinsicToDialect.lookup(*intrinsicIt)->getNamespace()));

123 }

124 const auto *instructionIt =

126 return instructionToDialect.count(id);

127 });

131 llvm::formatv(

132 "expected unique conversion for instruction ({0}), but "

133 "got conflicting {1} and {2} conversions",

134 *intrinsicIt, iface.getDialect()->getNamespace(),

135 instructionToDialect.lookup(*intrinsicIt)

136 ->getDialect()

137 ->getNamespace()));

138 }

139

141 intrinsicToDialect[id] = iface.getDialect();

142

144 instructionToDialect[id] = &iface;

145

147 metadataToDialect[kind].push_back(iface.getDialect());

148 }

149

150 return success();

151 }

152

153

154

157

158

159

161 return intrinsicToDialect.count(id);

162 }

163

164

165

169

171 instructionToDialect.lookup(inst->getOpcode());

172 if (!iface)

173 return failure();

174

175 return iface->convertInstruction(builder, inst, llvmOperands, moduleImport);

176 }

177

178

179

181 return instructionToDialect.count(id);

182 }

183

184

185

186

187

189 llvm::MDNode *node, Operation *op,

191

192 auto it = metadataToDialect.find(kind);

193 if (it == metadataToDialect.end())

194 return failure();

195

196

197 bool isSuccess = false;

198 for (Dialect *dialect : it->getSecond()) {

200 assert(iface && "expected to find a dialect interface");

201 if (succeeded(

203 isSuccess = true;

204 }

205

206

207 return success(isSuccess);

208 }

209

210

211

213 return metadataToDialect.count(kind);

214 }

215

216 private:

217

218 static LogicalResult

219 convertUnregisteredIntrinsic(OpBuilder &builder, llvm::CallInst *inst,

221

225 };

226

227 }

228

229 #endif

union mlir::linalg::@1203::ArityGroupAndKind::Kind 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 ArrayRef< unsigned > getSupportedMetadata(llvm::LLVMContext &ctx) 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.

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.

The base class used for all derived interface types.

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.

auto get(MLIRContext *context, Ts &&...params)

Helper method that injects context only if needed, this helps unify some of the attribute constructio...