MLIR  21.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 
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 class Pred;
31 
32 // Wrapper class providing helper methods for accesing property constraint
33 // values.
34 class PropConstraint : public Constraint {
36 
37 public:
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.
46 class Property : public PropConstraint {
47 public:
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)
144  Property getBaseProperty() const;
145 
146 private:
147  // Elements describing a Property, in general fetched from the record.
148  StringRef summary;
149  StringRef description;
150  StringRef storageType;
151  StringRef interfaceType;
152  StringRef convertFromStorageCall;
153  StringRef assignToStorageCall;
154  StringRef convertToAttributeCall;
155  StringRef convertFromAttributeCall;
156  StringRef parserCall;
157  StringRef optionalParserCall;
158  StringRef printerCall;
159  StringRef readFromMlirBytecodeCall;
160  StringRef writeToMlirBytecodeCall;
161  StringRef hashPropertyCall;
162  StringRef defaultValue;
163  StringRef storageTypeValueOverride;
164 };
165 
166 // A struct wrapping an op property and its name together
168  llvm::StringRef name;
170 };
171 
172 } // namespace tblgen
173 } // namespace mlir
174 
175 #endif // MLIR_TABLEGEN_PROPERTY_H_
Kind getKind() const
Definition: Constraint.h:83
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:36
StringRef getPropertyDefName() const
Definition: Property.cpp:92
Pred getPredicate() const
Definition: Property.cpp:99
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 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:108
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
@ Type
An inlay hint that for a type annotation.
Include the generated interface declarations.
llvm::StringRef name
Definition: Property.h:168