1 | //===- AttrKindDetail.h - AttrKind conversion details -----------*- C++ -*-===// |
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 | #ifndef ATTRKINDDETAIL_H_ |
10 | #define ATTRKINDDETAIL_H_ |
11 | |
12 | #include "mlir/Dialect/LLVMIR/LLVMDialect.h" |
13 | #include "llvm/IR/Attributes.h" |
14 | |
15 | namespace mlir { |
16 | namespace LLVM { |
17 | namespace detail { |
18 | |
19 | /// Returns a list of pairs that each hold a mapping from LLVM attribute kinds |
20 | /// to their corresponding string name in LLVM IR dialect. |
21 | static llvm::ArrayRef<std::pair<llvm::Attribute::AttrKind, llvm::StringRef>> |
22 | getAttrKindToNameMapping() { |
23 | using ElemTy = std::pair<llvm::Attribute::AttrKind, llvm::StringRef>; |
24 | // Mapping from llvm attribute kinds to their corresponding MLIR name. |
25 | static const llvm::SmallVector<ElemTy> kindNamePairs = { |
26 | {llvm::Attribute::AttrKind::Alignment, LLVMDialect::getAlignAttrName()}, |
27 | {llvm::Attribute::AttrKind::AllocAlign, |
28 | LLVMDialect::getAllocAlignAttrName()}, |
29 | {llvm::Attribute::AttrKind::AllocatedPointer, |
30 | LLVMDialect::getAllocatedPointerAttrName()}, |
31 | {llvm::Attribute::AttrKind::ByVal, LLVMDialect::getByValAttrName()}, |
32 | {llvm::Attribute::AttrKind::ByRef, LLVMDialect::getByRefAttrName()}, |
33 | {llvm::Attribute::AttrKind::NoUndef, LLVMDialect::getNoUndefAttrName()}, |
34 | {llvm::Attribute::AttrKind::Dereferenceable, |
35 | LLVMDialect::getDereferenceableAttrName()}, |
36 | {llvm::Attribute::AttrKind::DereferenceableOrNull, |
37 | LLVMDialect::getDereferenceableOrNullAttrName()}, |
38 | {llvm::Attribute::AttrKind::InAlloca, LLVMDialect::getInAllocaAttrName()}, |
39 | {llvm::Attribute::AttrKind::InReg, LLVMDialect::getInRegAttrName()}, |
40 | {llvm::Attribute::AttrKind::Nest, LLVMDialect::getNestAttrName()}, |
41 | {llvm::Attribute::AttrKind::NoAlias, LLVMDialect::getNoAliasAttrName()}, |
42 | {llvm::Attribute::AttrKind::NoCapture, |
43 | LLVMDialect::getNoCaptureAttrName()}, |
44 | {llvm::Attribute::AttrKind::NoFree, LLVMDialect::getNoFreeAttrName()}, |
45 | {llvm::Attribute::AttrKind::NonNull, LLVMDialect::getNonNullAttrName()}, |
46 | {llvm::Attribute::AttrKind::Preallocated, |
47 | LLVMDialect::getPreallocatedAttrName()}, |
48 | {llvm::Attribute::AttrKind::ReadOnly, LLVMDialect::getReadonlyAttrName()}, |
49 | {llvm::Attribute::AttrKind::ReadNone, LLVMDialect::getReadnoneAttrName()}, |
50 | {llvm::Attribute::AttrKind::Returned, LLVMDialect::getReturnedAttrName()}, |
51 | {llvm::Attribute::AttrKind::SExt, LLVMDialect::getSExtAttrName()}, |
52 | {llvm::Attribute::AttrKind::StackAlignment, |
53 | LLVMDialect::getStackAlignmentAttrName()}, |
54 | {llvm::Attribute::AttrKind::StructRet, |
55 | LLVMDialect::getStructRetAttrName()}, |
56 | {llvm::Attribute::AttrKind::WriteOnly, |
57 | LLVMDialect::getWriteOnlyAttrName()}, |
58 | {llvm::Attribute::AttrKind::ZExt, LLVMDialect::getZExtAttrName()}}; |
59 | return kindNamePairs; |
60 | } |
61 | |
62 | /// Returns a dense map from LLVM attribute name to their kind in LLVM IR |
63 | /// dialect. |
64 | [[maybe_unused]] static llvm::DenseMap<llvm::StringRef, |
65 | llvm::Attribute::AttrKind> |
66 | getAttrNameToKindMapping() { |
67 | static auto attrNameToKindMapping = []() { |
68 | llvm::DenseMap<llvm::StringRef, llvm::Attribute::AttrKind> nameKindMap; |
69 | for (auto kindNamePair : getAttrKindToNameMapping()) { |
70 | nameKindMap.insert(KV: {kindNamePair.second, kindNamePair.first}); |
71 | } |
72 | return nameKindMap; |
73 | }(); |
74 | return attrNameToKindMapping; |
75 | } |
76 | |
77 | } // namespace detail |
78 | } // namespace LLVM |
79 | } // namespace mlir |
80 | |
81 | #endif // ATTRKINDDETAIL_H_ |
82 | |