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