MLIR  20.0.0git
AttrKindDetail.h
Go to the documentation of this file.
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 
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.
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::Range, LLVMDialect::getRangeAttrName()},
49  {llvm::Attribute::AttrKind::ReadOnly, LLVMDialect::getReadonlyAttrName()},
50  {llvm::Attribute::AttrKind::ReadNone, LLVMDialect::getReadnoneAttrName()},
51  {llvm::Attribute::AttrKind::Returned, LLVMDialect::getReturnedAttrName()},
52  {llvm::Attribute::AttrKind::SExt, LLVMDialect::getSExtAttrName()},
53  {llvm::Attribute::AttrKind::StackAlignment,
54  LLVMDialect::getStackAlignmentAttrName()},
55  {llvm::Attribute::AttrKind::StructRet,
56  LLVMDialect::getStructRetAttrName()},
57  {llvm::Attribute::AttrKind::WriteOnly,
58  LLVMDialect::getWriteOnlyAttrName()},
59  {llvm::Attribute::AttrKind::ZExt, LLVMDialect::getZExtAttrName()}};
60  return kindNamePairs;
61 }
62 
63 /// Returns a dense map from LLVM attribute name to their kind in LLVM IR
64 /// dialect.
65 [[maybe_unused]] static llvm::DenseMap<llvm::StringRef,
66  llvm::Attribute::AttrKind>
68  static auto attrNameToKindMapping = []() {
70  for (auto kindNamePair : getAttrKindToNameMapping()) {
71  nameKindMap.insert({kindNamePair.second, kindNamePair.first});
72  }
73  return nameKindMap;
74  }();
75  return attrNameToKindMapping;
76 }
77 
78 } // namespace detail
79 } // namespace LLVM
80 } // namespace mlir
81 
82 #endif // ATTRKINDDETAIL_H_
static llvm::ArrayRef< std::pair< llvm::Attribute::AttrKind, llvm::StringRef > > getAttrKindToNameMapping()
Returns a list of pairs that each hold a mapping from LLVM attribute kinds to their corresponding str...
static llvm::DenseMap< llvm::StringRef, llvm::Attribute::AttrKind > getAttrNameToKindMapping()
Returns a dense map from LLVM attribute name to their kind in LLVM IR dialect.
Include the generated interface declarations.