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.
84getSupportedMetadataImpl(llvm::LLVMContext &llvmContext) {
85 SmallVector<unsigned> convertibleMetadata = {
86 llvm::LLVMContext::MD_prof,
87 llvm::LLVMContext::MD_tbaa,
88 llvm::LLVMContext::MD_access_group,
89 llvm::LLVMContext::MD_loop,
90 llvm::LLVMContext::MD_noalias,
91 llvm::LLVMContext::MD_alias_scope,
92 llvm::LLVMContext::MD_dereferenceable,
93 llvm::LLVMContext::MD_dereferenceable_or_null,
94 llvm::LLVMContext::MD_mmra,
95 llvmContext.getMDKindID(vecTypeHintMDName),
96 llvmContext.getMDKindID(workGroupSizeHintMDName),
97 llvmContext.getMDKindID(reqdWorkGroupSizeMDName),
98 llvmContext.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.
105static 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() == llvm::MDProfLabels::FunctionEntryCount) {
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() != llvm::MDProfLabels::BranchWeights)
136 return failure();
137 // The branch_weights metadata must have at least 2 operands.
138 if (node->getNumOperands() < 2)
139 return failure();
140
141 ArrayRef<llvm::MDOperand> branchWeightOperands =
142 node->operands().drop_front();
143 if (auto *mdString = dyn_cast<llvm::MDString>(node->getOperand(1))) {
144 if (mdString->getString() != llvm::MDProfLabels::ExpectedBranchWeights)
145 return failure();
146 // The MLIR WeightedBranchOpInterface does not support the
147 // ExpectedBranchWeights field, so it is dropped.
148 branchWeightOperands = branchWeightOperands.drop_front();
149 }
150
151 // Handle branch weights metadata.
152 SmallVector<int32_t> branchWeights;
153 branchWeights.reserve(branchWeightOperands.size());
154 for (const llvm::MDOperand &operand : branchWeightOperands) {
155 llvm::ConstantInt *branchWeight =
156 llvm::mdconst::dyn_extract<llvm::ConstantInt>(operand);
157 if (!branchWeight)
158 return failure();
159 branchWeights.push_back(branchWeight->getZExtValue());
160 }
161
162 if (auto iface = dyn_cast<WeightedBranchOpInterface>(op)) {
163 // LLVM allows attaching a single weight to call instructions.
164 // This is used for carrying the execution count information
165 // in PGO modes. MLIR WeightedBranchOpInterface does not allow this,
166 // so we drop the metadata in this case.
167 // LLVM should probably use the VP form of MD_prof metadata
168 // for such cases.
169 if (op->getNumSuccessors() != 0)
170 iface.setWeights(branchWeights);
171 return success();
172 }
173 return failure();
174}
175
176/// Searches for the attribute that maps to the given TBAA metadata `node` and
177/// attaches it to the imported operation if the lookup succeeds. Returns
178/// failure otherwise.
179static LogicalResult setTBAAAttr(const llvm::MDNode *node, Operation *op,
180 LLVM::ModuleImport &moduleImport) {
181 Attribute tbaaTagSym = moduleImport.lookupTBAAAttr(node);
182 if (!tbaaTagSym)
183 return failure();
184
185 auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
186 if (!iface)
187 return failure();
188
189 iface.setTBAATags(ArrayAttr::get(iface.getContext(), tbaaTagSym));
190 return success();
191}
192
193/// Looks up all the access group attributes that map to the access group nodes
194/// starting from the access group metadata `node`, and attaches all of them to
195/// the imported operation if the lookups succeed. Returns failure otherwise.
196static LogicalResult setAccessGroupsAttr(const llvm::MDNode *node,
197 Operation *op,
198 LLVM::ModuleImport &moduleImport) {
199 FailureOr<SmallVector<AccessGroupAttr>> accessGroups =
200 moduleImport.lookupAccessGroupAttrs(node);
201 if (failed(accessGroups))
202 return failure();
203
204 auto iface = dyn_cast<AccessGroupOpInterface>(op);
205 if (!iface)
206 return failure();
207
208 iface.setAccessGroups(ArrayAttr::get(
209 iface.getContext(), llvm::to_vector_of<Attribute>(*accessGroups)));
210 return success();
211}
212
213/// Converts the given dereferenceable metadata node to a dereferenceable
214/// attribute, and attaches it to the imported operation if the translation
215/// succeeds. Returns failure if the LLVM IR metadata node is ill-formed.
216static LogicalResult setDereferenceableAttr(const llvm::MDNode *node,
217 unsigned kindID, Operation *op,
218 LLVM::ModuleImport &moduleImport) {
219 auto dereferenceable =
220 moduleImport.translateDereferenceableAttr(node, kindID);
221 if (failed(dereferenceable))
222 return failure();
223
224 auto iface = dyn_cast<DereferenceableOpInterface>(op);
225 if (!iface)
226 return failure();
227
228 iface.setDereferenceable(*dereferenceable);
229 return success();
230}
231
232/// Convert the given MMRA metadata (either an MMRA tag or an array of them)
233/// into corresponding MLIR attributes and set them on the given operation as a
234/// discardable `llvm.mmra` attribute.
235static LogicalResult setMmraAttr(llvm::MDNode *node, Operation *op,
236 LLVM::ModuleImport &moduleImport) {
237 if (!node)
238 return success();
239
240 // We don't use the LLVM wrappers here becasue we care about the order
241 // of the metadata for deterministic roundtripping.
242 MLIRContext *ctx = op->getContext();
243 auto toAttribute = [&](llvm::MDNode *tag) -> Attribute {
244 return LLVM::MMRATagAttr::get(
245 ctx, cast<llvm::MDString>(tag->getOperand(0))->getString(),
246 cast<llvm::MDString>(tag->getOperand(1))->getString());
247 };
248 Attribute mlirMmra;
249 if (llvm::MMRAMetadata::isTagMD(node)) {
250 mlirMmra = toAttribute(node);
251 } else {
253 for (const llvm::MDOperand &operand : node->operands()) {
254 auto *tagNode = dyn_cast<llvm::MDNode>(operand.get());
255 if (!tagNode || !llvm::MMRAMetadata::isTagMD(tagNode))
256 return failure();
257 tags.push_back(toAttribute(tagNode));
258 }
259 mlirMmra = ArrayAttr::get(ctx, tags);
260 }
261 op->setAttr(LLVMDialect::getMmraAttrName(), mlirMmra);
262 return success();
263}
264
265/// Converts the given loop metadata node to an MLIR loop annotation attribute
266/// and attaches it to the imported operation if the translation succeeds.
267/// Returns failure otherwise.
268static LogicalResult setLoopAttr(const llvm::MDNode *node, Operation *op,
269 LLVM::ModuleImport &moduleImport) {
270 LoopAnnotationAttr attr =
271 moduleImport.translateLoopAnnotationAttr(node, op->getLoc());
272 if (!attr)
273 return failure();
274
276 .Case<LLVM::BrOp, LLVM::CondBrOp>([&](auto branchOp) {
277 branchOp.setLoopAnnotationAttr(attr);
278 return success();
279 })
280 .Default([](auto) { return failure(); });
281}
282
283/// Looks up all the alias scope attributes that map to the alias scope nodes
284/// starting from the alias scope metadata `node`, and attaches all of them to
285/// the imported operation if the lookups succeed. Returns failure otherwise.
286static LogicalResult setAliasScopesAttr(const llvm::MDNode *node, Operation *op,
287 LLVM::ModuleImport &moduleImport) {
288 FailureOr<SmallVector<AliasScopeAttr>> aliasScopes =
289 moduleImport.lookupAliasScopeAttrs(node);
290 if (failed(aliasScopes))
291 return failure();
292
293 auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
294 if (!iface)
295 return failure();
296
297 iface.setAliasScopes(ArrayAttr::get(
298 iface.getContext(), llvm::to_vector_of<Attribute>(*aliasScopes)));
299 return success();
300}
301
302/// Looks up all the alias scope attributes that map to the alias scope nodes
303/// starting from the noalias metadata `node`, and attaches all of them to the
304/// imported operation if the lookups succeed. Returns failure otherwise.
305static LogicalResult setNoaliasScopesAttr(const llvm::MDNode *node,
306 Operation *op,
307 LLVM::ModuleImport &moduleImport) {
308 FailureOr<SmallVector<AliasScopeAttr>> noAliasScopes =
309 moduleImport.lookupAliasScopeAttrs(node);
310 if (failed(noAliasScopes))
311 return failure();
312
313 auto iface = dyn_cast<AliasAnalysisOpInterface>(op);
314 if (!iface)
315 return failure();
316
317 iface.setNoAliasScopes(ArrayAttr::get(
318 iface.getContext(), llvm::to_vector_of<Attribute>(*noAliasScopes)));
319 return success();
320}
321
322/// Extracts an integer from the provided metadata `md` if possible. Returns
323/// nullopt otherwise.
324static std::optional<int32_t> parseIntegerMD(llvm::Metadata *md) {
325 auto *constant = dyn_cast_if_present<llvm::ConstantAsMetadata>(md);
326 if (!constant)
327 return {};
328
329 auto *intConstant = dyn_cast<llvm::ConstantInt>(constant->getValue());
330 if (!intConstant)
331 return {};
332
333 return intConstant->getValue().getSExtValue();
334}
335
336/// Converts the provided metadata node `node` to an LLVM dialect
337/// VecTypeHintAttr if possible.
338static VecTypeHintAttr convertVecTypeHint(Builder builder, llvm::MDNode *node,
339 ModuleImport &moduleImport) {
340 if (!node || node->getNumOperands() != 2)
341 return {};
342
343 auto *hintMD = dyn_cast<llvm::ValueAsMetadata>(node->getOperand(0).get());
344 if (!hintMD)
345 return {};
346 TypeAttr hint = TypeAttr::get(moduleImport.convertType(hintMD->getType()));
347
348 std::optional<int32_t> optIsSigned =
349 parseIntegerMD(node->getOperand(1).get());
350 if (!optIsSigned)
351 return {};
352 bool isSigned = *optIsSigned != 0;
353
354 return builder.getAttr<VecTypeHintAttr>(hint, isSigned);
355}
356
357/// Converts the provided metadata node `node` to an MLIR DenseI32ArrayAttr if
358/// possible.
360 llvm::MDNode *node) {
361 if (!node)
362 return {};
364 for (const llvm::MDOperand &op : node->operands()) {
365 std::optional<int32_t> mdValue = parseIntegerMD(op.get());
366 if (!mdValue)
367 return {};
368 vals.push_back(*mdValue);
369 }
370 return builder.getDenseI32ArrayAttr(vals);
371}
372
373/// Convert an `MDNode` to an MLIR `IntegerAttr` if possible.
374static IntegerAttr convertIntegerMD(Builder builder, llvm::MDNode *node) {
375 if (!node || node->getNumOperands() != 1)
376 return {};
377 std::optional<int32_t> val = parseIntegerMD(node->getOperand(0));
378 if (!val)
379 return {};
380 return builder.getI32IntegerAttr(*val);
381}
382
383static LogicalResult setVecTypeHintAttr(Builder &builder, llvm::MDNode *node,
384 Operation *op,
385 LLVM::ModuleImport &moduleImport) {
386 auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
387 if (!funcOp)
388 return failure();
389
390 VecTypeHintAttr attr = convertVecTypeHint(builder, node, moduleImport);
391 if (!attr)
392 return failure();
393
394 funcOp.setVecTypeHintAttr(attr);
395 return success();
396}
397
398static LogicalResult
399setWorkGroupSizeHintAttr(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.setWorkGroupSizeHintAttr(attr);
409 return success();
410}
411
412static LogicalResult
413setReqdWorkGroupSizeAttr(Builder &builder, llvm::MDNode *node, Operation *op) {
414 auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
415 if (!funcOp)
416 return failure();
417
418 DenseI32ArrayAttr attr = convertDenseI32Array(builder, node);
419 if (!attr)
420 return failure();
421
422 funcOp.setReqdWorkGroupSizeAttr(attr);
423 return success();
424}
425
426/// Converts the given intel required subgroup size metadata node to an MLIR
427/// attribute and attaches it to the imported operation if the translation
428/// succeeds. Returns failure otherwise.
429static LogicalResult setIntelReqdSubGroupSizeAttr(Builder &builder,
430 llvm::MDNode *node,
431 Operation *op) {
432 auto funcOp = dyn_cast<LLVM::LLVMFuncOp>(op);
433 if (!funcOp)
434 return failure();
435
436 IntegerAttr attr = convertIntegerMD(builder, node);
437 if (!attr)
438 return failure();
439
440 funcOp.setIntelReqdSubGroupSizeAttr(attr);
441 return success();
442}
443
444namespace {
445
446/// Implementation of the dialect interface that converts operations belonging
447/// to the LLVM dialect to LLVM IR.
448class LLVMDialectLLVMIRImportInterface : public LLVMImportDialectInterface {
449public:
451
452 /// Converts the LLVM intrinsic to an MLIR LLVM dialect operation if a
453 /// conversion exits. Returns failure otherwise.
454 LogicalResult convertIntrinsic(OpBuilder &builder, llvm::CallInst *inst,
455 LLVM::ModuleImport &moduleImport) const final {
456 return convertIntrinsicImpl(builder, inst, moduleImport);
457 }
458
459 /// Attaches the given LLVM metadata to the imported operation if a conversion
460 /// to an LLVM dialect attribute exists and succeeds. Returns failure
461 /// otherwise.
462 LogicalResult setMetadataAttrs(OpBuilder &builder, unsigned kind,
463 llvm::MDNode *node, Operation *op,
464 LLVM::ModuleImport &moduleImport) const final {
465 // Call metadata specific handlers.
466 if (kind == llvm::LLVMContext::MD_prof)
467 return setProfilingAttr(builder, node, op, moduleImport);
468 if (kind == llvm::LLVMContext::MD_tbaa)
469 return setTBAAAttr(node, op, moduleImport);
470 if (kind == llvm::LLVMContext::MD_access_group)
471 return setAccessGroupsAttr(node, op, moduleImport);
472 if (kind == llvm::LLVMContext::MD_loop)
473 return setLoopAttr(node, op, moduleImport);
474 if (kind == llvm::LLVMContext::MD_alias_scope)
475 return setAliasScopesAttr(node, op, moduleImport);
476 if (kind == llvm::LLVMContext::MD_noalias)
477 return setNoaliasScopesAttr(node, op, moduleImport);
478 if (kind == llvm::LLVMContext::MD_dereferenceable)
479 return setDereferenceableAttr(node, llvm::LLVMContext::MD_dereferenceable,
480 op, moduleImport);
481 if (kind == llvm::LLVMContext::MD_dereferenceable_or_null)
483 node, llvm::LLVMContext::MD_dereferenceable_or_null, op,
484 moduleImport);
485 if (kind == llvm::LLVMContext::MD_mmra)
486 return setMmraAttr(node, op, moduleImport);
487 llvm::LLVMContext &context = node->getContext();
488 if (kind == context.getMDKindID(vecTypeHintMDName))
489 return setVecTypeHintAttr(builder, node, op, moduleImport);
490 if (kind == context.getMDKindID(workGroupSizeHintMDName))
491 return setWorkGroupSizeHintAttr(builder, node, op);
492 if (kind == context.getMDKindID(reqdWorkGroupSizeMDName))
493 return setReqdWorkGroupSizeAttr(builder, node, op);
494 if (kind == context.getMDKindID(intelReqdSubGroupSizeMDName))
495 return setIntelReqdSubGroupSizeAttr(builder, node, op);
496
497 // A handler for a supported metadata kind is missing.
498 llvm_unreachable("unknown metadata type");
499 }
500
501 /// Returns the list of LLVM IR intrinsic identifiers that are convertible to
502 /// MLIR LLVM dialect intrinsics.
503 ArrayRef<unsigned> getSupportedIntrinsics() const final {
505 }
506
507 /// Returns the list of LLVM IR metadata kinds that are convertible to MLIR
508 /// LLVM dialect attributes.
509 SmallVector<unsigned>
510 getSupportedMetadata(llvm::LLVMContext &llvmContext) const final {
511 return getSupportedMetadataImpl(llvmContext);
512 }
513};
514} // namespace
515
517 registry.insert<LLVM::LLVMDialect>();
518 registry.addExtension(+[](MLIRContext *ctx, LLVM::LLVMDialect *dialect) {
519 dialect->addInterfaces<LLVMDialectLLVMIRImportInterface>();
520 });
521}
522
524 DialectRegistry registry;
526 context.appendDialectRegistry(registry);
527}
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 SmallVector< unsigned > getSupportedMetadataImpl(llvm::LLVMContext &llvmContext)
Returns the list of LLVM IR metadata kinds that are convertible to MLIR LLVM dialect attributes.
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 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.