/home/arjun/llvm-project/mlir/include/mlir/IR/AttributeSupport.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===- AttributeSupport.h ---------------------------------------*- 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 | | // This file defines support types for registering dialect extended attributes. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef MLIR_IR_ATTRIBUTESUPPORT_H |
14 | | #define MLIR_IR_ATTRIBUTESUPPORT_H |
15 | | |
16 | | #include "mlir/IR/MLIRContext.h" |
17 | | #include "mlir/IR/StorageUniquerSupport.h" |
18 | | #include "llvm/ADT/PointerIntPair.h" |
19 | | |
20 | | namespace mlir { |
21 | | class MLIRContext; |
22 | | class Type; |
23 | | |
24 | | //===----------------------------------------------------------------------===// |
25 | | // AttributeStorage |
26 | | //===----------------------------------------------------------------------===// |
27 | | |
28 | | namespace detail { |
29 | | class AttributeUniquer; |
30 | | } // end namespace detail |
31 | | |
32 | | /// Base storage class appearing in an attribute. Derived storage classes should |
33 | | /// only be constructed within the context of the AttributeUniquer. |
34 | | class AttributeStorage : public StorageUniquer::BaseStorage { |
35 | | friend detail::AttributeUniquer; |
36 | | friend StorageUniquer; |
37 | | |
38 | | public: |
39 | | /// Get the type of this attribute. |
40 | | Type getType() const; |
41 | | |
42 | | /// Get the dialect of this attribute. |
43 | 0 | Dialect &getDialect() const { |
44 | 0 | assert(dialect && "Malformed attribute storage object."); |
45 | 0 | return const_cast<Dialect &>(*dialect); |
46 | 0 | } |
47 | | |
48 | | protected: |
49 | | /// Construct a new attribute storage instance with the given type. |
50 | | /// Note: All attributes require a valid type. If no type is provided here, |
51 | | /// the type of the attribute will automatically default to NoneType |
52 | | /// upon initialization in the uniquer. |
53 | | AttributeStorage(Type type); |
54 | | AttributeStorage(); |
55 | | |
56 | | /// Set the type of this attribute. |
57 | | void setType(Type type); |
58 | | |
59 | | // Set the dialect for this storage instance. This is used by the |
60 | | // AttributeUniquer when initializing a newly constructed storage object. |
61 | 0 | void initializeDialect(Dialect &newDialect) { dialect = &newDialect; } |
62 | | |
63 | | private: |
64 | | /// The dialect for this attribute. |
65 | | Dialect *dialect; |
66 | | |
67 | | /// The opaque type of the attribute value. |
68 | | const void *type; |
69 | | }; |
70 | | |
71 | | /// Default storage type for attributes that require no additional |
72 | | /// initialization or storage. |
73 | | using DefaultAttributeStorage = AttributeStorage; |
74 | | |
75 | | //===----------------------------------------------------------------------===// |
76 | | // AttributeStorageAllocator |
77 | | //===----------------------------------------------------------------------===// |
78 | | |
79 | | // This is a utility allocator used to allocate memory for instances of derived |
80 | | // Attributes. |
81 | | using AttributeStorageAllocator = StorageUniquer::StorageAllocator; |
82 | | |
83 | | //===----------------------------------------------------------------------===// |
84 | | // AttributeUniquer |
85 | | //===----------------------------------------------------------------------===// |
86 | | namespace detail { |
87 | | // A utility class to get, or create, unique instances of attributes within an |
88 | | // MLIRContext. This class manages all creation and uniquing of attributes. |
89 | | class AttributeUniquer { |
90 | | public: |
91 | | /// Get an uniqued instance of attribute T. |
92 | | template <typename T, typename... Args> |
93 | 0 | static T get(MLIRContext *ctx, unsigned kind, Args &&... args) { |
94 | 0 | return ctx->getAttributeUniquer().get<typename T::ImplType>( |
95 | 0 | [ctx](AttributeStorage *storage) { |
96 | 0 | initializeAttributeStorage(storage, ctx, T::getTypeID()); |
97 | 0 | }, Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_13AffineMapAttrEJRNS_9AffineMapEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESD_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_9ArrayAttrEJRN4llvm8ArrayRefINS_9AttributeEEEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_14DictionaryAttrEJRN4llvm8ArrayRefISt4pairINS_10IdentifierENS_9AttributeEEEEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESJ_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_9FloatAttrEJRNS_4TypeERdEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESE_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_9FloatAttrEJRNS_4TypeERN4llvm7APFloatEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_13SymbolRefAttrEJRN4llvm9StringRefERNS4_8NoneTypeEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_13SymbolRefAttrEJRN4llvm9StringRefERNS4_8ArrayRefINS_17FlatSymbolRefAttrEEEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESI_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_11IntegerAttrEJRNS_4TypeERN4llvm5APIntEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_14IntegerSetAttrEJRNS_10IntegerSetEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESD_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_10OpaqueAttrEJRNS_10IdentifierERN4llvm9StringRefERNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESI_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_10StringAttrEJRN4llvm9StringRefERNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_8TypeAttrEJRNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESD_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_23DenseStringElementsAttrEJRNS_10ShapedTypeERN4llvm8ArrayRefINS6_9StringRefEEERbEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESJ_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_24DenseIntOrFPElementsAttrEJRNS_10ShapedTypeERN4llvm8ArrayRefIcEERbEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESI_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_18OpaqueElementsAttrEJRNS_10ShapedTypeERPNS_7DialectERN4llvm9StringRefEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESJ_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_18SparseElementsAttrEJRNS_10ShapedTypeERNS_20DenseIntElementsAttrERNS_17DenseElementsAttrEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESH_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_11CallSiteLocEJRNS_8LocationES5_EEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESD_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_14FileLineColLocEJRNS_10IdentifierERjS6_EEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESE_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_8FusedLocEJRN4llvm8ArrayRefINS_8LocationEEERNS_9AttributeEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESI_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_7NameLocEJRNS_10IdentifierERNS_8LocationEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESF_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_9OpaqueLocEJRmRNS_6TypeIDERNS_8LocationEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESG_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_8BoolAttrEJPNS_11MLIRContextEbEEET_S5_jDpOT0_ENKUlPNS_16AttributeStorageEE_clESB_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_8UnitAttrEJEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESB_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_10UnknownLocEJEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESB_ Unexecuted instantiation: _ZZN4mlir6detail16AttributeUniquer3getINS_14DictionaryAttrEJN4llvm8ArrayRefISt4pairINS_10IdentifierENS_9AttributeEEEEEEET_PNS_11MLIRContextEjDpOT0_ENKUlPNS_16AttributeStorageEE_clESI_ |
98 | 0 | kind, std::forward<Args>(args)...); |
99 | 0 | } Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_13AffineMapAttrEJRNS_9AffineMapEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_9ArrayAttrEJRN4llvm8ArrayRefINS_9AttributeEEEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_14DictionaryAttrEJRN4llvm8ArrayRefISt4pairINS_10IdentifierENS_9AttributeEEEEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_9FloatAttrEJRNS_4TypeERdEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_9FloatAttrEJRNS_4TypeERN4llvm7APFloatEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_13SymbolRefAttrEJRN4llvm9StringRefERNS4_8NoneTypeEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_13SymbolRefAttrEJRN4llvm9StringRefERNS4_8ArrayRefINS_17FlatSymbolRefAttrEEEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_11IntegerAttrEJRNS_4TypeERN4llvm5APIntEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_14IntegerSetAttrEJRNS_10IntegerSetEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_10OpaqueAttrEJRNS_10IdentifierERN4llvm9StringRefERNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_10StringAttrEJRN4llvm9StringRefERNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_8TypeAttrEJRNS_4TypeEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_23DenseStringElementsAttrEJRNS_10ShapedTypeERN4llvm8ArrayRefINS6_9StringRefEEERbEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_24DenseIntOrFPElementsAttrEJRNS_10ShapedTypeERN4llvm8ArrayRefIcEERbEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_18OpaqueElementsAttrEJRNS_10ShapedTypeERPNS_7DialectERN4llvm9StringRefEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_18SparseElementsAttrEJRNS_10ShapedTypeERNS_20DenseIntElementsAttrERNS_17DenseElementsAttrEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_11CallSiteLocEJRNS_8LocationES5_EEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_14FileLineColLocEJRNS_10IdentifierERjS6_EEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_8FusedLocEJRN4llvm8ArrayRefINS_8LocationEEERNS_9AttributeEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_7NameLocEJRNS_10IdentifierERNS_8LocationEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_9OpaqueLocEJRmRNS_6TypeIDERNS_8LocationEEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_8BoolAttrEJPNS_11MLIRContextEbEEET_S5_jDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_8UnitAttrEJEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_10UnknownLocEJEEET_PNS_11MLIRContextEjDpOT0_ Unexecuted instantiation: _ZN4mlir6detail16AttributeUniquer3getINS_14DictionaryAttrEJN4llvm8ArrayRefISt4pairINS_10IdentifierENS_9AttributeEEEEEEET_PNS_11MLIRContextEjDpOT0_ |
100 | | |
101 | | private: |
102 | | /// Initialize the given attribute storage instance. |
103 | | static void initializeAttributeStorage(AttributeStorage *storage, |
104 | | MLIRContext *ctx, TypeID attrID); |
105 | | }; |
106 | | } // namespace detail |
107 | | |
108 | | } // end namespace mlir |
109 | | |
110 | | #endif |