1 | //===- Property.h - Property wrapper class --------------------*- 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 | // Property wrapper to simplify using TableGen Record defining a MLIR |
10 | // Property. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef MLIR_TABLEGEN_PROPERTY_H_ |
15 | #define MLIR_TABLEGEN_PROPERTY_H_ |
16 | |
17 | #include "mlir/Support/LLVM.h" |
18 | #include "mlir/TableGen/Constraint.h" |
19 | #include "llvm/ADT/StringRef.h" |
20 | |
21 | namespace llvm { |
22 | class DefInit; |
23 | class Record; |
24 | } // namespace llvm |
25 | |
26 | namespace mlir { |
27 | namespace tblgen { |
28 | class Dialect; |
29 | class Type; |
30 | |
31 | // Wrapper class providing helper methods for accessing MLIR Property defined |
32 | // in TableGen. This class should closely reflect what is defined as class |
33 | // `Property` in TableGen. |
34 | class Property { |
35 | public: |
36 | explicit Property(const llvm::Record *record); |
37 | explicit Property(const llvm::DefInit *init); |
38 | Property(StringRef storageType, StringRef interfaceType, |
39 | StringRef convertFromStorageCall, StringRef assignToStorageCall, |
40 | StringRef convertToAttributeCall, StringRef convertFromAttributeCall, |
41 | StringRef readFromMlirBytecodeCall, |
42 | StringRef writeToMlirBytecodeCall, StringRef hashPropertyCall, |
43 | StringRef defaultValue); |
44 | |
45 | // Returns the storage type. |
46 | StringRef getStorageType() const { return storageType; } |
47 | |
48 | // Returns the interface type for this property. |
49 | StringRef getInterfaceType() const { return interfaceType; } |
50 | |
51 | // Returns the template getter method call which reads this property's |
52 | // storage and returns the value as of the desired return type. |
53 | StringRef getConvertFromStorageCall() const { return convertFromStorageCall; } |
54 | |
55 | // Returns the template setter method call which reads this property's |
56 | // in the provided interface type and assign it to the storage. |
57 | StringRef getAssignToStorageCall() const { return assignToStorageCall; } |
58 | |
59 | // Returns the conversion method call which reads this property's |
60 | // in the storage type and builds an attribute. |
61 | StringRef getConvertToAttributeCall() const { return convertToAttributeCall; } |
62 | |
63 | // Returns the setter method call which reads this property's |
64 | // in the provided interface type and assign it to the storage. |
65 | StringRef getConvertFromAttributeCall() const { |
66 | return convertFromAttributeCall; |
67 | } |
68 | |
69 | // Returns the method call which reads this property from |
70 | // bytecode and assign it to the storage. |
71 | StringRef getReadFromMlirBytecodeCall() const { |
72 | return readFromMlirBytecodeCall; |
73 | } |
74 | |
75 | // Returns the method call which write this property's |
76 | // to the the bytecode. |
77 | StringRef getWriteToMlirBytecodeCall() const { |
78 | return writeToMlirBytecodeCall; |
79 | } |
80 | |
81 | // Returns the code to compute the hash for this property. |
82 | StringRef getHashPropertyCall() const { return hashPropertyCall; } |
83 | |
84 | // Returns whether this Property has a default value. |
85 | bool hasDefaultValue() const { return !defaultValue.empty(); } |
86 | |
87 | // Returns the default value for this Property. |
88 | StringRef getDefaultValue() const { return defaultValue; } |
89 | |
90 | // Returns the TableGen definition this Property was constructed from. |
91 | const llvm::Record &getDef() const { return *def; } |
92 | |
93 | private: |
94 | // The TableGen definition of this constraint. |
95 | const llvm::Record *def; |
96 | |
97 | // Elements describing a Property, in general fetched from the record. |
98 | StringRef storageType; |
99 | StringRef interfaceType; |
100 | StringRef convertFromStorageCall; |
101 | StringRef assignToStorageCall; |
102 | StringRef convertToAttributeCall; |
103 | StringRef convertFromAttributeCall; |
104 | StringRef readFromMlirBytecodeCall; |
105 | StringRef writeToMlirBytecodeCall; |
106 | StringRef hashPropertyCall; |
107 | StringRef defaultValue; |
108 | }; |
109 | |
110 | // A struct wrapping an op property and its name together |
111 | struct NamedProperty { |
112 | llvm::StringRef name; |
113 | Property prop; |
114 | }; |
115 | |
116 | } // namespace tblgen |
117 | } // namespace mlir |
118 | |
119 | #endif // MLIR_TABLEGEN_PROPERTY_H_ |
120 | |