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