MLIR  21.0.0git
LLVMIRToLLVMTranslation.cpp
Go to the documentation of this file.
1 //===- LLVMIRToLLVMTranslation.cpp - Translate LLVM IR to LLVM dialect ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements a translation between LLVM IR and the MLIR LLVM dialect.
10 //
11 //===----------------------------------------------------------------------===//
12 
16 #include "mlir/Support/LLVM.h"
18 
19 #include "llvm/ADT/PostOrderIterator.h"
20 #include "llvm/ADT/ScopeExit.h"
21 #include "llvm/ADT/StringSet.h"
22 #include "llvm/ADT/TypeSwitch.h"
23 #include "llvm/IR/Constants.h"
24 #include "llvm/IR/InlineAsm.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/Support/ModRef.h"
28 
29 using namespace mlir;
30 using namespace mlir::LLVM;
31 using namespace mlir::LLVM::detail;
32 
33 #include "mlir/Dialect/LLVMIR/LLVMConversionEnumsFromLLVM.inc"
34 
35 static constexpr StringLiteral vecTypeHintMDName = "vec_type_hint";
36 static constexpr StringLiteral workGroupSizeHintMDName = "work_group_size_hint";
37 static constexpr StringLiteral reqdWorkGroupSizeMDName = "reqd_work_group_size";
38 static constexpr StringLiteral intelReqdSubGroupSizeMDName =
39  "intel_reqd_sub_group_size";
40 
41 /// Returns true if the LLVM IR intrinsic is convertible to an MLIR LLVM dialect
42 /// intrinsic. Returns false otherwise.
44  static const DenseSet<unsigned> convertibleIntrinsics = {
45 #include "mlir/Dialect/LLVMIR/LLVMConvertibleLLVMIRIntrinsics.inc"
46  };
47  return convertibleIntrinsics.contains(id);
48 }
49 
50 /// Returns the list of LLVM IR intrinsic identifiers that are convertible to
51 /// MLIR LLVM dialect intrinsics.
53  static const SmallVector<unsigned> convertibleIntrinsics = {
54 #include "mlir/Dialect/LLVMIR/LLVMConvertibleLLVMIRIntrinsics.inc"
55  };
56  return convertibleIntrinsics;
57 }
58 
59 /// Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a
60 /// conversion exits. Returns failure otherwise.
61 static LogicalResult convertIntrinsicImpl(OpBuilder &odsBuilder,
62  llvm::CallInst *inst,
63  LLVM::ModuleImport &moduleImport) {
64  llvm::Intrinsic::ID intrinsicID = inst->getIntrinsicID();
65 
66  // Check if the intrinsic is convertible to an MLIR dialect counterpart and
67  // copy the arguments to an an LLVM operands array reference for conversion.
68  if (isConvertibleIntrinsic(intrinsicID)) {
69  SmallVector<llvm::Value *> args(inst->args());
70  ArrayRef<llvm::Value *> llvmOperands(args);
71 
73  llvmOpBundles.reserve(inst->getNumOperandBundles());
74  for (unsigned i = 0; i < inst->getNumOperandBundles(); ++i)
75  llvmOpBundles.push_back(inst->getOperandBundleAt(i));
76 
77 #include "mlir/Dialect/LLVMIR/LLVMIntrinsicFromLLVMIRConversions.inc"
78  }
79 
80  return failure();
81 }
82 
83 /// Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM
84 /// dialect attributes.
85 static ArrayRef<unsigned> getSupportedMetadataImpl(llvm::LLVMContext &context) {
86  static const SmallVector<unsigned> convertibleMetadata = {
87  llvm::LLVMContext::MD_prof,
88  llvm::LLVMContext::MD_tbaa,
89  llvm::LLVMContext::MD_access_group,
90  llvm::LLVMContext::MD_loop,
91  llvm::LLVMContext::MD_noalias,
92  llvm::LLVMContext::MD_alias_scope,
93  llvm::LLVMContext::MD_dereferenceable,
94  llvm::LLVMContext::MD_dereferenceable_or_null,
95  context.getMDKindID(vecTypeHintMDName),
96  context.getMDKindID(workGroupSizeHintMDName),
97  context.getMDKindID(reqdWorkGroupSizeMDName),
98  context.getMDKindID(intelReqdSubGroupSizeMDName)};
99  return convertibleMetadata;
100 }
101 
102 /// Converts the given profiling metadata `node` to an MLIR profiling attribute
103 /// and attaches it to the imported operation if the translation succeeds.
104 /// Returns failure otherwise.
105 static LogicalResult setProfilingAttr(OpBuilder &builder, llvm::MDNode *node,
106  Operation *op,
107  LLVM::ModuleImport &moduleImport) {
108  // Return failure for empty metadata nodes since there is nothing to import.
109  if (!node->getNumOperands())
110  return failure();
111 
112  auto *name = dyn_cast<llvm::MDString>(node->getOperand(0));
113  if (!name)
114  return failure();
115 
116  // Handle function entry count metadata.
117  if (name->getString() == "function_entry_count") {
118 
119  // TODO support function entry count metadata with GUID fields.
120  if (node->getNumOperands() != 2)
121  return failure();
122 
123  llvm::ConstantInt *entryCount =
124  llvm::mdconst::dyn_extract<llvm::ConstantInt>(node->getOperand(1));
125  if (!entryCount)
126  return failure();
127  if (auto funcOp = dyn_cast<LLVMFuncOp>(op)) {
128  funcOp.setFunctionEntryCount(entryCount->getZExtValue());
129  return success();
130  }
131  return op->emitWarning()
132  << "expected function_entry_count to be attached to a function";
133  }
134 
135  if (name->getString() != "branch_weights")
136  return failure();
137 
138  // Handle branch weights metadata.
139  SmallVector<int32_t> branchWeights;
140  branchWeights.reserve(node->getNumOperands() - 1);
141  for (unsigned i = 1, e = node->getNumOperands(); i != e; ++i) {
142  llvm::ConstantInt *branchWeight =
143  llvm::mdconst::dyn_extract<llvm::ConstantInt>(node->getOperand(i));
144  if (!branchWeight)
145  return failure();
146  branchWeights.push_back(branchWeight->getZExtValue());
147  }
148 
149  if (auto iface = dyn_cast<WeightedBranchOpInterface>(op)) {
150  // LLVM allows attaching a single weight to call instructions.
151  // This is used for carrying the execution count information
152  // in PGO modes. MLIR WeightedBranchOpInterface does not allow this,
153  // so we drop the metadata in this case.
154  // LLVM should probably use the VP form of MD_prof metadata
155  // for such cases.
156  if (op->getNumSuccessors() != 0)
157  iface.setWeights(branchWeights);
158  return success();
159  }
160  return failure();
161 }
162 
163 /// Searches for the attribute that maps to the given TBAA metadata `node` and
164 /// attaches it to the imported operation if the lookup succeeds. Returns
165 /// failure otherwise.
166 static LogicalResult setTBAAAttr(const llvm::MDNode *node, Operation *op,
167  LLVM::ModuleImport &moduleImport) {
168  Attribute tbaaTagSym = moduleImport.lookupTBAAAttr(node);
169  if (!tbaaTagSym)
170  return failure();
171 
172  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
173  if (!iface)
174  return failure();
175 
176  iface.setTBAATags(ArrayAttr::get(iface.getContext(), tbaaTagSym));
177  return success();
178 }
179 
180 /// Looks up all the access group attributes that map to the access group nodes
181 /// starting from the access group metadata `node`, and attaches all of them to
182 /// the imported operation if the lookups succeed. Returns failure otherwise.
183 static LogicalResult setAccessGroupsAttr(const llvm::MDNode *node,
184  Operation *op,
185  LLVM::ModuleImport &moduleImport) {
186  FailureOr<SmallVector<AccessGroupAttr>> accessGroups =
187  moduleImport.lookupAccessGroupAttrs(node);
188  if (failed(accessGroups))
189  return failure();
190 
191  auto iface = dyn_cast<AccessGroupOpInterface>(op);
192  if (!iface)
193  return failure();
194 
195  iface.setAccessGroups(ArrayAttr::get(
196  iface.getContext(), llvm::to_vector_of<Attribute>(*accessGroups)));
197  return success();
198 }
199 
200 /// Converts the given dereferenceable metadata node to a dereferenceable
201 /// attribute, and attaches it to the imported operation if the translation
202 /// succeeds. Returns failure if the LLVM IR metadata node is ill-formed.
203 static LogicalResult setDereferenceableAttr(const llvm::MDNode *node,
204  unsigned kindID, Operation *op,
205  LLVM::ModuleImport &moduleImport) {
206  auto dereferenceable =
207  moduleImport.translateDereferenceableAttr(node, kindID);
208  if (failed(dereferenceable))
209  return failure();
210 
211  auto iface = dyn_cast<DereferenceableOpInterface>(op);
212  if (!iface)
213  return failure();
214 
215  iface.setDereferenceable(*dereferenceable);
216  return success();
217 }
218 
219 /// Converts the given loop metadata node to an MLIR loop annotation attribute
220 /// and attaches it to the imported operation if the translation succeeds.
221 /// Returns failure otherwise.
222 static LogicalResult setLoopAttr(const llvm::MDNode *node, Operation *op,
223  LLVM::ModuleImport &moduleImport) {
224  LoopAnnotationAttr attr =
225  moduleImport.translateLoopAnnotationAttr(node, op->getLoc());
226  if (!attr)
227  return failure();
228 
230  .Case<LLVM::BrOp, LLVM::CondBrOp>([&](auto branchOp) {
231  branchOp.setLoopAnnotationAttr(attr);
232  return success();
233  })
234  .Default([](auto) { return failure(); });
235 }
236 
237 /// Looks up all the alias scope attributes that map to the alias scope nodes
238 /// starting from the alias scope metadata `node`, and attaches all of them to
239 /// the imported operation if the lookups succeed. Returns failure otherwise.
240 static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
241  LLVM::ModuleImport &moduleImport) {
242  FailureOr<SmallVector<AliasScopeAttr>> aliasScopes =
243  moduleImport.lookupAliasScopeAttrs(node);
244  if (failed(aliasScopes))
245  return failure();
246 
247  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
248  if (!iface)
249  return failure();
250 
251  iface.setAliasScopes(ArrayAttr::get(
252  iface.getContext(), llvm::to_vector_of<Attribute>(*aliasScopes)));
253  return success();
254 }
255 
256 /// Looks up all the alias scope attributes that map to the alias scope nodes
257 /// starting from the noalias metadata `node`, and attaches all of them to the
258 /// imported operation if the lookups succeed. Returns failure otherwise.
259 static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node,
260  Operation *op,
261  LLVM::ModuleImport &moduleImport) {
262  FailureOr<SmallVector<AliasScopeAttr>> noAliasScopes =
263  moduleImport.lookupAliasScopeAttrs(node);
264  if (failed(noAliasScopes))
265  return failure();
266 
267  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
268  if (!iface)
269  return failure();
270 
271  iface.setNoAliasScopes(ArrayAttr::get(
272  iface.getContext(), llvm::to_vector_of<Attribute>(*noAliasScopes)));
273  return success();
274 }
275 
276 /// Extracts an integer from the provided metadata `md` if possible. Returns
277 /// nullopt otherwise.
278 static std::optional<int32_t> parseIntegerMD(llvm::Metadata *md) {
279  auto *constant = dyn_cast_if_present<llvm::ConstantAsMetadata>(md);
280  if (!constant)
281  return {};
282 
283  auto *intConstant = dyn_cast<llvm::ConstantInt>(constant->getValue());
284  if (!intConstant)
285  return {};
286 
287  return intConstant->getValue().getSExtValue();
288 }
289 
290 /// Converts the provided metadata node `node` to an LLVM dialect
291 /// VecTypeHintAttr if possible.
292 static VecTypeHintAttr convertVecTypeHint(Builder builder, llvm::MDNode *node,
293  ModuleImport &moduleImport) {
294  if (!node || node->getNumOperands() != 2)
295  return {};
296 
297  auto *hintMD = dyn_cast<llvm::ValueAsMetadata>(node->getOperand(0).get());
298  if (!hintMD)
299  return {};
300  TypeAttr hint = TypeAttr::get(moduleImport.convertType(hintMD->getType()));
301 
302  std::optional<int32_t> optIsSigned =
303  parseIntegerMD(node->getOperand(1).get());
304  if (!optIsSigned)
305  return {};
306  bool isSigned = *optIsSigned != 0;
307 
308  return builder.getAttr<VecTypeHintAttr>(hint, isSigned);
309 }
310 
311 /// Converts the provided metadata node `node` to an MLIR DenseI32ArrayAttr if
312 /// possible.
314  llvm::MDNode *node) {
315  if (!node)
316  return {};
318  for (const llvm::MDOperand &op : node->operands()) {
319  std::optional<int32_t> mdValue = parseIntegerMD(op.get());
320  if (!mdValue)
321  return {};
322  vals.push_back(*mdValue);
323  }
324  return builder.getDenseI32ArrayAttr(vals);
325 }
326 
327 /// Convert an `MDNode` to an MLIR `IntegerAttr` if possible.
328 static IntegerAttr convertIntegerMD(Builder builder, llvm::MDNode *node) {
329  if (!node || node->getNumOperands() != 1)
330  return {};
331  std::optional<int32_t> val = parseIntegerMD(node->getOperand(0));
332  if (!val)
333  return {};
334  return builder.getI32IntegerAttr(*val);
335 }
336 
337 static LogicalResult setVecTypeHintAttr(Builder &builder, llvm::MDNode *node,
338  Operation *op,
339  LLVM::ModuleImport &moduleImport) {
340  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
341  if (!funcOp)
342  return failure();
343 
344  VecTypeHintAttr attr = convertVecTypeHint(builder, node, moduleImport);
345  if (!attr)
346  return failure();
347 
348  funcOp.setVecTypeHintAttr(attr);
349  return success();
350 }
351 
352 static LogicalResult
353 setWorkGroupSizeHintAttr(Builder &builder, llvm::MDNode *node, Operation *op) {
354  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
355  if (!funcOp)
356  return failure();
357 
358  DenseI32ArrayAttr attr = convertDenseI32Array(builder, node);
359  if (!attr)
360  return failure();
361 
362  funcOp.setWorkGroupSizeHintAttr(attr);
363  return success();
364 }
365 
366 static LogicalResult
367 setReqdWorkGroupSizeAttr(Builder &builder, llvm::MDNode *node, Operation *op) {
368  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
369  if (!funcOp)
370  return failure();
371 
372  DenseI32ArrayAttr attr = convertDenseI32Array(builder, node);
373  if (!attr)
374  return failure();
375 
376  funcOp.setReqdWorkGroupSizeAttr(attr);
377  return success();
378 }
379 
380 /// Converts the given intel required subgroup size metadata node to an MLIR
381 /// attribute and attaches it to the imported operation if the translation
382 /// succeeds. Returns failure otherwise.
383 static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder,
384  llvm::MDNode *node,
385  Operation *op) {
386  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
387  if (!funcOp)
388  return failure();
389 
390  IntegerAttr attr = convertIntegerMD(builder, node);
391  if (!attr)
392  return failure();
393 
394  funcOp.setIntelReqdSubGroupSizeAttr(attr);
395  return success();
396 }
397 
398 namespace {
399 
400 /// Implementation of the dialect interface that converts operations belonging
401 /// to the LLVM dialect to LLVM IR.
402 class LLVMDialectLLVMIRImportInterface : public LLVMImportDialectInterface {
403 public:
405 
406  /// Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a
407  /// conversion exits. Returns failure otherwise.
408  LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
409  LLVM::ModuleImport &moduleImport) const final {
410  return convertIntrinsicImpl(builder, inst, moduleImport);
411  }
412 
413  /// Attaches the given LLVM metadata to the imported operation if a conversion
414  /// to an LLVM dialect attribute exists and succeeds. Returns failure
415  /// otherwise.
416  LogicalResult setMetadataAttrs(OpBuilder &builder, unsigned kind,
417  llvm::MDNode *node, Operation *op,
418  LLVM::ModuleImport &moduleImport) const final {
419  // Call metadata specific handlers.
420  if (kind == llvm::LLVMContext::MD_prof)
421  return setProfilingAttr(builder, node, op, moduleImport);
422  if (kind == llvm::LLVMContext::MD_tbaa)
423  return setTBAAAttr(node, op, moduleImport);
424  if (kind == llvm::LLVMContext::MD_access_group)
425  return setAccessGroupsAttr(node, op, moduleImport);
426  if (kind == llvm::LLVMContext::MD_loop)
427  return setLoopAttr(node, op, moduleImport);
428  if (kind == llvm::LLVMContext::MD_alias_scope)
429  return setAliasScopesAttr(node, op, moduleImport);
430  if (kind == llvm::LLVMContext::MD_noalias)
431  return setNoaliasScopesAttr(node, op, moduleImport);
432  if (kind == llvm::LLVMContext::MD_dereferenceable)
433  return setDereferenceableAttr(node, llvm::LLVMContext::MD_dereferenceable,
434  op, moduleImport);
435  if (kind == llvm::LLVMContext::MD_dereferenceable_or_null)
436  return setDereferenceableAttr(
437  node, llvm::LLVMContext::MD_dereferenceable_or_null, op,
438  moduleImport);
439 
440  llvm::LLVMContext &context = node->getContext();
441  if (kind == context.getMDKindID(vecTypeHintMDName))
442  return setVecTypeHintAttr(builder, node, op, moduleImport);
443  if (kind == context.getMDKindID(workGroupSizeHintMDName))
444  return setWorkGroupSizeHintAttr(builder, node, op);
445  if (kind == context.getMDKindID(reqdWorkGroupSizeMDName))
446  return setReqdWorkGroupSizeAttr(builder, node, op);
447  if (kind == context.getMDKindID(intelReqdSubGroupSizeMDName))
448  return setIntelReqdSubGroupSizeAttr(builder, node, op);
449 
450  // A handler for a supported metadata kind is missing.
451  llvm_unreachable("unknown metadata type");
452  }
453 
454  /// Returns the list of LLVM IR intrinsic identifiers that are convertible to
455  /// MLIR LLVM dialect intrinsics.
456  ArrayRef<unsigned> getSupportedIntrinsics() const final {
458  }
459 
460  /// Returns the list of LLVM IR metadata kinds that are convertible to MLIR
461  /// LLVM dialect attributes.
463  getSupportedMetadata(llvm::LLVMContext &context) const final {
464  return getSupportedMetadataImpl(context);
465  }
466 };
467 } // namespace
468 
470  registry.insert<LLVM::LLVMDialect>();
471  registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
472  dialect->addInterfaces<LLVMDialectLLVMIRImportInterface>();
473  });
474 }
475 
477  DialectRegistry registry;
478  registerLLVMDialectImport(registry);
479  context.appendDialectRegistry(registry);
480 }
static VecTypeHintAttr convertVecTypeHint(Builder builder, llvm::MDNode *node, ModuleImport &moduleImport)
Converts the provided metadata node node to an LLVM dialect VecTypeHintAttr if possible.
static constexpr StringLiteral workGroupSizeHintMDName
static LogicalResult setReqdWorkGroupSizeAttr(Builder &builder, llvm::MDNode *node, Operation *op)
static DenseI32ArrayAttr convertDenseI32Array(Builder builder, llvm::MDNode *node)
Converts the provided metadata node node to an MLIR DenseI32ArrayAttr if possible.
static LogicalResult setWorkGroupSizeHintAttr(Builder &builder, llvm::MDNode *node, Operation *op)
static LogicalResult setVecTypeHintAttr(Builder &builder, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
static LogicalResult setLoopAttr(const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Converts the given loop metadata node to an MLIR loop annotation attribute and attaches it to the imp...
static ArrayRef< unsigned > getSupportedIntrinsicsImpl()
Returns the list of LLVM IR intrinsic identifiers that are convertible to MLIR LLVM dialect intrinsic...
static LogicalResult setTBAAAttr(const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Searches for the attribute that maps to the given TBAA metadata node and attaches it to the imported ...
static constexpr StringLiteral intelReqdSubGroupSizeMDName
static ArrayRef< unsigned > getSupportedMetadataImpl(llvm::LLVMContext &context)
Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM dialect attributes.
static LogicalResult setProfilingAttr(OpBuilder &builder, llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Converts the given profiling metadata node to an MLIR profiling attribute and attaches it to the impo...
static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder, llvm::MDNode *node, Operation *op)
Converts the given intel required subgroup size metadata node to an MLIR attribute and attaches it to...
static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Looks up all the alias scope attributes that map to the alias scope nodes starting from the alias sco...
static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Looks up all the alias scope attributes that map to the alias scope nodes starting from the noalias m...
static bool isConvertibleIntrinsic(llvm::Intrinsic::ID id)
Returns true if the LLVM IR intrinsic is convertible to an MLIR LLVM dialect intrinsic.
static constexpr StringLiteral reqdWorkGroupSizeMDName
static LogicalResult convertIntrinsicImpl(OpBuilder &odsBuilder, llvm::CallInst *inst, LLVM::ModuleImport &moduleImport)
Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a conversion exits.
static constexpr StringLiteral vecTypeHintMDName
static LogicalResult setAccessGroupsAttr(const llvm::MDNode *node, Operation *op, LLVM::ModuleImport &moduleImport)
Looks up all the access group attributes that map to the access group nodes starting from the access ...
static IntegerAttr convertIntegerMD(Builder builder, llvm::MDNode *node)
Convert an MDNode to an MLIR IntegerAttr if possible.
static LogicalResult setDereferenceableAttr(const llvm::MDNode *node, unsigned kindID, Operation *op, LLVM::ModuleImport &moduleImport)
Converts the given dereferenceable metadata node to a dereferenceable attribute, and attaches it to t...
static std::optional< int32_t > parseIntegerMD(llvm::Metadata *md)
Extracts an integer from the provided metadata md if possible.
union mlir::linalg::@1205::ArityGroupAndKind::Kind kind
Attributes are known-constant values of operations.
Definition: Attributes.h:25
This class is a general helper class for creating context-global objects like types,...
Definition: Builders.h:50
IntegerAttr getI32IntegerAttr(int32_t value)
Definition: Builders.cpp:198
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
Definition: Builders.cpp:161
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
Definition: Builders.h:96
The DialectRegistry maps a dialect namespace to a constructor for the matching dialect.
bool addExtension(TypeID extensionID, std::unique_ptr< DialectExtensionBase > extension)
Add the given extension to the registry.
Base class for dialect interfaces used to import LLVM IR.
LLVMImportDialectInterface(Dialect *dialect)
Module import implementation class that provides methods to import globals and functions from an LLVM...
Definition: ModuleImport.h:47
Attribute lookupTBAAAttr(const llvm::MDNode *node) const
Returns the MLIR attribute mapped to the given LLVM TBAA metadata node.
Definition: ModuleImport.h:244
FailureOr< SmallVector< AliasScopeAttr > > lookupAliasScopeAttrs(const llvm::MDNode *node) const
Returns the alias scope attributes that map to the alias scope nodes starting from the metadata node.
Type convertType(llvm::Type *type)
Converts the type from LLVM to MLIR LLVM dialect.
Definition: ModuleImport.h:182
LoopAnnotationAttr translateLoopAnnotationAttr(const llvm::MDNode *node, Location loc) const
Returns the loop annotation attribute that corresponds to the given LLVM loop metadata node.
FailureOr< SmallVector< AccessGroupAttr > > lookupAccessGroupAttrs(const llvm::MDNode *node) const
Returns the access group attributes that map to the access group nodes starting from the access group...
FailureOr< DereferenceableAttr > translateDereferenceableAttr(const llvm::MDNode *node, unsigned kindID)
Returns the dereferenceable attribute that corresponds to the given LLVM dereferenceable or dereferen...
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
void appendDialectRegistry(const DialectRegistry &registry)
Append the contents of the given dialect registry to the registry associated with this context.
This class helps build Operations.
Definition: Builders.h:205
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
unsigned getNumSuccessors()
Definition: Operation.h:706
InFlightDiagnostic emitWarning(const Twine &message={})
Emit a warning about this operation, reporting up to any diagnostic handlers that may be listening.
Definition: Operation.cpp:280
Location getLoc()
The source location the operation was defined or derived from.
Definition: Operation.h:223
Include the generated interface declarations.
void registerLLVMDialectImport(DialectRegistry &registry)
Registers the LLVM dialect and its import from LLVM IR in the given registry.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...