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<BranchWeightOpInterface>(op)) {
150  iface.setBranchWeights(builder.getDenseI32ArrayAttr(branchWeights));
151  return success();
152  }
153  return failure();
154 }
155 
156 /// Searches for the attribute that maps to the given TBAA metadata `node` and
157 /// attaches it to the imported operation if the lookup succeeds. Returns
158 /// failure otherwise.
159 static LogicalResult setTBAAAttr(const llvm::MDNode *node, Operation *op,
160  LLVM::ModuleImport &moduleImport) {
161  Attribute tbaaTagSym = moduleImport.lookupTBAAAttr(node);
162  if (!tbaaTagSym)
163  return failure();
164 
165  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
166  if (!iface)
167  return failure();
168 
169  iface.setTBAATags(ArrayAttr::get(iface.getContext(), tbaaTagSym));
170  return success();
171 }
172 
173 /// Looks up all the access group attributes that map to the access group nodes
174 /// starting from the access group metadata `node`, and attaches all of them to
175 /// the imported operation if the lookups succeed. Returns failure otherwise.
176 static LogicalResult setAccessGroupsAttr(const llvm::MDNode *node,
177  Operation *op,
178  LLVM::ModuleImport &moduleImport) {
179  FailureOr<SmallVector<AccessGroupAttr>> accessGroups =
180  moduleImport.lookupAccessGroupAttrs(node);
181  if (failed(accessGroups))
182  return failure();
183 
184  auto iface = dyn_cast<AccessGroupOpInterface>(op);
185  if (!iface)
186  return failure();
187 
188  iface.setAccessGroups(ArrayAttr::get(
189  iface.getContext(), llvm::to_vector_of<Attribute>(*accessGroups)));
190  return success();
191 }
192 
193 /// Converts the given dereferenceable metadata node to a dereferenceable
194 /// attribute, and attaches it to the imported operation if the translation
195 /// succeeds. Returns failure if the LLVM IR metadata node is ill-formed.
196 static LogicalResult setDereferenceableAttr(const llvm::MDNode *node,
197  unsigned kindID, Operation *op,
198  LLVM::ModuleImport &moduleImport) {
199  auto dereferenceable =
200  moduleImport.translateDereferenceableAttr(node, kindID);
201  if (failed(dereferenceable))
202  return failure();
203 
204  auto iface = dyn_cast<DereferenceableOpInterface>(op);
205  if (!iface)
206  return failure();
207 
208  iface.setDereferenceable(*dereferenceable);
209  return success();
210 }
211 
212 /// Converts the given loop metadata node to an MLIR loop annotation attribute
213 /// and attaches it to the imported operation if the translation succeeds.
214 /// Returns failure otherwise.
215 static LogicalResult setLoopAttr(const llvm::MDNode *node, Operation *op,
216  LLVM::ModuleImport &moduleImport) {
217  LoopAnnotationAttr attr =
218  moduleImport.translateLoopAnnotationAttr(node, op->getLoc());
219  if (!attr)
220  return failure();
221 
223  .Case<LLVM::BrOp, LLVM::CondBrOp>([&](auto branchOp) {
224  branchOp.setLoopAnnotationAttr(attr);
225  return success();
226  })
227  .Default([](auto) { return failure(); });
228 }
229 
230 /// Looks up all the alias scope attributes that map to the alias scope nodes
231 /// starting from the alias scope metadata `node`, and attaches all of them to
232 /// the imported operation if the lookups succeed. Returns failure otherwise.
233 static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
234  LLVM::ModuleImport &moduleImport) {
235  FailureOr<SmallVector<AliasScopeAttr>> aliasScopes =
236  moduleImport.lookupAliasScopeAttrs(node);
237  if (failed(aliasScopes))
238  return failure();
239 
240  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
241  if (!iface)
242  return failure();
243 
244  iface.setAliasScopes(ArrayAttr::get(
245  iface.getContext(), llvm::to_vector_of<Attribute>(*aliasScopes)));
246  return success();
247 }
248 
249 /// Looks up all the alias scope attributes that map to the alias scope nodes
250 /// starting from the noalias metadata `node`, and attaches all of them to the
251 /// imported operation if the lookups succeed. Returns failure otherwise.
252 static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node,
253  Operation *op,
254  LLVM::ModuleImport &moduleImport) {
255  FailureOr<SmallVector<AliasScopeAttr>> noAliasScopes =
256  moduleImport.lookupAliasScopeAttrs(node);
257  if (failed(noAliasScopes))
258  return failure();
259 
260  auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
261  if (!iface)
262  return failure();
263 
264  iface.setNoAliasScopes(ArrayAttr::get(
265  iface.getContext(), llvm::to_vector_of<Attribute>(*noAliasScopes)));
266  return success();
267 }
268 
269 /// Extracts an integer from the provided metadata `md` if possible. Returns
270 /// nullopt otherwise.
271 static std::optional<int32_t> parseIntegerMD(llvm::Metadata *md) {
272  auto *constant = dyn_cast_if_present<llvm::ConstantAsMetadata>(md);
273  if (!constant)
274  return {};
275 
276  auto *intConstant = dyn_cast<llvm::ConstantInt>(constant->getValue());
277  if (!intConstant)
278  return {};
279 
280  return intConstant->getValue().getSExtValue();
281 }
282 
283 /// Converts the provided metadata node `node` to an LLVM dialect
284 /// VecTypeHintAttr if possible.
285 static VecTypeHintAttr convertVecTypeHint(Builder builder, llvm::MDNode *node,
286  ModuleImport &moduleImport) {
287  if (!node || node->getNumOperands() != 2)
288  return {};
289 
290  auto *hintMD = dyn_cast<llvm::ValueAsMetadata>(node->getOperand(0).get());
291  if (!hintMD)
292  return {};
293  TypeAttr hint = TypeAttr::get(moduleImport.convertType(hintMD->getType()));
294 
295  std::optional<int32_t> optIsSigned =
296  parseIntegerMD(node->getOperand(1).get());
297  if (!optIsSigned)
298  return {};
299  bool isSigned = *optIsSigned != 0;
300 
301  return builder.getAttr<VecTypeHintAttr>(hint, isSigned);
302 }
303 
304 /// Converts the provided metadata node `node` to an MLIR DenseI32ArrayAttr if
305 /// possible.
307  llvm::MDNode *node) {
308  if (!node)
309  return {};
311  for (const llvm::MDOperand &op : node->operands()) {
312  std::optional<int32_t> mdValue = parseIntegerMD(op.get());
313  if (!mdValue)
314  return {};
315  vals.push_back(*mdValue);
316  }
317  return builder.getDenseI32ArrayAttr(vals);
318 }
319 
320 /// Convert an `MDNode` to an MLIR `IntegerAttr` if possible.
321 static IntegerAttr convertIntegerMD(Builder builder, llvm::MDNode *node) {
322  if (!node || node->getNumOperands() != 1)
323  return {};
324  std::optional<int32_t> val = parseIntegerMD(node->getOperand(0));
325  if (!val)
326  return {};
327  return builder.getI32IntegerAttr(*val);
328 }
329 
330 static LogicalResult setVecTypeHintAttr(Builder &builder, llvm::MDNode *node,
331  Operation *op,
332  LLVM::ModuleImport &moduleImport) {
333  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
334  if (!funcOp)
335  return failure();
336 
337  VecTypeHintAttr attr = convertVecTypeHint(builder, node, moduleImport);
338  if (!attr)
339  return failure();
340 
341  funcOp.setVecTypeHintAttr(attr);
342  return success();
343 }
344 
345 static LogicalResult
346 setWorkGroupSizeHintAttr(Builder &builder, llvm::MDNode *node, Operation *op) {
347  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
348  if (!funcOp)
349  return failure();
350 
351  DenseI32ArrayAttr attr = convertDenseI32Array(builder, node);
352  if (!attr)
353  return failure();
354 
355  funcOp.setWorkGroupSizeHintAttr(attr);
356  return success();
357 }
358 
359 static LogicalResult
360 setReqdWorkGroupSizeAttr(Builder &builder, llvm::MDNode *node, Operation *op) {
361  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
362  if (!funcOp)
363  return failure();
364 
365  DenseI32ArrayAttr attr = convertDenseI32Array(builder, node);
366  if (!attr)
367  return failure();
368 
369  funcOp.setReqdWorkGroupSizeAttr(attr);
370  return success();
371 }
372 
373 /// Converts the given intel required subgroup size metadata node to an MLIR
374 /// attribute and attaches it to the imported operation if the translation
375 /// succeeds. Returns failure otherwise.
376 static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder,
377  llvm::MDNode *node,
378  Operation *op) {
379  auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
380  if (!funcOp)
381  return failure();
382 
383  IntegerAttr attr = convertIntegerMD(builder, node);
384  if (!attr)
385  return failure();
386 
387  funcOp.setIntelReqdSubGroupSizeAttr(attr);
388  return success();
389 }
390 
391 namespace {
392 
393 /// Implementation of the dialect interface that converts operations belonging
394 /// to the LLVM dialect to LLVM IR.
395 class LLVMDialectLLVMIRImportInterface : public LLVMImportDialectInterface {
396 public:
398 
399  /// Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a
400  /// conversion exits. Returns failure otherwise.
401  LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
402  LLVM::ModuleImport &moduleImport) const final {
403  return convertIntrinsicImpl(builder, inst, moduleImport);
404  }
405 
406  /// Attaches the given LLVM metadata to the imported operation if a conversion
407  /// to an LLVM dialect attribute exists and succeeds. Returns failure
408  /// otherwise.
409  LogicalResult setMetadataAttrs(OpBuilder &builder, unsigned kind,
410  llvm::MDNode *node, Operation *op,
411  LLVM::ModuleImport &moduleImport) const final {
412  // Call metadata specific handlers.
413  if (kind == llvm::LLVMContext::MD_prof)
414  return setProfilingAttr(builder, node, op, moduleImport);
415  if (kind == llvm::LLVMContext::MD_tbaa)
416  return setTBAAAttr(node, op, moduleImport);
417  if (kind == llvm::LLVMContext::MD_access_group)
418  return setAccessGroupsAttr(node, op, moduleImport);
419  if (kind == llvm::LLVMContext::MD_loop)
420  return setLoopAttr(node, op, moduleImport);
421  if (kind == llvm::LLVMContext::MD_alias_scope)
422  return setAliasScopesAttr(node, op, moduleImport);
423  if (kind == llvm::LLVMContext::MD_noalias)
424  return setNoaliasScopesAttr(node, op, moduleImport);
425  if (kind == llvm::LLVMContext::MD_dereferenceable)
426  return setDereferenceableAttr(node, llvm::LLVMContext::MD_dereferenceable,
427  op, moduleImport);
428  if (kind == llvm::LLVMContext::MD_dereferenceable_or_null)
429  return setDereferenceableAttr(
430  node, llvm::LLVMContext::MD_dereferenceable_or_null, op,
431  moduleImport);
432 
433  llvm::LLVMContext &context = node->getContext();
434  if (kind == context.getMDKindID(vecTypeHintMDName))
435  return setVecTypeHintAttr(builder, node, op, moduleImport);
436  if (kind == context.getMDKindID(workGroupSizeHintMDName))
437  return setWorkGroupSizeHintAttr(builder, node, op);
438  if (kind == context.getMDKindID(reqdWorkGroupSizeMDName))
439  return setReqdWorkGroupSizeAttr(builder, node, op);
440  if (kind == context.getMDKindID(intelReqdSubGroupSizeMDName))
441  return setIntelReqdSubGroupSizeAttr(builder, node, op);
442 
443  // A handler for a supported metadata kind is missing.
444  llvm_unreachable("unknown metadata type");
445  }
446 
447  /// Returns the list of LLVM IR intrinsic identifiers that are convertible to
448  /// MLIR LLVM dialect intrinsics.
449  ArrayRef<unsigned> getSupportedIntrinsics() const final {
451  }
452 
453  /// Returns the list of LLVM IR metadata kinds that are convertible to MLIR
454  /// LLVM dialect attributes.
456  getSupportedMetadata(llvm::LLVMContext &context) const final {
457  return getSupportedMetadataImpl(context);
458  }
459 };
460 } // namespace
461 
463  registry.insert<LLVM::LLVMDialect>();
464  registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
465  dialect->addInterfaces<LLVMDialectLLVMIRImportInterface>();
466  });
467 }
468 
470  DialectRegistry registry;
471  registerLLVMDialectImport(registry);
472  context.appendDialectRegistry(registry);
473 }
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::@1194::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:196
DenseI32ArrayAttr getDenseI32ArrayAttr(ArrayRef< int32_t > values)
Definition: Builders.cpp:159
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
Definition: Builders.h:95
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:204
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
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...