MLIR 24.0.0git
Property.h
Go to the documentation of this file.
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"
19#include "llvm/ADT/StringRef.h"
20
21namespace llvm {
22class DefInit;
23class Record;
24} // namespace llvm
25
26namespace mlir {
27namespace tblgen {
28class Dialect;
29class Type;
30class Pred;
31
32// Wrapper class providing helper methods for accesing property constraint
33// values.
34class PropConstraint : public Constraint {
35public:
37
38 static bool classof(const Constraint *c) { return c->getKind() == CK_Prop; }
39
40 StringRef getInterfaceType() const;
41};
42
43// Wrapper class providing helper methods for accessing MLIR Property defined
44// in TableGen. This class should closely reflect what is defined as class
45// `Property` in TableGen.
46class Property : public PropConstraint {
47public:
48 explicit Property(const llvm::Record *def);
49 explicit Property(const llvm::DefInit *init);
50 Property(const llvm::Record *maybeDef, StringRef summary,
51 StringRef description, StringRef storageType,
52 StringRef interfaceType, StringRef convertFromStorageCall,
53 StringRef assignToStorageCall, StringRef convertToAttributeCall,
54 StringRef convertFromAttributeCall, StringRef parserCall,
55 StringRef optionalParserCall, StringRef printerCall,
56 StringRef readFromMlirBytecodeCall,
57 StringRef writeToMlirBytecodeCall, StringRef hashPropertyCall,
58 StringRef defaultValue, StringRef storageTypeValueOverride);
59
60 // Returns the summary (for error messages) of this property's type.
61 StringRef getSummary() const { return summary; }
62
63 // Returns the description of this property.
64 StringRef getDescription() const { return description; }
65
66 // Returns the storage type.
67 StringRef getStorageType() const { return storageType; }
68
69 // Returns the interface type for this property.
70 StringRef getInterfaceType() const { return interfaceType; }
71
72 // Returns the template getter method call which reads this property's
73 // storage and returns the value as of the desired return type.
74 StringRef getConvertFromStorageCall() const { return convertFromStorageCall; }
75
76 // Returns the template setter method call which reads this property's
77 // in the provided interface type and assign it to the storage.
78 StringRef getAssignToStorageCall() const { return assignToStorageCall; }
79
80 // Returns the conversion method call which reads this property's
81 // in the storage type and builds an attribute.
82 StringRef getConvertToAttributeCall() const { return convertToAttributeCall; }
83
84 // Returns the setter method call which reads this property's
85 // in the provided interface type and assign it to the storage.
86 StringRef getConvertFromAttributeCall() const {
87 return convertFromAttributeCall;
88 }
89
90 // Return the property's predicate. Properties that didn't come from
91 // tablegen (the hardcoded ones) have the null predicate.
92 Pred getPredicate() const;
93
94 // Returns the method call which parses this property from textual MLIR.
95 StringRef getParserCall() const { return parserCall; }
96
97 // Returns true if this property uses the parser inherited from the base
98 // Property class.
99 bool usesDefaultParser() const;
100
101 // Returns true if this property has defined an optional parser.
102 bool hasOptionalParser() const { return !optionalParserCall.empty(); }
103
104 // Returns the method call which optionally parses this property from textual
105 // MLIR.
106 StringRef getOptionalParserCall() const { return optionalParserCall; }
107
108 // Returns the method call which prints this property to textual MLIR.
109 StringRef getPrinterCall() const { return printerCall; }
110
111 // Returns the method call which reads this property from
112 // bytecode and assign it to the storage.
113 StringRef getReadFromMlirBytecodeCall() const {
114 return readFromMlirBytecodeCall;
115 }
116
117 // Returns the method call which write this property's
118 // to the the bytecode.
119 StringRef getWriteToMlirBytecodeCall() const {
120 return writeToMlirBytecodeCall;
121 }
122
123 // Returns the code to compute the hash for this property.
124 StringRef getHashPropertyCall() const { return hashPropertyCall; }
125
126 // Returns whether this Property has a default value.
127 bool hasDefaultValue() const { return !defaultValue.empty(); }
128
129 // Returns the default value for this Property.
130 StringRef getDefaultValue() const { return defaultValue; }
131
132 // Returns whether this Property has a default storage-type value that is
133 // distinct from its default interface-type value.
135 return !storageTypeValueOverride.empty();
136 }
137
138 StringRef getStorageTypeValueOverride() const {
139 return storageTypeValueOverride;
140 }
141
142 // Returns this property's TableGen def-name.
143 StringRef getPropertyDefName() const;
144
145 // Returns the base-level property that this Property constraint is based on
146 // or the Property itself otherwise. (Note: there are currently no
147 // property constraints, this function is added for future-proofing)
149
150 // Returns true if this property is backed by a TableGen definition and that
151 // definition is a subclass of `className`.
152 bool isSubClassOf(StringRef className) const;
153
154private:
155 // Elements describing a Property, in general fetched from the record.
156 StringRef summary;
157 StringRef description;
158 StringRef storageType;
159 StringRef interfaceType;
160 StringRef convertFromStorageCall;
161 StringRef assignToStorageCall;
162 StringRef convertToAttributeCall;
163 StringRef convertFromAttributeCall;
164 StringRef parserCall;
165 StringRef optionalParserCall;
166 StringRef printerCall;
167 StringRef readFromMlirBytecodeCall;
168 StringRef writeToMlirBytecodeCall;
169 StringRef hashPropertyCall;
170 StringRef defaultValue;
171 StringRef storageTypeValueOverride;
172};
173
174// A struct wrapping an op property and its name together
176 llvm::StringRef name;
178};
179
180// Wrapper class providing helper methods for processing constant property
181// values defined using the `ConstantProp` subclass of `Property`
182// in TableGen.
183class ConstantProp : public Property {
184public:
185 explicit ConstantProp(const llvm::DefInit *def) : Property(def) {
186 assert(isSubClassOf("ConstantProp"));
187 }
188
189 static bool classof(Property *p) { return p->isSubClassOf("ConstantProp"); }
190
191 // Return the constant value of the property as an expression
192 // that produces an interface-type constant.
193 StringRef getValue() const;
194};
195} // namespace tblgen
196} // namespace mlir
197
198#endif // MLIR_TABLEGEN_PROPERTY_H_
ConstantProp(const llvm::DefInit *def)
Definition Property.h:185
static bool classof(Property *p)
Definition Property.h:189
StringRef getValue() const
Definition Property.cpp:134
const llvm::Record * def
Definition Constraint.h:90
Constraint(const llvm::Record *record, Kind kind)
Definition Constraint.h:43
static bool classof(const Constraint *c)
Definition Property.h:38
StringRef getInterfaceType() const
Definition Property.cpp:35
Constraint(const llvm::Record *record, Kind kind)
Definition Constraint.h:43
StringRef getPropertyDefName() const
Definition Property.cpp:91
Pred getPredicate() const
Definition Property.cpp:98
StringRef getStorageType() const
Definition Property.h:67
StringRef getConvertFromStorageCall() const
Definition Property.h:74
StringRef getReadFromMlirBytecodeCall() const
Definition Property.h:113
StringRef getPrinterCall() const
Definition Property.h:109
bool isSubClassOf(StringRef className) const
Definition Property.cpp:130
bool hasOptionalParser() const
Definition Property.h:102
StringRef getDescription() const
Definition Property.h:64
StringRef getAssignToStorageCall() const
Definition Property.h:78
Property(const llvm::Record *def)
StringRef getHashPropertyCall() const
Definition Property.h:124
StringRef getConvertToAttributeCall() const
Definition Property.h:82
bool hasDefaultValue() const
Definition Property.h:127
StringRef getWriteToMlirBytecodeCall() const
Definition Property.h:119
bool hasStorageTypeValueOverride() const
Definition Property.h:134
Property getBaseProperty() const
Definition Property.cpp:122
StringRef getConvertFromAttributeCall() const
Definition Property.h:86
StringRef getSummary() const
Definition Property.h:61
StringRef getStorageTypeValueOverride() const
Definition Property.h:138
StringRef getDefaultValue() const
Definition Property.h:130
StringRef getParserCall() const
Definition Property.h:95
StringRef getInterfaceType() const
Definition Property.h:70
Property(const llvm::DefInit *init)
bool usesDefaultParser() const
Definition Property.cpp:107
StringRef getOptionalParserCall() const
Definition Property.h:106
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:227
Include the generated interface declarations.