1 //===- LLVMAttrs.cpp - LLVM Attributes registration -----------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the attribute details for the LLVM IR dialect in MLIR.
11 //===----------------------------------------------------------------------===//
13 #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
14 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15 #include "mlir/IR/Builders.h"
16 #include "mlir/IR/DialectImplementation.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/TypeSwitch.h"
19 #include "llvm/BinaryFormat/Dwarf.h"
23 using namespace mlir::LLVM
;
25 #include "mlir/Dialect/LLVMIR/LLVMOpsEnums.cpp.inc"
26 #define GET_ATTRDEF_CLASSES
27 #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
29 //===----------------------------------------------------------------------===//
30 // LLVMDialect registration
31 //===----------------------------------------------------------------------===//
33 void LLVMDialect::registerAttributes() {
35 #define GET_ATTRDEF_LIST
36 #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
40 //===----------------------------------------------------------------------===//
42 //===----------------------------------------------------------------------===//
44 bool DINodeAttr::classof(Attribute attr
) {
45 return llvm::isa
<DIBasicTypeAttr
, DICompileUnitAttr
, DICompositeTypeAttr
,
46 DIDerivedTypeAttr
, DIFileAttr
, DILabelAttr
,
47 DILexicalBlockAttr
, DILexicalBlockFileAttr
,
48 DILocalVariableAttr
, DIModuleAttr
, DINamespaceAttr
,
49 DINullTypeAttr
, DISubprogramAttr
, DISubrangeAttr
,
50 DISubroutineTypeAttr
>(attr
);
53 //===----------------------------------------------------------------------===//
55 //===----------------------------------------------------------------------===//
57 bool DIScopeAttr::classof(Attribute attr
) {
58 return llvm::isa
<DICompileUnitAttr
, DICompositeTypeAttr
, DIFileAttr
,
59 DILocalScopeAttr
, DIModuleAttr
, DINamespaceAttr
>(attr
);
62 //===----------------------------------------------------------------------===//
64 //===----------------------------------------------------------------------===//
66 bool DILocalScopeAttr::classof(Attribute attr
) {
67 return llvm::isa
<DILexicalBlockAttr
, DILexicalBlockFileAttr
,
68 DISubprogramAttr
>(attr
);
71 //===----------------------------------------------------------------------===//
73 //===----------------------------------------------------------------------===//
75 bool DITypeAttr::classof(Attribute attr
) {
76 return llvm::isa
<DINullTypeAttr
, DIBasicTypeAttr
, DICompositeTypeAttr
,
77 DIDerivedTypeAttr
, DISubroutineTypeAttr
>(attr
);
80 //===----------------------------------------------------------------------===//
82 //===----------------------------------------------------------------------===//
84 bool TBAANodeAttr::classof(Attribute attr
) {
85 return llvm::isa
<TBAATypeDescriptorAttr
, TBAARootAttr
>(attr
);
88 //===----------------------------------------------------------------------===//
90 //===----------------------------------------------------------------------===//
92 MemoryEffectsAttr
MemoryEffectsAttr::get(MLIRContext
*context
,
93 ArrayRef
<ModRefInfo
> memInfoArgs
) {
94 if (memInfoArgs
.empty())
95 return MemoryEffectsAttr::get(context
, ModRefInfo::ModRef
,
96 ModRefInfo::ModRef
, ModRefInfo::ModRef
);
97 if (memInfoArgs
.size() == 3)
98 return MemoryEffectsAttr::get(context
, memInfoArgs
[0], memInfoArgs
[1],
103 bool MemoryEffectsAttr::isReadWrite() {
104 if (this->getArgMem() != ModRefInfo::ModRef
)
106 if (this->getInaccessibleMem() != ModRefInfo::ModRef
)
108 if (this->getOther() != ModRefInfo::ModRef
)