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