MLIR 22.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 has defined an optional parser.
98 bool hasOptionalParser() const { return !optionalParserCall.empty(); }
99
100 // Returns the method call which optionally parses this property from textual
101 // MLIR.
102 StringRef getOptionalParserCall() const { return optionalParserCall; }
103
104 // Returns the method call which prints this property to textual MLIR.
105 StringRef getPrinterCall() const { return printerCall; }
106
107 // Returns the method call which reads this property from
108 // bytecode and assign it to the storage.
109 StringRef getReadFromMlirBytecodeCall() const {
110 return readFromMlirBytecodeCall;
111 }
112
113 // Returns the method call which write this property's
114 // to the the bytecode.
115 StringRef getWriteToMlirBytecodeCall() const {
116 return writeToMlirBytecodeCall;
117 }
118
119 // Returns the code to compute the hash for this property.
120 StringRef getHashPropertyCall() const { return hashPropertyCall; }
121
122 // Returns whether this Property has a default value.
123 bool hasDefaultValue() const { return !defaultValue.empty(); }
124
125 // Returns the default value for this Property.
126 StringRef getDefaultValue() const { return defaultValue; }
127
128 // Returns whether this Property has a default storage-type value that is
129 // distinct from its default interface-type value.
131 return !storageTypeValueOverride.empty();
132 }
133
134 StringRef getStorageTypeValueOverride() const {
135 return storageTypeValueOverride;
136 }
137
138 // Returns this property's TableGen def-name.
139 StringRef getPropertyDefName() const;
140
141 // Returns the base-level property that this Property constraint is based on
142 // or the Property itself otherwise. (Note: there are currently no
143 // property constraints, this function is added for future-proofing)
145
146 // Returns true if this property is backed by a TableGen definition and that
147 // definition is a subclass of `className`.
148 bool isSubClassOf(StringRef className) const;
149
150private:
151 // Elements describing a Property, in general fetched from the record.
152 StringRef summary;
153 StringRef description;
154 StringRef storageType;
155 StringRef interfaceType;
156 StringRef convertFromStorageCall;
157 StringRef assignToStorageCall;
158 StringRef convertToAttributeCall;
159 StringRef convertFromAttributeCall;
160 StringRef parserCall;
161 StringRef optionalParserCall;
162 StringRef printerCall;
163 StringRef readFromMlirBytecodeCall;
164 StringRef writeToMlirBytecodeCall;
165 StringRef hashPropertyCall;
166 StringRef defaultValue;
167 StringRef storageTypeValueOverride;
168};
169
170// A struct wrapping an op property and its name together
172 llvm::StringRef name;
174};
175
176// Wrapper class providing helper methods for processing constant property
177// values defined using the `ConstantProp` subclass of `Property`
178// in TableGen.
179class ConstantProp : public Property {
180public:
181 explicit ConstantProp(const llvm::DefInit *def) : Property(def) {
182 assert(isSubClassOf("ConstantProp"));
183 }
184
185 static bool classof(Property *p) { return p->isSubClassOf("ConstantProp"); }
186
187 // Return the constant value of the property as an expression
188 // that produces an interface-type constant.
189 StringRef getValue() const;
190};
191} // namespace tblgen
192} // namespace mlir
193
194#endif // MLIR_TABLEGEN_PROPERTY_H_
ConstantProp(const llvm::DefInit *def)
Definition Property.h:181
static bool classof(Property *p)
Definition Property.h:185
StringRef getValue() const
Definition Property.cpp:119
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:109
StringRef getPrinterCall() const
Definition Property.h:105
bool isSubClassOf(StringRef className) const
Definition Property.cpp:115
bool hasOptionalParser() const
Definition Property.h:98
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:120
StringRef getConvertToAttributeCall() const
Definition Property.h:82
bool hasDefaultValue() const
Definition Property.h:123
StringRef getWriteToMlirBytecodeCall() const
Definition Property.h:115
bool hasStorageTypeValueOverride() const
Definition Property.h:130
Property getBaseProperty() const
Definition Property.cpp:107
StringRef getConvertFromAttributeCall() const
Definition Property.h:86
StringRef getSummary() const
Definition Property.h:61
StringRef getStorageTypeValueOverride() const
Definition Property.h:134
StringRef getDefaultValue() const
Definition Property.h:126
StringRef getParserCall() const
Definition Property.h:95
StringRef getInterfaceType() const
Definition Property.h:70
Property(const llvm::DefInit *init)
StringRef getOptionalParserCall() const
Definition Property.h:102
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.